public void Get_CallsRepositoryGetAllMethod() { // arrange var breedsController = new BreedsController(_repository); // act breedsController.Get(); // assert _repository.AssertWasCalled(X => X.GetAll()); }
public void Get_ReturnsListOfBreedOrderedAlphabeticallyAscending() { // arrange var breedsController = new BreedsController(_repository); // act var result = breedsController.Get().ToList(); // assert Assert.That(result, Is.TypeOf<List<Breed>>()); Assert.That(result.First().Name, Is.EqualTo("Afghan Hound")); Assert.That(result.Last().Name, Is.EqualTo("Whippet")); }
public void GetAllBreedsErrorNotFoundTest() { //Arrange List <Breed> expectedBreeds = null; var mockBreedsBusinessLogic = new Mock <IBreedsBusinessLogic>(); mockBreedsBusinessLogic .Setup(bl => bl.GetAllBreeds()) .Returns(expectedBreeds); var controller = new BreedsController(mockBreedsBusinessLogic.Object); //Act IHttpActionResult obtainedResult = controller.Get(); //Assert mockBreedsBusinessLogic.VerifyAll(); Assert.IsInstanceOfType(obtainedResult, typeof(NotFoundResult)); }
public void GetBreedByIdNotFoundErrorTest() { //Arrange var fakeGuid = Guid.NewGuid(); var mockBreedsBusinessLogic = new Mock <IBreedsBusinessLogic>(); mockBreedsBusinessLogic .Setup(bl => bl.GetByID(fakeGuid)) .Returns((Breed)null); // Debemos retornar null, es lo que le exigimos al Mock para lograr // que el controller nos de NotFound var controller = new BreedsController(mockBreedsBusinessLogic.Object); //Act IHttpActionResult obtainedResult = controller.Get(fakeGuid); //Assert mockBreedsBusinessLogic.VerifyAll(); Assert.IsInstanceOfType(obtainedResult, typeof(NotFoundResult)); }
public void GetAllBreedsOkTest() { //Arrange var expectedBreeds = GetFakeBreeds(); var mockBreedsBusinessLogic = new Mock <IBreedsBusinessLogic>(); mockBreedsBusinessLogic .Setup(bl => bl.GetAllBreeds()) .Returns(expectedBreeds); var controller = new BreedsController(mockBreedsBusinessLogic.Object); //Act IHttpActionResult obtainedResult = controller.Get(); var contentResult = obtainedResult as OkNegotiatedContentResult <IEnumerable <Breed> >; //Assert mockBreedsBusinessLogic.VerifyAll(); Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.AreEqual(expectedBreeds, contentResult.Content); }
public void GetBreedByIdOkTest() { //Arrange var fakeBreed = GetAFakeBreed(); var fakeGuid = GetARandomFakeGuid(); var mockBreedsBusinessLogic = new Mock <IBreedsBusinessLogic>(); mockBreedsBusinessLogic .Setup(bl => bl.GetByID(fakeGuid)) .Returns(fakeBreed); var controller = new BreedsController(mockBreedsBusinessLogic.Object); //Act IHttpActionResult obtainedResult = controller.Get(fakeGuid); var contentResult = obtainedResult as OkNegotiatedContentResult <Breed>; //Assert mockBreedsBusinessLogic.VerifyAll(); Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.AreEqual(fakeGuid, contentResult.Content.Id); }