public void Put()
        {
            // Arrange
            DeviseController controller = new DeviseController();
            Devise           dFalse     = new Devise(7, "test", 2);
            Devise           dUpdated   = new Devise(1, "testYes", 2);

            // Act
            IHttpActionResult result1 = controller.Put(1, dUpdated);
            var result = controller.Put(1, dUpdated);
            IHttpActionResult result2 = controller.Put(2, dFalse);
            IHttpActionResult result3 = controller.Put(7, dFalse);


            // Assert
            Assert.AreEqual(1, dUpdated.Id);
            Assert.AreEqual(dUpdated, controller.Get().ElementAt(0));
            Assert.IsInstanceOfType(result1, typeof(StatusCodeResult));
            Assert.IsInstanceOfType(result2, typeof(BadRequestResult)); // devise.id is not the same as the id parameter
            Assert.IsInstanceOfType(result3, typeof(NotFoundResult));   // Id is not found


            controller.ModelState.AddModelError("Error", "Error");
            var response = controller.Put(7, dFalse);

            Assert.IsInstanceOfType(response, typeof(InvalidModelStateResult));
        }
Beispiel #2
0
        public async Task Put_WellFormedObjectPassed()
        {
            // Act
            double newTaux = 1.09;
            var    result  = await _controller.Put(1, new Devise(1, "Dollar", newTaux)) as NoContentResult;

            var getById = await _controller.GetById(1) as OkObjectResult;

            Devise modifiedDevise = (Devise)getById.Value;

            // Assert
            Assert.IsInstanceOfType(result, typeof(NoContentResult), "Pas un NoContentResult");
            Assert.IsTrue(modifiedDevise.Taux == newTaux);
        }
        public void PutTest()
        {
            DeviseController     dc      = new DeviseController();
            IEnumerable <Devise> devises = dc.Get();

            Devise toEdit = devises.FirstOrDefault();

            Assert.IsNotNull(toEdit);

            toEdit.Nom = "Donatien";


            var result = dc.Put(1, toEdit) as StatusCodeResult;

            Assert.AreEqual(result.StatusCode, HttpStatusCode.OK);
        }