Ejemplo n.º 1
0
        public void PostMethodSetsLocationHeader()
        {
            // Arrange
            var newDesc    = "Description";
            var controller = new ContactNumbersController(MockContactNumberService.Object);

            // Act
            IHttpActionResult actionResult = controller.Post(new ContactNumber {
                Description = newDesc
            });
            var createdResult = actionResult as CreatedODataResult <ContactNumber>;

            // Assert
            Assert.IsNotNull(createdResult);
            Assert.IsNotNull(createdResult.Entity.Id);
            Assert.AreEqual(createdResult.Entity.Description, newDesc);
        }
Ejemplo n.º 2
0
        public void PostMethodReturnsBadRequestWhenModelIsInvalid()
        {
            // Arrange
            var newGuid    = new Guid("0998d643-4c5e-4b1f-9778-e0f6974eaf1d");
            var newDesc    = "Description";
            var controller = new ContactNumbersController(MockContactNumberService.Object);

            controller.ModelState.AddModelError("test", "test");

            // Act
            IHttpActionResult actionResult = controller.Post(new ContactNumber {
                Id = newGuid, Description = newDesc
            });
            var createdResult = actionResult as InvalidModelStateResult;

            // Assert
            Assert.IsNotNull(createdResult);
        }