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 AddingAsyncAPetTestAndGetCount() { 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>())) .Callback( (Pet pet) => list.Add(pet)); var service = new PetsService(mockRepo.Object); var inputModel = new AddPetInputModel { BreedId = 1, CityId = 1, Id = 1, Name = "Gosho", DateOfBirth = new DateTime(2008, 3, 1, 7, 0, 0), Gender = "Male", }; var imagePaths = new List <string>(); imagePaths.Add("vasko.com"); await service.AddAsync(inputModel, 1, "Pesho", imagePaths); Assert.Equal(1, service.GetCount()); }