-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
179 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System; | ||
|
||
namespace LiteDB.Tests | ||
{ | ||
public class Gang | ||
{ | ||
public ObjectId Id { get; set; } | ||
public string Name { get; set; } | ||
public ulong LeaderId { get; set; } | ||
public ulong GuildId { get; set; } | ||
public List<ulong> Members { get; set; } | ||
public double Wealth { get; set; } = 0.0; | ||
public DateTime Raid { get; set; } = DateTime.UtcNow.AddYears(-1); | ||
} | ||
|
||
[TestClass] | ||
public class ULongListTest | ||
{ | ||
[TestMethod] | ||
public void ULongList_Test() | ||
{ | ||
using (var file = new TempFile()) | ||
using (var db = new LiteDatabase(file.Filename)) | ||
{ | ||
var col = db.GetCollection<Gang>(); | ||
|
||
col.Insert(new Gang | ||
{ | ||
GuildId = 1, | ||
LeaderId = 2, | ||
Members = new List<ulong> { 5, 6, 7} | ||
}); | ||
|
||
ulong userId = 5; | ||
ulong guildId = 1; | ||
|
||
var e = col.Exists(x => x.GuildId == guildId && (x.LeaderId == userId)); | ||
|
||
//Assert.IsTrue(e); | ||
|
||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
using System; | ||
using LiteDB; | ||
|
||
namespace LiteDbRepro | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
BsonMapper.Global.Entity<AudioLogEntry>() | ||
.Id(x => x.Id, true) | ||
.Index(x => x.UserInvokeId) | ||
.Index(x => x.Timestamp); | ||
|
||
using (var database = new LiteDatabase("history.db")) | ||
{ | ||
var audioLogEntries = database.GetCollection<AudioLogEntry>("audioLogEntries"); | ||
audioLogEntries.EnsureIndex(x => x.AudioResource.ResourceTitle); | ||
audioLogEntries.EnsureIndex(x => x.AudioResource.UniqueId, true); | ||
|
||
var ale = new AudioLogEntry(1, new AudioResource("a", "b", AudioType.MediaLink)) | ||
{ | ||
UserInvokeId = 42, | ||
Timestamp = DateTime.UtcNow, | ||
PlayCount = 1, | ||
}; | ||
|
||
// Throws here: | ||
audioLogEntries.Insert(ale); | ||
} | ||
} | ||
} | ||
|
||
public class AudioLogEntry | ||
{ | ||
/// <summary>A unique id for each <see cref="ResourceFactories.AudioResource"/>, given by the history system.</summary> | ||
public int Id { get; set; } | ||
/// <summary>The dbid of the teamspeak user, who played this song first.</summary> | ||
public uint UserInvokeId { get; set; } | ||
/// <summary>How often the song has been played.</summary> | ||
public uint PlayCount { get; set; } | ||
/// <summary>The last time this song has been played.</summary> | ||
public DateTime Timestamp { get; set; } | ||
|
||
public AudioResource AudioResource { get; set; } | ||
|
||
public AudioLogEntry() | ||
{ | ||
PlayCount = 0; | ||
} | ||
|
||
public AudioLogEntry(int id, AudioResource resource) : this() | ||
{ | ||
Id = id; | ||
AudioResource = resource; | ||
} | ||
|
||
public void SetName(string newName) | ||
{ | ||
AudioResource = AudioResource.WithName(newName); | ||
} | ||
} | ||
|
||
public class AudioResource | ||
{ | ||
/// <summary>The resource type.</summary> | ||
public AudioType AudioType { get; set; } | ||
/// <summary>An identifier to create the song. This id is uniqe among same <see cref="TS3AudioBot.AudioType"/> resources.</summary> | ||
public string ResourceId { get; set; } | ||
/// <summary>The display title.</summary> | ||
public string ResourceTitle { get; set; } | ||
/// <summary>An identifier wich is unique among all <see cref="AudioResource"/> and <see cref="TS3AudioBot.AudioType"/>.</summary> | ||
public string UniqueId => ResourceId + AudioType.ToString(); | ||
|
||
public AudioResource() { } | ||
|
||
public AudioResource(string resourceId, string resourceTitle, AudioType type) | ||
{ | ||
ResourceId = resourceId; | ||
ResourceTitle = resourceTitle; | ||
AudioType = type; | ||
} | ||
|
||
public AudioResource(AudioResource copyResource) | ||
{ | ||
ResourceId = copyResource.ResourceId; | ||
ResourceTitle = copyResource.ResourceTitle; | ||
AudioType = copyResource.AudioType; | ||
} | ||
|
||
public AudioResource WithName(string newName) => new AudioResource(ResourceId, newName, AudioType); | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
var other = obj as AudioResource; | ||
if (other == null) | ||
return false; | ||
|
||
return AudioType == other.AudioType | ||
&& ResourceId == other.ResourceId; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
int hash = 0x7FFFF + (int)AudioType; | ||
hash = (hash * 0x1FFFF) + ResourceId.GetHashCode(); | ||
return hash; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return $"{AudioType} ID:{ResourceId}"; | ||
} | ||
} | ||
|
||
public enum AudioType | ||
{ | ||
MediaLink, | ||
Youtube, | ||
Soundcloud, | ||
Twitch, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters