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 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 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 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 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 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 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 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 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)); }