public void CreateApartment_RegularValues_OkResults() { //Arrange var apt = new Mock <IApartment>(); apt.SetupGet(a => a.Id).Returns(4); apt.SetupGet(a => a.BuildingId).Returns(1); apt.SetupGet(a => a.FacingDirection).Returns(model.FacingDirection); apt.SetupGet(a => a.Level).Returns(model.Level); apt.SetupGet(a => a.Number).Returns(model.Number); apt.SetupGet(a => a.TenantsAllowed).Returns(model.TenantsAllowed); facade.Setup( f => f.CreateApartment(model.Level, model.Number, model.TenantsAllowed, model.FacingDirection, "3445")).Returns(apt.Object); var controller = new ApartmentController(facade.Object) { ControllerContext = controllerContext }; //Act var result = controller.CreateApartment(model); //Assert Assert.NotNull(result); var okresult = Assert.IsType <OkNegotiatedContentResult <GenericResponse> >(result); Assert.Equal(true, okresult.Content.IsSuccess); }
public void CreateFacility_ThrowsError_BadModel() { //Arrange var controller = new ApartmentController(facade.Object) { ControllerContext = controllerContext }; controller.ModelState.AddModelError("Key", "ErrorMessage"); //Act var result = controller.CreateApartment(model); //Assert Assert.NotNull(result); Assert.IsType <InvalidModelStateResult>(result); }
public void CreateApartment_ThrowsError_InternalError() { //Arrange var exception = new ConnApsDomain.Exceptions.InternalException(); facade.Setup(f => f.CreateApartment(model.Level, model.Number, model.TenantsAllowed, model.FacingDirection, "3445")).Throws(exception); var controller = new ApartmentController(facade.Object) { ControllerContext = controllerContext }; //Act var result = controller.CreateApartment(model); //Assert Assert.NotNull(result); Assert.IsType <InternalServerErrorResult>(result); }
public void CreateApartment_InvalidValues_BadRequest() { //Arrange var exception = new ConnApsDomain.Exceptions.NotFoundException("Apartment"); facade.Setup(f => f.CreateApartment(model.Level, model.Number, model.TenantsAllowed, model.FacingDirection, "3445")).Throws(exception); var controller = new ApartmentController(facade.Object) { ControllerContext = controllerContext }; //Act var result = controller.CreateApartment(model); //Assert Assert.NotNull(result); var badRequest = Assert.IsType <BadRequestErrorMessageResult>(result); Assert.Equal("The Apartment you requested was not found. Please search again.", badRequest.Message); }