public async Task DeleteAsyncPet() { var list = new List <Pet>(); var mockRepo = new Mock <IDeletableEntityRepository <Pet> >(); mockRepo.Setup(x => x.All()).Returns(list.AsQueryable()); mockRepo.Setup(x => x.AddAsync(It.IsAny <Pet>())); mockRepo.Setup(x => x.Delete(It.IsAny <Pet>())) .Callback( (Pet pet) => list.Remove(pet)); var service = new PetsService(mockRepo.Object); var pet = new Pet { BreedId = 1, CityId = 1, Id = 1, Name = "GoshoCat", DateOfBirth = new DateTime(2008, 3, 1, 7, 0, 0), SpecieId = 1, AddedByUserId = "PeshoId", }; list.Add(pet); await service.DeleteAsync(1, "PeshoId"); Assert.Equal(0, service.GetCount()); }
public async Task DeleteAsyncPetWithWrongUserId() { var list = new List <Pet>(); var mockRepo = new Mock <IDeletableEntityRepository <Pet> >(); mockRepo.Setup(x => x.All()).Returns(list.AsQueryable()); mockRepo.Setup(x => x.Delete(It.IsAny <Pet>())); var service = new PetsService(mockRepo.Object); var pet = new Pet { BreedId = 1, CityId = 1, Id = 1, Name = "GoshoCat", DateOfBirth = new DateTime(2008, 3, 1, 7, 0, 0), SpecieId = 1, AddedByUserId = "PeshoId", }; list.Add(pet); Assert.False(await service.DeleteAsync(1, "WrongId")); }