コード例 #1
0
        public void Handle_Fail_ShouldBeBadRequestObjectResult()
        {
            _sut.Handle(new CreateUserCommandResponse
            {
                Success      = false,
                ErrorMessage = "Fail with unknown reason"
            });

            _sut.Result.Should().BeOfType <BadRequestObjectResult>();
        }
コード例 #2
0
        public void Handle_ExistingUserName_ReturnsConflictActionResult()
        {
            // Arrange
            var response = Response <User> .Fail(new[] { "errorMessage" });

            var presenter = new CreateUserPresenter();

            // Act
            presenter.Handle(response);

            // Assert
            var conflictActionResult = presenter.ActionResult as ConflictObjectResult;

            Assert.AreEqual((int)HttpStatusCode.Conflict, conflictActionResult.StatusCode);
            Assert.AreEqual(response.Errors, conflictActionResult.Value);
        }
コード例 #3
0
        public void Handle_UserCreated_ReturnsCreatedActionResultWithTheCreatedUser()
        {
            // Arrange
            var createdUser = new UserBuilder()
                              .WithName(new Name("TestName"))
                              .WithRoles(new Role(new Name("TestRole")))
                              .Build();
            var response = Response <User> .Success(createdUser);

            var presenter = new CreateUserPresenter();

            // Act
            presenter.Handle(response);

            // Assert
            var createdActionResult = presenter.ActionResult as CreatedResult;

            Assert.AreEqual((int)HttpStatusCode.Created, createdActionResult.StatusCode);
            var userModel = createdActionResult.Value as UserModel;

            Assert.AreEqual(createdUser.UserName.Value, userModel.UserName);
            Assert.AreEqual(createdUser.Id, userModel.Id);
            CollectionAssert.AreEquivalent(createdUser.Roles.Select(role => role.Name.Value).ToList(), userModel.Roles.ToList());
        }