예제 #1
0
        public void ANoteIsCreated()
        {
            int createdNoteId = 0;
            UnProcessableEntityException couldNotCreateNoteException = null;

            try
            {
                var userId  = _fixture.LandmarkContext.Users.First().Id;
                var command = new CreateNoteCommand
                {
                    UserId    = userId,
                    Text      = "a sample note",
                    Latitude  = 50,
                    Longitude = 50
                };
                createdNoteId = new CreateNoteCommandHandler(_fixture.LandmarkContext, new FakeDatetimeProvider()).Handle(command, CancellationToken.None).GetAwaiter().GetResult();
            }
            catch (UnProcessableEntityException ex)
            {
                couldNotCreateNoteException = ex;
            }


            couldNotCreateNoteException.ShouldBeNull();
            createdNoteId.ShouldBeGreaterThan(0);
        }
예제 #2
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")
                );
        }