public async Task GetAuthorByIdShouldReturnNullWhenDeleted() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); await db.Authors.AddAsync( new Author { FirstName = "first1", SecondName = "second1", LastName = "last1", IsDeleted = true, DeletedOn = DateTime.UtcNow, }); await db.SaveChangesAsync(); var authorsService = new AuthorsService(db); var result = await authorsService.GetAuthorByIdAsync <AuthorTestModel>(1); Assert.Null(result); }
public async Task GetAuthorByIdShouldReturnNullWhenNotFound() { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); var authorsService = new AuthorsService(db); var result = await authorsService.GetAuthorByIdAsync <AuthorTestModel>(1); Assert.Null(result); }
public async Task GetAuthorByIdShouldReturnRightAuthor(int authorId) { var options = new DbContextOptionsBuilder <AlexandriaDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var db = new AlexandriaDbContext(options); await db.Authors.AddRangeAsync( new Author { FirstName = "first1", SecondName = "second1", LastName = "last1", }, new Author { FirstName = "first1", SecondName = "second1", LastName = "last1", }, new Author { FirstName = "first1", SecondName = "second1", LastName = "last1", }); await db.SaveChangesAsync(); var authorsService = new AuthorsService(db); var result = authorsService.GetAuthorByIdAsync <AuthorTestModel>(authorId); Assert.Equal(authorId, result.Id); }