public void TestPutSuccessful() { TouristSpot touristSpotToUpdate = new TouristSpot() { Name = "Virgen del verdún", Id = 3 }; TouristSpot newData = new TouristSpot() { Name = "The Green Roofs", }; TouristSpotModelIn touristSpotModelToUpdate = new TouristSpotModelIn(touristSpotToUpdate); TouristSpotModelIn newDataModel = new TouristSpotModelIn(newData); var mock = new Mock <ITouristSpotLogic>(MockBehavior.Strict); mock.Setup(ts => ts.Update(touristSpotModelToUpdate.Id, newData)); mock.Setup(ts => ts.Get(touristSpotToUpdate.Id)).Returns(touristSpotToUpdate); var controller = new TouristSpotController(mock.Object); var result = controller.Put(touristSpotModelToUpdate.Id, newDataModel) as OkObjectResult; var expectedResult = new OkObjectResult(new TouristSpotModelOut(touristSpotToUpdate)); mock.VerifyAll(); Assert.AreEqual(expectedResult.Value, result.Value); }
public void TestGetAllTouristSpotsOk() { IEnumerable <TouristSpot> touristSpotsToReturn = new List <TouristSpot>() { new TouristSpot() { Id = 1, Name = "Faro de La Paloma", Description = "Very tall. Traditional.", Image = "image", }, new TouristSpot() { Id = 2, Name = "Playa de los Pescadores", Description = "Cozy, humble.", Image = "image2", } }; var mock = new Mock <ITouristSpotLogic>(MockBehavior.Strict); mock.Setup(ts => ts.GetAll()).Returns(touristSpotsToReturn); var controller = new TouristSpotController(mock.Object); var result = controller.Get(); var okResult = result as OkObjectResult; var touristSpots = okResult.Value as IEnumerable <TouristSpotModelOut>; mock.VerifyAll(); Assert.IsTrue(touristSpotsToReturn.Select(ts => new TouristSpotModelOut(ts)).SequenceEqual(touristSpots)); }
public void TestPutNotFoundObject() { TouristSpot touristSpotToUpdate = new TouristSpot() { Name = "Virgen del verdún", Id = 3 }; TouristSpot newData = new TouristSpot() { Name = "The Green Roofs", }; TouristSpotModelIn touristSpotModelToUpdate = new TouristSpotModelIn(touristSpotToUpdate); TouristSpotModelIn newDataModel = new TouristSpotModelIn(newData); var mock = new Mock <ITouristSpotLogic>(MockBehavior.Strict); mock.Setup(ts => ts.Update(touristSpotModelToUpdate.Id, newData)); mock.Setup(ts => ts.Get(touristSpotToUpdate.Id)).Throws(new ObjectNotFoundInDatabaseException()); var controller = new TouristSpotController(mock.Object); var result = controller.Put(touristSpotModelToUpdate.Id, newDataModel) as NotFoundObjectResult; var expectedResult = new NotFoundObjectResult("There is no tourist spot with such id."); mock.VerifyAll(); Assert.AreEqual(expectedResult.Value, result.Value); }
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 TestGetTouristSpotReturnsValidModel() { var touristSpot = TouristSpotModel.ToEntity(); touristSpot.Region = new Region { Id = touristSpot.RegionId.Value }; var touristSpotCategories = new TouristSpotCategory() { Category = Category, CategoryId = Category.Id, TouristSpot = touristSpot, TouristSpotId = touristSpot.Id }; touristSpot.TouristSpotCategories = new List <TouristSpotCategory>() { touristSpotCategories }; var touristSpots = new List <TouristSpot> { touristSpot }; var touristSpotLogicMock = new Mock <ITouristSpotLogic>(MockBehavior.Strict); touristSpotLogicMock.Setup(m => m.Search(TouristSpotSearchModel)).Returns(touristSpots); var touristSpotController = new TouristSpotController(touristSpotLogicMock.Object); var result = touristSpotController.Get(TouristSpotSearchModel) as OkObjectResult; var content = result.Value as List <TouristSpotBasicInfoModel>; touristSpotLogicMock.VerifyAll(); Assert.IsTrue(content.SequenceEqual(touristSpots.Select(x => new TouristSpotBasicInfoModel(x)))); }
public void TestGetTouristSpotHas200StatusCode() { var touristSpot = TouristSpotModel.ToEntity(); touristSpot.Region = new Region { Id = touristSpot.RegionId.Value }; var touristSpotCategories = new TouristSpotCategory() { Category = Category, CategoryId = Category.Id, TouristSpot = touristSpot, TouristSpotId = touristSpot.Id }; touristSpot.TouristSpotCategories = new List <TouristSpotCategory>() { touristSpotCategories }; var touristSpots = new List <TouristSpot> { touristSpot }; var touristSpotLogicMock = new Mock <ITouristSpotLogic>(MockBehavior.Strict); touristSpotLogicMock.Setup(m => m.Search(TouristSpotSearchModel)).Returns(touristSpots); var touristSpotController = new TouristSpotController(touristSpotLogicMock.Object); var result = touristSpotController.Get(TouristSpotSearchModel) as OkObjectResult; touristSpotLogicMock.VerifyAll(); Assert.AreEqual(result.StatusCode, 200); }
public void TestGetTouristSpotByIdReturnsValidModel() { var touristSpot = TouristSpotModel.ToEntity(); touristSpot.Region = new Region { Id = touristSpot.RegionId.Value }; var touristSpotCategories = new TouristSpotCategory() { Category = Category, CategoryId = Category.Id, TouristSpot = touristSpot, TouristSpotId = touristSpot.Id }; touristSpot.TouristSpotCategories = new List <TouristSpotCategory>() { touristSpotCategories }; TouristSpotLogicMock.Setup(m => m.Get(touristSpot.Id)).Returns(touristSpot); var touristSpotController = new TouristSpotController(TouristSpotLogicMock.Object); var result = touristSpotController.GetById(touristSpot.Id) as OkObjectResult; var content = result.Value as TouristSpotDetailedInfoModel; TouristSpotLogicMock.VerifyAll(); Assert.AreEqual(content, new TouristSpotDetailedInfoModel(touristSpot)); }
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 TestGetTouristSpotIsBadRequestIfRegionIsNull() { TouristSpotSearchModel.Region = null; var touristSpotLogicMock = new Mock <ITouristSpotLogic>(MockBehavior.Strict); var touristSpotController = new TouristSpotController(touristSpotLogicMock.Object); var result = touristSpotController.Get(TouristSpotSearchModel) as BadRequestObjectResult; Assert.AreEqual(result.StatusCode, 400); }
public void GetTouristSpotByIdInternalErrorTest() { var touristSpotMock = new Mock <ITouristSpotManagement>(MockBehavior.Strict); touristSpotMock.Setup(m => m.GetTouristSpotById(It.IsAny <Guid>())).Throws(new ServerBusinessLogicException("No se puede obtener el punto turistico a traves del Id.")); TouristSpotController touristSpotController = new TouristSpotController(touristSpotMock.Object); var result = touristSpotController.Get(touristSpotResponseModel.Id); var createdResult = result as ObjectResult; touristSpotMock.VerifyAll(); Assert.AreEqual(500, createdResult.StatusCode); }
public void GetAllTouristSpotsInternalErrorTest() { var touristSpotMock = new Mock <ITouristSpotManagement>(MockBehavior.Strict); touristSpotMock.Setup(m => m.GetAllTouristSpot()).Throws(new ServerBusinessLogicException("Error. No se pueden obtener todos los puntos turisticos.")); TouristSpotController touristSpotController = new TouristSpotController(touristSpotMock.Object); var result = touristSpotController.Get(); var createdResult = result as ObjectResult; touristSpotMock.VerifyAll(); Assert.AreEqual(500, createdResult.StatusCode); }
public void GetAllTouristSpotsNotFoundTest() { var touristSpotMock = new Mock <ITouristSpotManagement>(MockBehavior.Strict); touristSpotMock.Setup(m => m.GetAllTouristSpot()).Throws(new ClientBusinessLogicException()); TouristSpotController touristSpotController = new TouristSpotController(touristSpotMock.Object); var result = touristSpotController.Get(); var createdResult = result as NotFoundObjectResult; touristSpotMock.VerifyAll(); Assert.AreEqual(404, 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 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 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 TestGetByIdNotFound() { var mock = new Mock <ITouristSpotLogic>(MockBehavior.Strict); mock.Setup(ts => ts.Get(3)).Throws(new ObjectNotFoundInDatabaseException()); var controller = new TouristSpotController(mock.Object); var result = controller.Get(3) as NotFoundObjectResult; var expectedResult = new NotFoundObjectResult("There is no such tourist spot id."); mock.VerifyAll(); Assert.AreEqual(expectedResult.Value, result.Value); }
public void GetTouristSpotByIdTestOk() { var touristSpotMock = new Mock <ITouristSpotManagement>(MockBehavior.Strict); touristSpotMock.Setup(m => m.GetTouristSpotById(It.IsAny <Guid>())).Returns(touristSpotAdded); TouristSpotController touristSpotController = new TouristSpotController(touristSpotMock.Object); var result = touristSpotController.Get(touristSpotResponseModel.Id); var createdResult = result as OkObjectResult; var model = createdResult.Value as TouristSpotForResponseModel; touristSpotMock.VerifyAll(); Assert.AreEqual(touristSpotResponseModel, model); }
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 GetTouristSpotByCategoriesAndRegionIdInternalErrorTest() { var touristSpotMock = new Mock <ITouristSpotManagement>(MockBehavior.Strict); touristSpotMock.Setup(m => m.GetTouristSpotsByCategoriesAndRegion(It.IsAny <List <Guid> >(), It.IsAny <Guid>())) .Throws(new ServerBusinessLogicException("No se puede obtener los puntos turisticos que se estan buscando por dichas categorias y region.")); TouristSpotController touristSpotController = new TouristSpotController(touristSpotMock.Object); Guid[] categories = new Guid[] { category.Id }; var result = touristSpotController.GetTouristSpotsByCategoriesAndRegionId(categories, regionForTouristSpot.Id); var createdResult = result as ObjectResult; touristSpotMock.VerifyAll(); Assert.AreEqual(500, createdResult.StatusCode); }
public void GetTouristSpotByCategoriesAndRegionIdNotFoundTest() { var touristSpotMock = new Mock <ITouristSpotManagement>(MockBehavior.Strict); touristSpotMock.Setup(m => m.GetTouristSpotsByCategoriesAndRegion(It.IsAny <List <Guid> >(), It.IsAny <Guid>())) .Throws(new ClientBusinessLogicException()); TouristSpotController touristSpotController = new TouristSpotController(touristSpotMock.Object); Guid[] categories = new Guid[] { category.Id }; var result = touristSpotController.GetTouristSpotsByCategoriesAndRegionId(categories, regionForTouristSpot.Id); var createdResult = result as NotFoundObjectResult; touristSpotMock.VerifyAll(); Assert.AreEqual(404, createdResult.StatusCode); }
public void GetAllTouristSpotsOkTest() { var touristSpotMock = new Mock <ITouristSpotManagement>(MockBehavior.Strict); touristSpotMock.Setup(m => m.GetAllTouristSpot()).Returns(new List <TouristSpot> () { touristSpotAdded }); TouristSpotController touristSpotController = new TouristSpotController(touristSpotMock.Object); var result = touristSpotController.Get(); var createdResult = result as OkObjectResult; var model = createdResult.Value as List <TouristSpotForResponseModel>; touristSpotMock.VerifyAll(); Assert.AreEqual(model.First(), touristSpotResponseModel); }
public void GetTouristSpotByCategoriesAndRegionIdOkTest() { var touristSpotMock = new Mock <ITouristSpotManagement>(MockBehavior.Strict); touristSpotMock.Setup(m => m.GetTouristSpotsByCategoriesAndRegion(It.IsAny <List <Guid> >(), It.IsAny <Guid>())).Returns(new List <TouristSpot> { touristSpotAdded }); TouristSpotController touristSpotController = new TouristSpotController(touristSpotMock.Object); Guid[] categories = new Guid[] { category.Id }; var result = touristSpotController.GetTouristSpotsByCategoriesAndRegionId(categories, regionForTouristSpot.Id); var createdResult = result as OkObjectResult; var model = createdResult.Value as List <TouristSpotForResponseModel>; touristSpotMock.VerifyAll(); Assert.AreEqual(touristSpotResponseModel, model.First()); }
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 TestDeleteNotFoundObject() { TouristSpot touristSpot = new TouristSpot() { Name = "Virgen del verdún", Id = 3 }; TouristSpotModelIn touristSpotModel = new TouristSpotModelIn(touristSpot); var mock = new Mock <ITouristSpotLogic>(MockBehavior.Strict); mock.Setup(ts => ts.Delete(3)).Throws(new ObjectNotFoundInDatabaseException()); var controller = new TouristSpotController(mock.Object); var result = controller.Delete(touristSpotModel.Id) as NotFoundObjectResult; var expectedResult = new NotFoundObjectResult("There is no tourist spot with such id."); mock.VerifyAll(); Assert.AreEqual(expectedResult.Value, result.Value); }
public void TestSuccessfulDelete() { TouristSpot touristSpot = new TouristSpot() { Name = "Virgen del verdún", Id = 3 }; TouristSpotModelIn touristSpotModel = new TouristSpotModelIn(touristSpot); var mock = new Mock <ITouristSpotLogic>(MockBehavior.Strict); mock.Setup(ts => ts.Delete(3)); var controller = new TouristSpotController(mock.Object); var result = controller.Delete(touristSpotModel.Id) as OkObjectResult; var expectedResult = new OkObjectResult("Success."); mock.VerifyAll(); Assert.AreEqual(expectedResult.Value, result.Value); }
public void TestGetByIdFound() { TouristSpot touristSpotToReturn = new TouristSpot() { Id = 1, Name = "Faro de La Paloma", Description = "Very tall. Traditional.", Image = "image", }; TouristSpotModelOut modelToReturn = new TouristSpotModelOut(touristSpotToReturn); var mock = new Mock <ITouristSpotLogic>(MockBehavior.Strict); mock.Setup(ts => ts.Get(1)).Returns(touristSpotToReturn); var controller = new TouristSpotController(mock.Object); var result = controller.Get(1); var okResult = result as OkObjectResult; var touristSpot = okResult.Value as TouristSpotModelOut; mock.VerifyAll(); Assert.IsTrue(touristSpot.Equals(modelToReturn)); }
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); }