public void WhenValidResponseFromAPI_ValidateResponseModel() { //Arrange PetsByGenderResponse moqResponse = new PetsByGenderResponse() { PetsByGenderList = new List <PetsByGender> { new PetsByGender() { Gender = "Male", petsList = new List <string> { "Max", "Tom" } }, new PetsByGender() { Gender = "Female", petsList = new List <string> { "Maxi" } } } }; PetsController controllerUnderTest = new PetsController(_moqPetsBusinesslogic.Object); _moqPetsBusinesslogic.Setup(m => m.RetreivePetsByType(It.IsAny <string>())).Returns(moqResponse); // Act var viewresult = controllerUnderTest.Get("Cat") as ViewResult; var responseModel = (PetsByGenderResponse)viewresult.Model; // Assert Assert.Greater(responseModel.PetsByGenderList.Count, 0); }
public void PetsController_GetAllPetsByOwnerGender_Test() { var list = new List <OwnerGenderPets>(); list.Add(new OwnerGenderPets { Gender = "M", PetNames = new List <string> { "abc", "def", "ghi" } }); list.Add(new OwnerGenderPets { Gender = "F", PetNames = new List <string> { "jkl", "mno", "pqr" } }); petOwnerService.GetAllPetsByOwnerGenderAsync(PetType.Cat).Returns(list); _petsController = new PetsController(petOwnerService); var result = _petsController.GetAllPetsByOwnerGender(PetType.Cat).Result; Assert.IsType <OkObjectResult>(result); var value = ((OkObjectResult)result).Value; Assert.Equal(2, (value as List <OwnerGenderPets>).Count); }
public void Apos_A_Criacao_De_Um_Pet_Deve_Ser_Possivel_Pesquisar_Pelo_Id_Gerado_Para_O_Mesmo() { var controller = new PetsController(); var resultadoCriacao = controller.CriarPet(new Pet() { Nome = "Teddy", Status = StatusPet.Disponivel, Categoria = new Categoria { Nome = "Basset-Hound" }, Tags = new List <Tag> { new Tag { Descricao = "Babão" }, new Tag { Descricao = "Brincalhão" } } }); var criado = resultadoCriacao as CreatedAtRouteResult; Assert.IsNotNull(criado); var petCriado = criado.Value as Pet; Assert.IsNotNull(petCriado); var resultadoBusca = controller.BuscarPetPorId(petCriado.Id); Assert.IsNotNull(resultadoBusca as OkObjectResult); }
public void WhenControllerCalled_verifyViewname() { //Arrange PetsByGenderResponse moqResponse = new PetsByGenderResponse() { PetsByGenderList = new List <PetsByGender> { new PetsByGender() { Gender = "Male", petsList = new List <string> { "Max", "Tom" } }, new PetsByGender() { Gender = "Female", petsList = new List <string> { "Maxi" } } } }; PetsController controllerUnderTest = new PetsController(_moqPetsBusinesslogic.Object); _moqPetsBusinesslogic.Setup(m => m.RetreivePetsByType(It.IsAny <string>())).Returns(moqResponse); // Act var viewresult = controllerUnderTest.Get("Cat") as ViewResult; // Assert Assert.AreEqual("pets", viewresult.ViewName); }
public void CatsByOwnerGenderTest() { List <RequestModel> ownerList = new List <RequestModel> { new RequestModel { Name = "Bob", Age = 23, Gender = "Male", Pets = new List <Pet> { new Pet { Name = "Garfield", Type = "Cat" } } } }; List <ResponseModel> listOfPets = new List <ResponseModel> { new ResponseModel { Gender = "Male", Names = new List <string> { "Garfield" } } }; var helper = new Mock <IPetsRepository>(); var petsController = new PetsController(helper.Object); helper.Setup(p => p.GetOwners <List <RequestModel> >()).Returns(ownerList); helper.Setup(p => p.GetCatsByOwnerGender <List <ResponseModel> >(ownerList)).Returns(listOfPets); var pets = petsController.GetCatsByOwnerGender(); Assert.True(listOfPets[0].Gender == pets[0].Gender); Assert.True(listOfPets[0].Names.Count == pets[0].Names.Count); }
public static void Load() { PetsController.Add(CREWPET); PetsController.Add(BEAR); PetsController.Add(FOX); PetsController.Add(RABBIT); }
public void Pets_Atualizados_Devem_Ser_Retornados_No_Obter_Por_Id() { var pet = CriarTeddy(); var controller = new PetsController(); var resultadoCriacao = controller.CriarPet(pet) as CreatedAtRouteResult; Assert.IsNotNull(resultadoCriacao); var petCriado = resultadoCriacao.Value as Pet; petCriado.Nome = "Joaquim"; var resultadoAlteracao = controller.AlterarPet(petCriado.Id, petCriado) as OkObjectResult; Assert.IsNotNull(resultadoAlteracao); var resultadoBusca = controller.BuscarPetPorId(petCriado.Id) as OkObjectResult; Assert.IsNotNull(resultadoBusca); var petBuscado = resultadoBusca.Value as Pet; Assert.IsNotNull(petBuscado); Assert.AreEqual("Joaquim", petBuscado.Nome); }
public SizeEntity[] GetPetSize(int?id = 0, String name = "") { ValidSecurityToken(authHeader); PetsController controller = new PetsController(); SizeEntity[] size; if (id < 0) { CacheHelper.Add("GetPetsSize", controller.GetPetsSize(), DateTime.Now.AddDays(1)); } if (CacheHelper.Exists("GetPetsSize") == false) { CacheHelper.Add("GetPetsSize", controller.GetPetsSize(), DateTime.Now.AddDays(1)); } CacheHelper.Get("GetPetsSize", out size); if (!string.IsNullOrEmpty(name) && id <= 0) { return(size.Where(x => x.Name.ToLower().Contains(name.ToLower())).ToArray()); } else if (string.IsNullOrEmpty(name) && id > 0) { return(size.Where(x => x.Id == id).ToArray()); } else if (!string.IsNullOrEmpty(name) && id > 0) { return(size.Where(x => x.Id == id && x.Name.ToLower().Contains(name.ToLower())).ToArray()); } return(size); }
public void PutPet_ShouldFail_WhenDifferentID() { var controller = new PetsController(new TestPetQuestContext()); var badresult = controller.PutPet(999, GetDemoPet()); Assert.IsInstanceOfType(badresult, typeof(BadRequestResult)); }
public void Pesquisar_Um_Pet_Por_Um_Id_Inexistente_Deve_Retornar_Not_Found() { var controller = new PetsController(); var resultadoBusca = controller.BuscarPetPorId(int.MaxValue); Assert.IsNotNull(resultadoBusca as NotFoundObjectResult); }
public void PetGetReturnsNotFound() { var mockRepo = new Mock <IPetStoreRepository>(); var controller = new PetsController(mockRepo.Object); IHttpActionResult actionResult = controller.GetPet(3); Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult)); }
public void PetsIndex() { var controller = new PetsController(); var result = controller.Index() as ViewResult; var modelObj = result.ViewData.Model; Assert.IsNotNull(modelObj); }
public void GetPetDetails() { //Pets id cannot be null, if this test fails, //it means that that the method Details() doesn't work or the pets table is empty (or no connection to db to database) PetsController pets = new PetsController(); ActionResult result = pets.Details(3); Assert.IsInstanceOfType(result, typeof(ViewResult)); }
public void Remover_Pet_Deve_Retornar_Erro_Quando_O_Id_For_Inexistente() { var controller = new PetsController(); var badRequest = controller.RemoverPet(1) as NotFoundObjectResult; Assert.IsNotNull(badRequest); Assert.AreEqual("O pet id 1 não foi encontrado", badRequest.Value); }
public void Atualizar_Pet_Deve_Retornar_Erro_Quando_O_Pet_For_Nulo() { var controller = new PetsController(); var badRequest = controller.AlterarPet(1, null) as BadRequestObjectResult; Assert.IsNotNull(badRequest); Assert.AreEqual("O parametro petAtualizado não pode ser nulo", badRequest.Value); }
private PetsController GetController(IPetProvider policyProvider) { var controller = new PetsController(policyProvider, _debugContext) { Request = new HttpRequestMessage() }; controller.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); return(controller); }
public void PetsDetails() { // Arrange PetsController petController = new PetsController(); // Act ViewResult result = petController.PetProfile(5) as ViewResult; // Assert Assert.IsNotNull(result); }
public void PetsEdit() { // Arrange PetsController petController = new PetsController(); // Act ViewResult result = petController.EditPet(5) as ViewResult; // Assert Assert.IsNotNull(result); }
public void PutPet_ShouldReturnStatusCode() { var controller = new PetsController(new TestPetQuestContext()); var item = GetDemoPet(); var result = controller.PutPet(item.ID, item) as StatusCodeResult; Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(StatusCodeResult)); Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode); }
public void DeleteProduct_ShouldReturnOK() { var context = new TestPetQuestContext(); var item = GetDemoPet(); context.Pets.Add(item); var controller = new PetsController(context); var result = controller.DeletePet(3) as OkNegotiatedContentResult <Pet>; Assert.IsNotNull(result); Assert.AreEqual(item.ID, result.Content.ID); }
public void TestMethod1() { var controller = new PetsController(new PetQuest2.Tests.TestPetQuestContext()); var pet = GetDemoPet(); var result = controller.PostPet(pet) as CreatedAtRouteNegotiatedContentResult <Pet>; Assert.IsNotNull(result); Assert.AreEqual(result.RouteName, "DefaultApi"); Assert.AreEqual(result.RouteValues["id"], result.Content.ID); Assert.AreEqual(result.Content.Name, pet.Name); }
public void PetPostSetsLocationHeader() { var mockRepo = new Mock <IPetStoreRepository>(); var controller = new PetsController(mockRepo.Object); IHttpActionResult actionResult = controller.PostPet(new Pet { Id = 10, Name = "Kitty", Category = "White", IsAvailable = true, PhotoUrl = "" }); var createdResult = actionResult as CreatedAtRouteNegotiatedContentResult <Pet>; Assert.IsNotNull(createdResult); Assert.AreEqual("DefaultApi", createdResult.RouteName); Assert.AreEqual(10, createdResult.RouteValues["id"]); }
public void PostPet_ShouldReturnSamePet() { var controller = new PetsController(new TestPetQuestContext()); var item = GetDemoPet(); var result = controller.PostPet(item) as CreatedAtRouteNegotiatedContentResult <Pet>; Assert.IsNotNull(result); Assert.AreEqual(result.RouteName, "DefaultApi"); Assert.AreEqual(result.RouteValues["id"], result.Content.ID); Assert.AreEqual(result.Content.Name, item.Name); }
public void GetPet_ShouldReturnPetWithSameID() { var demo = GetDemoPet(); var context = new TestPetQuestContext(); context.Pets.Add(demo); var controller = new PetsController(context); var result = controller.GetPet(3) as OkNegotiatedContentResult <Pet>; Assert.IsNotNull(result); Assert.AreEqual(3, result.Content.ID); }
public void WhenUnhandledExceptionOccursInController_ResponseContainsErrors() { //Arrange PetsController controllerUnderTest = new PetsController(_moqPetsBusinesslogic.Object); _moqPetsBusinesslogic.Setup(m => m.RetreivePetsByType(It.IsAny <string>())).Throws(new Exception("object reference not set to instance")); // Act var viewresult = controllerUnderTest.Get("Cat") as ViewResult; var responseModel = (PetsByGenderResponse)viewresult.Model; // Assert Assert.IsTrue(responseModel.Errors.Any(error => error.ErrorMessage == "object reference not set to instance"), ""); }
public async Task Api_Get_Grouped_Results_Returns_Data_GroupedByOwnerGender_Sorted_By_Name_With_Ok_Response() { var mockDataForGrouping = new List <GroupedByOwnerGenderViewModel> { new GroupedByOwnerGenderViewModel { OwnerGender = "Female", Cats = new List <PetDetailsViewModel> { new PetDetailsViewModel { Name = "Garfield", OwnerName = "Selina" }, new PetDetailsViewModel { Name = "Abe", OwnerName = "Selina" } } }, new GroupedByOwnerGenderViewModel { OwnerGender = "Male", Cats = new List <PetDetailsViewModel> { new PetDetailsViewModel { Name = "Jasper", OwnerName = "Bruce" }, new PetDetailsViewModel { Name = "Garry", OwnerName = "Bruce" } } } }; var mockService = new Mock <IPetsService>(); mockService.Setup(x => x.GetCatsGroupedByOwnerGender()) .ReturnsAsync(mockDataForGrouping); var controller = new PetsController(mockService.Object); IActionResult response = await controller.Get().ConfigureAwait(false); response.Should().BeOfType <OkObjectResult>(); var resultObject = ((OkObjectResult)response).Value as List <GroupedByOwnerGenderViewModel>; resultObject.Should().NotBeNull(); resultObject.Count.Should().Be(mockDataForGrouping.Count); JsonConvert.SerializeObject(resultObject).ToLower() .Should() .Be(JsonConvert.SerializeObject(mockDataForGrouping).ToLower()); resultObject[0].OwnerGender.Should().Be("Female"); resultObject[1].OwnerGender.Should().Be("Male"); }
public void Index() { // Arrange PetsController controller = new PetsController(); // Act ViewResult result = controller.Index() as ViewResult; // Assert Assert.IsNotNull(result); var model = result.Model as List <Pet>; Assert.IsNotNull(model); }
public void Pets_Cadastrados_Devem_Ser_Retornados_No_Obter_Por_Id() { var controller = new PetsController(); var resultadoCriacao = controller.CriarPet(CriarTeddy()) as CreatedAtRouteResult; Assert.IsNotNull(resultadoCriacao); var petCriado = resultadoCriacao.Value as Pet; Assert.IsNotNull(petCriado); var resultadoBusca = controller.BuscarPetPorId(petCriado.Id); Assert.IsNotNull(resultadoBusca as OkObjectResult); }
public void NoPetsFoundTest() { //Arrange var jsonResult = String.Empty; AGLHttpClient.Setup(x => x.GetAsync(new Uri("http://agl-developer-test.azurewebsites.net/people.json"))).ReturnsAsync(jsonResult); SUT = new PetsController(logger, AGLHttpClient.Object); //Act var response = SUT.GetAsync("female", "cat"); //Assert Assert.IsNotNull(response.Exception); Assert.IsNotNull(response.Exception.Message); }
public void Todos_Pets_Cadastrados_Devem_Ser_Retornados_No_Obter_Todos() { var teddy = CriarTeddy(); var joazinho = CriarJoaozinho(); var petController = new PetsController(); var resultadoCriacaoTeddy = petController.CriarPet(teddy); var resultadoCriacaoJoazinho = petController.CriarPet(joazinho); var resultadoBuscaPets = petController.BuscarPets() as OkObjectResult; var pets = resultadoBuscaPets.Value as List <Pet>; Assert.AreEqual(2, pets.Count); }