Exemplo n.º 1
0
        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);
        }