public async Task LogEntryLimitMultiThreadedTest() { //Arrange var dbConnection = new UnitTestDbConnection(); Database.SetInitializer(new DropCreateDatabaseAlways <ZvsContext>()); var log = new DatabaseFeedback(dbConnection); var task1 = Task.Run(async() => { for (var i = 0; i < 1500; i++) { await log.ReportInfoFormatAsync(CancellationToken.None, "loop1 {0}", i); } }); var task2 = Task.Run(async() => { for (var i = 0; i < 400; i++) { await log.ReportInfoFormatAsync(CancellationToken.None, "loop2 {0}", i); } }); var task3 = Task.Run(async() => { using (var context = new ZvsContext(dbConnection)) { for (var i = 0; i < 700; i++) { context.LogEntries.Add(new LogEntry { Datetime = DateTime.Now, Level = LogEntryLevel.Info, Message = $"loop3 {i}", Source = "Source" }); } await context.SaveChangesAsync(CancellationToken.None); } }); await Task.WhenAll(task1, task2, task3); using (var context = new ZvsContext(dbConnection)) { var currentLogEntryCount = context.LogEntries.Count(); //Assert Assert.IsTrue(currentLogEntryCount == 2000, "Expected 2000 entries and got " + currentLogEntryCount); } }
public async Task LogEntryMultipleContextLimitTest() { //Arrange var dbConnection = new UnitTestDbConnection(); Database.SetInitializer(new DropCreateDatabaseAlways <ZvsContext>()); var log = new DatabaseFeedback(dbConnection); for (var i = 0; i < 2003; i++) { await log.ReportInfoFormatAsync(CancellationToken.None, "hello world {0}", i); } using (var context = new ZvsContext(dbConnection)) { var currentLogEntryCount = context.LogEntries.Count(); var firstentry = await context.LogEntries.OrderBy(o => o.Datetime).FirstAsync(); var lastEntry = await context.LogEntries.OrderByDescending(o => o.Datetime).FirstAsync(); //Aseert Assert.IsTrue(currentLogEntryCount == 2000, "Expected 2000 entries and got " + currentLogEntryCount); Assert.IsTrue(firstentry.Message == "hello world 3", "Expected first entry to start with 3"); Assert.IsTrue(lastEntry.Message == "hello world 2002", "Expected last entry to start with 2002"); } }
private async void Window_Loaded(object sender, RoutedEventArgs e) { // Do not load your data at design time. if (DesignerProperties.GetIsInDesignMode(this)) { return; } var log = new DatabaseFeedback(_app.EntityContextConnection) { Source = "Main Window" }; await log.ReportInfoFormatAsync(_app.Cts.Token, "{0} User Interface Loaded", Utils.ApplicationName); dList1.ShowMore = false; Title = Utils.ApplicationNameAndVersion; }
public async Task LogEntryMultipleContextLimitTest() { //Arrange var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "LogEntrySingleContextLimitTest" }; Database.SetInitializer(new DropCreateDatabaseAlways<ZvsContext>()); var log = new DatabaseFeedback(dbConnection); for (var i = 0; i < 2003; i++) { await log.ReportInfoFormatAsync(CancellationToken.None, "hello world {0}", i); } using (var context = new ZvsContext(dbConnection)) { var currentLogEntryCount = context.LogEntries.Count(); var firstentry = await context.LogEntries.OrderBy(o => o.Datetime).FirstAsync(); var lastEntry = await context.LogEntries.OrderByDescending(o => o.Datetime).FirstAsync(); //Aseert Assert.IsTrue(currentLogEntryCount == 2000, "Expected 2000 entries and got " + currentLogEntryCount); Assert.IsTrue(firstentry.Message == "hello world 3", "Expected first entry to start with 3"); Assert.IsTrue(lastEntry.Message == "hello world 2002", "Expected last entry to start with 2002"); } }
public async Task LogEntryLimitMultiThreadedTest() { //Arrange var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "LogEntryLimitMultiThreadedTest" }; Database.SetInitializer(new DropCreateDatabaseAlways<ZvsContext>()); var log = new DatabaseFeedback(dbConnection); var task1 = Task.Run(async () => { for (var i = 0; i < 1500; i++) { await log.ReportInfoFormatAsync(CancellationToken.None, "loop1 {0}", i); } }); var task2 = Task.Run(async () => { for (var i = 0; i < 400; i++) { await log.ReportInfoFormatAsync(CancellationToken.None, "loop2 {0}", i); } }); var task3 = Task.Run(async () => { using (var context = new ZvsContext(dbConnection)) { for (var i = 0; i < 700; i++) { context.LogEntries.Add(new LogEntry { Datetime = DateTime.Now, Level = LogEntryLevel.Info, Message = string.Format("loop3 {0}", i), Source = "Source" }); } await context.SaveChangesAsync(CancellationToken.None); } }); await Task.WhenAll(task1, task2, task3); using (var context = new ZvsContext(dbConnection)) { var currentLogEntryCount = context.LogEntries.Count(); //Assert Assert.IsTrue(currentLogEntryCount == 2000, "Expected 2000 entries and got " + currentLogEntryCount); } }