Example #1
0
        public void ShouldReturnBadRequest()
        {
            // Arrange
            var    failure             = new ValidationFailure("code", "message");
            var    commandResult       = new CommandResult(failure);
            string resourceForLocation = "users";

            // Act
            var response = commandResult.Accepted(resourceForLocation);

            // Assert
            Assert.IsType <BadRequestObjectResult>(response);
        }
Example #2
0
        public void ShouldReturnInternalServerError()
        {
            // Arrange
            var    failure             = new Failure("code", "message");
            var    commandResult       = new CommandResult(failure);
            string resourceForLocation = "users";

            // Act
            var response = commandResult.Accepted(resourceForLocation);

            // Assert
            Assert.IsType <ObjectResult>(response);
            Assert.Equal(StatusCodes.Status500InternalServerError, ((ObjectResult)response).StatusCode);
        }
Example #3
0
        public void ShouldSuccessWithResourceLocation()
        {
            // Arrange
            string resource         = "users";
            var    guid             = Guid.NewGuid();
            var    commandResult    = new CommandResult(guid);
            string expectedLocation = $"{resource}/{guid}";

            // Act
            var response = commandResult.Accepted(resourceForLocation: resource);

            // Assert
            Assert.IsType <AcceptedResult>(response);
            var result = response as AcceptedResult;

            Assert.Equal(StatusCodes.Status202Accepted, result.StatusCode);
            Assert.Equal(expectedLocation, result.Location);
            Assert.Null(result.Value);
        }
Example #4
0
        public void ShouldThrowArgumentNullExceptionForNullResourceLocation()
        {
            // Arrange
            bool   exceptionThrown     = false;
            string paramName           = "resourceForLocation";
            string resourceForLocation = null;
            var    commandResult       = new CommandResult(Guid.NewGuid());

            // Act
            try
            {
                commandResult.Accepted(resourceForLocation: resourceForLocation);
            }
            catch (ArgumentNullException ex)
            {
                exceptionThrown = true;
                Assert.Equal(paramName, ex.ParamName);
            }

            // Assert
            Assert.True(exceptionThrown);
        }