public async Task UserIsLogicallyDeleted_UpdatesHost()
        {
            await this.Context.Guests.AddAsync(new Domain.Entities.Guest()
            {
                IsDeleted = true,
                User      = new Domain.Entities.User()
                {
                    IsDeleted = true,
                    Username  = "******",
                    Password  = "******"
                }
            }).ConfigureAwait(false);

            await this.Context.SaveChangesAsync().ConfigureAwait(false);

            var request = new CreateGuestCommand()
            {
                Username  = "******",
                Password  = "******",
                FirstName = "Milos"
            };

            await this.sut.Handle(request, CancellationToken.None).ConfigureAwait(false);

            var guest = await this.Context.Guests.Include(g => g.User)
                        .SingleOrDefaultAsync(g => g.User.Username == request.Username, CancellationToken.None)
                        .ConfigureAwait(false);

            Assert.NotNull(guest);
            CustomAssertAreEqual(request, guest);
        }
コード例 #2
0
        public async Task Register_UserIsUnauthenticated_CreatesGuestUsingMediatorAndReturnsCreatedGuest()
        {
            var expectedGuestDto = new GuestDto()
            {
                Id = 5, Username = "******", Password = "******"
            };

            this.mediatorMock.Setup(m => m.Send(It.IsAny <CreateGuestCommand>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(expectedGuestDto);

            var controller = this.GetUnauthenticatedController();

            var command = new CreateGuestCommand()
            {
                Username = "******",
                Password = "******"
            };

            var result = await controller.Register(command).ConfigureAwait(false);

            var okObjectResult = Assert.IsAssignableFrom <OkObjectResult>(result);
            var user           = Assert.IsAssignableFrom <UserDto>(okObjectResult.Value);

            Assert.Equal(expectedGuestDto.Id, user.Id);

            this.mediatorMock.Verify(m => m.Send(command, CancellationToken.None), Times.Once);
        }
コード例 #3
0
        public async Task <IActionResult> Register([FromBody] CreateGuestCommand command)
        {
            if (this.User.Identity.IsAuthenticated)
            {
                await this.authService.LogoutAsync(this.HttpContext).ConfigureAwait(false);
            }

            return(this.Ok(await this.mediator.Send(command).ConfigureAwait(false)));
        }
コード例 #4
0
        public async Task <IActionResult> Register([FromBody] CreateGuestCommand command)
        {
            if (this.User.Identity.IsAuthenticated)
            {
                throw new AlreadyLoggedInException();
            }

            return(this.Ok(await this.mediator.Send(command).ConfigureAwait(false)));
        }
コード例 #5
0
        public void IsValid_ShouldBeFalse_WhenRequiredFieldsAreNotSet()
        {
            var command = new CreateGuestCommand();

            var validator = new CreateGuestCommandValidator(Context);

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(false);
        }
 private static void CustomAssertAreEqual(CreateGuestCommand request, Domain.Entities.Guest host)
 {
     Assert.Equal(request.Username, host.User.Username);
     Assert.Equal(request.Password, host.User.Password);
     Assert.Equal(request.FirstName, host.User.FirstName);
     Assert.Equal(request.LastName, host.User.LastName);
     Assert.Equal(request.Gender, host.User.Gender);
     Assert.Equal(RoleNames.Guest, host.User.RoleName);
     Assert.False(host.User.IsDeleted);
     Assert.False(host.IsDeleted);
 }
コード例 #7
0
        public void IsValid_ShouldBeTrue_WhenRequiredFieldsAreSet()
        {
            var command = new CreateGuestCommand
            {
                FirstName = "Test FirstName",
                LastName  = "Test LastName",
                Email     = "Test Email"
            };

            var validator = new CreateGuestCommandValidator(Context);

            var result = validator.Validate(command);

            result.IsValid.ShouldBe(true);
        }
コード例 #8
0
        public async Task Register_UserIsAuthenticated_ThrowAlreadyLoggedInException()
        {
            var controller = this.GetAuthenticatedController();

            var command = new CreateGuestCommand()
            {
                Username = "******",
                Password = "******"
            };

            await Assert
            .ThrowsAsync <AlreadyLoggedInException>(async() => await controller.Register(command).ConfigureAwait(false))
            .ConfigureAwait(false);

            this.mediatorMock.Verify(m => m.Send(command, CancellationToken.None), Times.Never);
        }
コード例 #9
0
ファイル: Create.cs プロジェクト: dkm8923/WeddingAppCore
        public async Task GivenValidCreateGuestCommand_ReturnsSuccessCode()
        {
            var client = await _factory.GetAuthenticatedClientAsync();

            var command = new CreateGuestCommand
            {
                FirstName = "Test FirstName",
                LastName  = "Test LastName",
                Email     = "Test Email"
            };

            var content = IntegrationTestHelper.GetRequestContent(command);

            var response = await client.PostAsync($"/api/Guest", content);

            response.EnsureSuccessStatusCode();
        }
        public async Task UserDoesNotExist_CreatesGuest()
        {
            // Arrange
            var request = new CreateGuestCommand()
            {
                Username = "******",
                Password = "******"
            };

            // Act
            await this.sut.Handle(request, CancellationToken.None).ConfigureAwait(false);

            // Assert
            var guest = await this.Context.Guests.Include(g => g.User)
                        .SingleOrDefaultAsync(g => g.User.Username == request.Username, CancellationToken.None)
                        .ConfigureAwait(false);

            Assert.NotNull(guest);
            CustomAssertAreEqual(request, guest);
        }
コード例 #11
0
        public async Task Handle_ShouldPersistGuest()
        {
            var command = new CreateGuestCommand
            {
                FirstName = "Test FirstName",
                LastName  = "Test LastName",
                Email     = "Test Email"
            };

            var handler = new CreateGuestCommand.CreateGuestCommandHandler(Context);

            var result = await handler.Handle(command, CancellationToken.None);

            var entity = Context.Guests.Find(result);

            entity.ShouldNotBeNull();
            entity.FirstName.ShouldBe(command.FirstName);
            entity.LastName.ShouldBe(command.LastName);
            entity.Email.ShouldBe(command.Email);
        }
コード例 #12
0
 public async Task <ActionResult <long> > Create(CreateGuestCommand command)
 {
     return(await Mediator.Send(command));
 }
コード例 #13
0
        public async Task <IActionResult> Post([FromBody] CreateGuestCommand command)
        {
            await this.mediator.Send(command).ConfigureAwait(false);

            return(this.NoContent());
        }