public void GetByIdShouldWorkCorrect() { var trophiesList = new List <Trophy> { new Trophy { Id = 1, BaitDescription = "a" }, new Trophy { Id = 22, BaitDescription = "bc" }, }; var repository = new Mock <IDeletableEntityRepository <Trophy> >(); repository.Setup(r => r.All()).Returns(trophiesList.AsQueryable()); var service = new TrophiesService(null, repository.Object); AutoMapperConfig.RegisterMappings(typeof(TrophyModel).Assembly); var trophy = service.GetById <TrophyModel>(22); Assert.Equal(22, trophy.Id); Assert.Equal("bc", trophy.BaitDescription); }
public async Task UpdateAsyncShouldWorkCorrect() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; using var db = new ApplicationDbContext(options); var trophyRepository = new EfDeletableEntityRepository <Trophy>(db); var service = new TrophiesService(null, trophyRepository); await trophyRepository.AddAsync(new Trophy { Id = 1, Weight = 50, BaitDescription = "corn", LakeId = 1, OwnerId = "asdasd123", }); await trophyRepository.SaveChangesAsync(); var input = new EditTrophyInputModel { Weight = 49, BaitDescription = "grass", }; await service.UpdateAsync(1, input); await trophyRepository.SaveChangesAsync(); AutoMapperConfig.RegisterMappings(typeof(TrophyModel).Assembly); var trophy = service.GetById <TrophyModel>(1); Assert.Equal(49, trophy.Weight); Assert.Equal("grass", trophy.BaitDescription); }