public async Task Update_given_existing_character_Updates_properties() { var context = new Mock <IFuturamaContext>(); var entity = new Character { Id = 42 }; context.Setup(c => c.Characters.FindAsync(42)).ReturnsAsync(entity); using (var repository = new EntityFrameworkCharacterRepository(context.Object)) { var character = new CharacterUpdateDTO { Id = 42, ActorId = 12, Name = "Name", Species = "Species", Planet = "Planet", Image = "Image" }; await repository.UpdateAsync(character); } Assert.Equal(12, entity.ActorId); Assert.Equal("Name", entity.Name); Assert.Equal("Species", entity.Species); Assert.Equal("Planet", entity.Planet); Assert.Equal("Image", entity.Image); }
public async Task Update_given_non_existing_character_does_not_SaveChangesAsync() { var context = new Mock <IFuturamaContext>(); context.Setup(c => c.Characters.FindAsync(42)).ReturnsAsync(default(Character)); using (var repository = new EntityFrameworkCharacterRepository(context.Object)) { var character = new CharacterUpdateDTO { Id = 42, Name = "Name", Species = "Species", }; await repository.UpdateAsync(character); } context.Verify(c => c.SaveChangesAsync(default(CancellationToken)), Times.Never); }
public async Task Update_given_non_existing_character_returns_false() { var context = new Mock <IFuturamaContext>(); context.Setup(c => c.Characters.FindAsync(42)).ReturnsAsync(default(Character)); using (var repository = new EntityFrameworkCharacterRepository(context.Object)) { var character = new CharacterUpdateDTO { Id = 42, Name = "Name", Species = "Species", }; var result = await repository.UpdateAsync(character); Assert.False(result); } }