Exemplo n.º 1
0
        public void UserIsCreatedWithCorrectInformation()
        {
            UserDetailModel createdUser = null;
            UnProcessableEntityException couldNotCreateUserException  = null;
            EntityNotFoundException      createdUserNotFoundException = null;

            var command = new CreateUserCommand
            {
                FirstName = "Marco",
                LastName  = "Polo",
                Password  = "******",
                Username  = "******"
            };

            try
            {
                var createdUserId = new CreateUserCommandHandler(_fixture.LandmarkContext, new FakeDatetimeProvider()).Handle(command, CancellationToken.None).GetAwaiter().GetResult();
                createdUser = new GetUserByIdQueryHandler(_fixture.LandmarkContext).Handle(new GetUserByIdQuery {
                    Id = createdUserId
                }, CancellationToken.None).GetAwaiter()
                              .GetResult();
            }
            catch (UnProcessableEntityException ex)
            {
                couldNotCreateUserException = ex;
            }
            catch (EntityNotFoundException ex)
            {
                createdUserNotFoundException = ex;
            }

            couldNotCreateUserException.ShouldBeNull();
            createdUserNotFoundException.ShouldBeNull();
            createdUser.ShouldSatisfyAllConditions(
                () => createdUser.FirstName.ShouldBe("Marco"),
                () => createdUser.LastName.ShouldBe("Polo"),
                () => createdUser.UserName.ShouldBe("marco.polo")
                );
        }