public async Task TestCheckFixCacheValuesServiceFindFixReviewsOk() { //SETUP var options = SqliteInMemory.CreateOptions <BookDbContext>(); using var context = new BookDbContext(options); context.Database.EnsureCreated(); var books = context.SeedDatabaseFourBooks(); //The Review cache values will be incorrect, and createUpdate not set SetAllBooksAsUpdatedNow(books); books[3].UpdateReviewCachedValues(2, books[3].Reviews.Average(x => x.NumStars)); await context.SaveChangesAsync(); var logs = new List <LogOutput>(); var logger = new Logger <CheckFixCacheValuesService>(new LoggerFactory(new[] { new MyLoggerProviderActionOut(logs.Add) })); var service = new CheckFixCacheValuesService(context, logger); //ATTEMPT var notes = await service.RunCheckAsync(new DateTime(2000, 1, 1), true, default); //VERIFY logs.Count.ShouldEqual(0); notes.First().ShouldEqual("Looked at 4 SQL books and found no errors"); }
public async Task TestCheckFixCacheValuesServiceFindBadOnlyReviews() { //SETUP var options = SqliteInMemory.CreateOptions <BookDbContext>(); using var context = new BookDbContext(options); context.Database.EnsureCreated(); var books = context.SeedDatabaseFourBooks(); //The Review cache values will be incorrect, and createUpdate not set SetAllBooksAsUpdatedNow(books); await context.SaveChangesAsync(); var logs = new List <LogOutput>(); var logger = new Logger <CheckFixCacheValuesService>(new LoggerFactory(new[] { new MyLoggerProviderActionOut(logs.Add) })); var service = new CheckFixCacheValuesService(context, logger); //ATTEMPT var notes = await service.RunCheckAsync(new DateTime(2000, 1, 1), false, default); //VERIFY context.ChangeTracker.Clear(); var readBook = context.Books.Single(x => x.BookId == books[3].BookId); readBook.ReviewsAverageVotes.ShouldEqual(0); readBook.ReviewsCount.ShouldEqual(0); logs.Count.ShouldEqual(1); notes.First().ShouldEqual("Looked at 4 SQL books and found 1 errors (not fixed)"); notes[1].ShouldEqual("BookId: 4"); }
public async Task TestCheckFixCacheValuesServiceFindOnlyName() { //SETUP var options = SqliteInMemory.CreateOptions <BookDbContext>(); using var context = new BookDbContext(options); context.Database.EnsureCreated(); var books = context.SeedDatabaseFourBooks(); //The Review cache values will be incorrect, and createUpdate not set SetAllBooksAsUpdatedNow(books.Take(2)); books[0].AuthorsLink.Single().Author.Name = "New Name"; await context.SaveChangesAsync(); var logs = new List <LogOutput>(); var logger = new Logger <CheckFixCacheValuesService>(new LoggerFactory(new[] { new MyLoggerProviderActionOut(logs.Add) })); var service = new CheckFixCacheValuesService(context, logger); //ATTEMPT var notes = await service.RunCheckAsync(new DateTime(2000, 1, 1), false, default); //VERIFY context.ChangeTracker.Clear(); var readBooks = context.Books.ToList(); readBooks[0].AuthorsOrdered.ShouldEqual("Martin Fowler"); readBooks[1].AuthorsOrdered.ShouldEqual("Martin Fowler"); logs.Count.ShouldEqual(2); notes.First().ShouldEqual("Looked at 2 SQL books and found 2 errors (not fixed)"); notes[1].ShouldEqual("BookId: 1"); notes[3].ShouldEqual("BookId: 2"); }