Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 public IActionResult Put(int id, [FromBody] TouristSpotModelIn dataToUpdate)
 {
     try
     {
         var touristSpot = dataToUpdate.ToEntity();
         this.touristSpotLogic.Update(id, touristSpot);
         var touristSpotToReturn = this.touristSpotLogic.Get(id);
         return(Ok(new TouristSpotModelOut(touristSpotToReturn)));
     }
     catch (Exception ex)
     {
         return(NotFound("There is no tourist spot with such id."));
     }
 }
Exemplo n.º 4
0
 //[ServiceFilter(typeof(AuthorizationAttributeFilter))]
 public IActionResult Post([FromBody] TouristSpotModelIn touristSpotModel)
 {
     try
     {
         var touristSpot = touristSpotModel.ToEntity();
         this.touristSpotLogic.Add(touristSpot);
         return(CreatedAtRoute(routeName: "GetTouristSpot",
                               routeValues: new { id = touristSpotModel.Id },
                               value: new TouristSpotModelIn(touristSpot)));
     }
     catch (Exception ex)
     {
         return(BadRequest("A tourist spot with such name has been already registered."));
     }
 }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }