public void ReadAndWrite_InParallelThreads() { using (var file = new TempFile()) { using (var db = new LiteDbAdapter(file.Filename)) { var iterations = Parallel.For(0, 100, i => { if (i % 2 == 0) { db.UpsertServerInfo(TestData.Server); } else { db.GetServers().Count().Should().BeLessOrEqualTo(1); } }); while (!iterations.IsCompleted) { Thread.Sleep(100); } var result = db.GetServers().ToArray(); result.Length.ShouldBeEquivalentTo(1); result[0].Should().Be(TestData.Server); } } }
public void NotAddNewRecord_IfServerAlreadyAdded() { using (var file = new TempFile()) using (var db = new LiteDbAdapter(file.Filename)) { for (var i = 0; i < 10; i++) { db.UpsertServerInfo(TestData.Server); db.UpsertServerInfo(new GameServer { endpoint = TestData.Server.endpoint, info = new ServerInfo() }); db.UpsertServerInfo(TestData.Server); } var result = db.GetServers().ToArray(); result.Length.ShouldBeEquivalentTo(1); result[0].Should().Be(TestData.Server); } }
public void ReturnAddedRecords() { using (var file = new TempFile()) { using (var db = new LiteDbAdapter(file.Filename)) { db.UpsertServerInfo(TestData.Server); var result = db.GetServerInfo(TestData.Server.endpoint); result.ShouldBeEquivalentTo(TestData.Server); } } }
public void KeepDataAfterClosingConnection() { using (var file = new TempFile()) { using (var db = new LiteDbAdapter(file.Filename)) { db.UpsertServerInfo(TestData.Server); } using (var db = new LiteDbAdapter(file.Filename)) { var result = db.GetServerInfo(TestData.Server.endpoint); result.ShouldBeEquivalentTo(TestData.Server); } } }
public void ReturnAllAddedRecords() { using (var file = new TempFile()) { using (var db = new LiteDbAdapter(file.Filename)) { IList <GameServer> serverInfos = TestData.Servers; foreach (var info in serverInfos) { db.UpsertServerInfo(info); } var result = db.GetServers(); result.Should().BeEquivalentTo(serverInfos); } } }
public void DoNotAddNewRecords_IfServerAlreadyAdded_InParallelThreads() { using (var file = new TempFile()) using (var db = new LiteDbAdapter(file.Filename)) { var iterations = Parallel.For(0, 100, _ => { db.GetServers().Count(x => x.endpoint == TestData.Server.endpoint).Should().BeLessOrEqualTo(1); db.UpsertServerInfo(TestData.Server); db.GetServers().Count(x => x.endpoint == TestData.Server.endpoint).Should().Be(1); }); while (!iterations.IsCompleted) { Thread.Sleep(100); } var result = db.GetServers().ToArray(); result.Length.ShouldBeEquivalentTo(1); result[0].Should().Be(TestData.Server); } }