public void TestPostTouristSpotHas201StatusCode() { var touristSpot = TouristSpotModel.ToEntity(); touristSpot.Region = new Region { Id = touristSpot.RegionId.Value }; touristSpot.TouristSpotCategories = new List <TouristSpotCategory>() { new TouristSpotCategory { CategoryId = Category.Id, Category = Category, TouristSpot = touristSpot, TouristSpotId = touristSpot.Id } }; var touristSpotLogicMock = new Mock <ITouristSpotLogic>(MockBehavior.Strict); touristSpotLogicMock.Setup(m => m.Create(TouristSpotModel.ToEntity())).Returns(touristSpot); var touristSpotController = new TouristSpotController(touristSpotLogicMock.Object); var result = touristSpotController.Post(TouristSpotModel) as CreatedResult; touristSpotLogicMock.VerifyAll(); Assert.AreEqual(result.StatusCode, 201); }
public void TestPostTouristSpotReturnsValidModel() { var touristSpot = TouristSpotModel.ToEntity(); touristSpot.Region = new Region { Id = touristSpot.RegionId.Value }; touristSpot.TouristSpotCategories = new List <TouristSpotCategory>() { new TouristSpotCategory() { CategoryId = Category.Id, Category = Category, TouristSpot = touristSpot, TouristSpotId = touristSpot.Id } }; var touristSpotLogicMock = new Mock <ITouristSpotLogic>(MockBehavior.Strict); touristSpotLogicMock.Setup(m => m.Create(TouristSpotModel.ToEntity())).Returns(touristSpot); var touristSpotController = new TouristSpotController(touristSpotLogicMock.Object); var result = touristSpotController.Post(TouristSpotModel) as CreatedResult; var content = result.Value as TouristSpotBasicInfoModel; touristSpotLogicMock.VerifyAll(); Assert.IsTrue(content.Equals(new TouristSpotBasicInfoModel(touristSpot))); }
public void CreateInvalidTouristSpotAlredyExistTest() { var touristSpotMock = new Mock <ITouristSpotManagement>(MockBehavior.Strict); touristSpotMock.Setup(m => m.Create(It.IsAny <TouristSpot>(), It.IsAny <Guid>(), It.IsAny <List <Guid> >())). Throws(new DomainBusinessLogicException("El punto turistico a crear ya existe.")); TouristSpotController touristSpotController = new TouristSpotController(touristSpotMock.Object); var result = touristSpotController.Post(touristSpotRequestModel); var createdResult = result as BadRequestObjectResult; touristSpotMock.VerifyAll(); Assert.AreEqual(400, createdResult.StatusCode); }
public void InvalidCreateTouristSpotTestInternalServerError() { var touristSpotMock = new Mock <ITouristSpotManagement>(MockBehavior.Strict); touristSpotMock.Setup(m => m.Create(It.IsAny <TouristSpot>(), It.IsAny <Guid>(), It.IsAny <List <Guid> >())). Throws(new ServerBusinessLogicException()); TouristSpotController touristSpotController = new TouristSpotController(touristSpotMock.Object); var result = touristSpotController.Post(touristSpotRequestModel); var createdResult = result as ObjectResult; touristSpotMock.VerifyAll(); Assert.AreEqual(500, createdResult.StatusCode); }
public void InvalidCreateTouristSpotTestWithoutCategoriesAndRegions() { var touristSpotMock = new Mock <ITouristSpotManagement>(MockBehavior.Strict); touristSpotMock.Setup(m => m.Create(It.IsAny <TouristSpot>(), It.IsAny <Guid>(), It.IsAny <List <Guid> >())). Throws(new ClientBusinessLogicException("No se pudo encontrar la region y/o las categorias asociadas")); TouristSpotController touristSpotController = new TouristSpotController(touristSpotMock.Object); var result = touristSpotController.Post(touristSpotRequestModel); var createdResult = result as NotFoundObjectResult; touristSpotMock.VerifyAll(); Assert.AreEqual(404, createdResult.StatusCode); }
public void InvalidCreateTouristSpotTestFormatError() { var touristSpotMock = new Mock <ITouristSpotManagement>(MockBehavior.Strict); touristSpotMock.Setup(m => m.Create(It.IsAny <TouristSpot>(), It.IsAny <Guid>(), It.IsAny <List <Guid> >())). Throws(new DomainBusinessLogicException("No se puede crear el punto turistico debido a que no es valido.")); TouristSpotController touristSpotController = new TouristSpotController(touristSpotMock.Object); var result = touristSpotController.Post(touristSpotRequestModel); var createdResult = result as BadRequestObjectResult; touristSpotMock.VerifyAll(); Assert.AreEqual(400, createdResult.StatusCode); }
public void TestPostTouristSpotInvalidReturnsError400() { TouristSpotModel.Name = ""; var touristSpot = TouristSpotModel.ToEntity(); var touristSpotLogicMock = new Mock <ITouristSpotLogic>(MockBehavior.Strict); touristSpotLogicMock.Setup(m => m.Create(touristSpot)).Returns(touristSpot); var touristSpotController = new TouristSpotController(touristSpotLogicMock.Object); var result = touristSpotController.Post(TouristSpotModel) as BadRequestObjectResult; Assert.AreEqual(result.StatusCode, 400); }
public void TestPostAlreadyExistingObject() { TouristSpot touristSpot = new TouristSpot() { Name = "Virgen del verdún", }; TouristSpotModelIn touristSpotModel = new TouristSpotModelIn(touristSpot); var mock = new Mock <ITouristSpotLogic>(MockBehavior.Strict); mock.Setup(ts => ts.Add(touristSpot)).Throws(new RepeatedObjectException()); var controller = new TouristSpotController(mock.Object); var result = controller.Post(touristSpotModel) as BadRequestObjectResult; var expectedResult = new BadRequestObjectResult("A tourist spot with such name has been already registered."); mock.VerifyAll(); Assert.AreEqual(expectedResult.Value, result.Value); }
public void TestSuccessfulPost() { TouristSpot touristSpot = new TouristSpot() { Name = "Virgen del verdún", }; TouristSpotModelIn touristSpotModel = new TouristSpotModelIn(touristSpot); var mock = new Mock <ITouristSpotLogic>(MockBehavior.Strict); mock.Setup(ts => ts.Add(touristSpot)); var controller = new TouristSpotController(mock.Object); var result = controller.Post(touristSpotModel) as CreatedAtRouteResult; var expectedResult = new CreatedAtRouteResult(routeValues: new { id = touristSpotModel.Id }, value: new TouristSpotModelIn(touristSpot)); mock.VerifyAll(); Assert.AreEqual(expectedResult.Value, result.Value); }
public void CreateTouristSpotNotEqualsIdTest() { TouristSpotForRequestModel touristSpotRequestModel = new TouristSpotForRequestModel() { Id = touristSpotAdded.Id, Name = "Punta del Este", Description = "Un lugar increible", RegionId = regionForTouristSpot.Id, ImagePath = "Desktop/joaco.jpg", ListOfCategoriesId = new List <Guid>() { category.Id } }; var touristSpotMock = new Mock <ITouristSpotManagement>(MockBehavior.Strict); touristSpotMock.Setup(m => m.Create(It.IsAny <TouristSpot>(), It.IsAny <Guid>(), It.IsAny <List <Guid> >())).Returns(touristSpotAdded); TouristSpotController touristSpotController = new TouristSpotController(touristSpotMock.Object); var result = touristSpotController.Post(touristSpotRequestModel); var createdResult = result as CreatedAtRouteResult; var model = createdResult.Value as TouristSpotForResponseModel; touristSpotMock.VerifyAll(); TouristSpotForResponseModel touristSpotResponseModel = new TouristSpotForResponseModel() { Id = Guid.NewGuid(), Name = "Punta del ", Description = "Un lugar increible", RegionModel = RegionForResponseModel.ToModel(regionForTouristSpot), ListOfCategoriesModel = new List <CategoryModel>() { CategoryModel.ToModel(category) } }; Assert.AreNotEqual(touristSpotRequestModel, model); }