public async Task CreatePetReturnsMessage() { var newPet = new PetVm { Name = "Keffas", Latitude = 50.123M, Longitude = -112.3553M, Breed = new Breed { ImgUrl = "//src/img", Name = "terrier", Id = 2 }, Type = new PetType { Id = 1, Name = "Dog" }, Location = "Regina, SK" }; var repo = new FakeModelRepo(); var repoMock = new Mock <IPetRepository>(); var logger = new Mock <ILogger>(); logger.Setup(x => x.Path).Returns("sample"); repoMock.Setup(x => x.ConfirmUniqueName(newPet.Name, newPet.Breed.Id)).Returns(repo.ConfirmUniqueName(newPet.Name, newPet.Breed.Id)); repoMock.Setup(x => x.CreatePet(newPet)).Returns(repo.CreatePet(newPet)); var controller = new PetController(repoMock.Object, logger.Object); var result = await controller.CreatePet(newPet) as CreatedResult; newPet.Name = "Seyi"; var exists = await controller.CreatePet(newPet) as OkObjectResult; if (result != null) { var obj = JsonConvert.DeserializeObject <Result>(JsonConvert.SerializeObject(result.Value)); Assert.Equal("success", obj.Status); } if (exists != null) { var existsObj = JsonConvert.DeserializeObject <Result>(JsonConvert.SerializeObject(exists.Value)); Assert.Equal("exists", existsObj.Status); } }
public async Task GetPetPerPageReturnsPerPage() { var repo = new FakeModelRepo(); var repoMock = new Mock <IPetRepository>(); var logger = new Mock <ILogger>(); logger.Setup(x => x.Path).Returns("sample"); repoMock.Setup(x => x.CountPets()).Returns(repo.CountPets()); repoMock.Setup(x => x.GetPetPerPage(1, 10)).Returns(repo.GetPetPerPage(1, 10)); var controller = new PetController(repoMock.Object, logger.Object); var result = await controller.GetPetsPerPage(1) as OkObjectResult; if (result != null) { dynamic obj = new DynamicObjectResultValue(result.Value); Assert.Equal(2, obj.totalCount); Assert.Equal(1, obj.totalPages); Assert.IsType <List <Pet> >(obj.pets); } }