public async Task UserIsLogicallyDeleted_UpdatesHost() { await this.Context.Hosts.AddAsync(new Domain.Entities.Host() { IsDeleted = true, User = new Domain.Entities.User() { IsDeleted = true, Username = "******", Password = "******" } }).ConfigureAwait(false); await this.Context.SaveChangesAsync().ConfigureAwait(false); var request = new CreateHostCommand() { Username = "******", Password = "******", FirstName = "Milos", RoleName = RoleNames.Host }; await this.sut.Handle(request, CancellationToken.None).ConfigureAwait(false); var host = await this.Context.Hosts.Include(h => h.User) .SingleOrDefaultAsync(h => h.User.Username == request.Username, CancellationToken.None) .ConfigureAwait(false); Assert.NotNull(host); CustomAssertAreEqual(request, host); }
private static void CustomAssertAreEqual(CreateHostCommand request, Domain.Entities.Host 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.Host, host.User.RoleName); Assert.False(host.User.IsDeleted); Assert.False(host.IsDeleted); }
public async Task Post_WhenInvoked_SendCreateCommandToMediator() { var controller = this.CreateController(this.userId, RoleNames.Administrator); var createCommand = new CreateHostCommand() { Username = "******", Password = "******" }; await controller.Post(createCommand); this.mediatorMock.Verify(m => m.Send(It.Is <CreateHostCommand>(c => c == createCommand), It.IsAny <CancellationToken>()), Times.Once); }
public async Task UserDoesNotExist_CreatesHost() { // Arrange var request = new CreateHostCommand() { Username = "******", Password = "******", RoleName = RoleNames.Host }; // Act await this.sut.Handle(request, CancellationToken.None).ConfigureAwait(false); // Assert var host = await this.Context.Hosts.Include(h => h.User) .SingleOrDefaultAsync(h => h.User.Username == request.Username, CancellationToken.None) .ConfigureAwait(false); Assert.NotNull(host); CustomAssertAreEqual(request, host); }
public Task Create(CreateHostCommand createHostCommand) { FirsName = createHostCommand.FirstName; LastName = createHostCommand.LastName; return(Task.CompletedTask); }
public async Task <IActionResult> Post([FromBody] CreateHostCommand command) { await this.mediator.Send(command).ConfigureAwait(false); return(this.NoContent()); }
public async Task <bool> PostAsync([FromBody] CreateHostCommand command) { return(await _mediator.Send(command)); }