public async Task ShouldRegisterWithoutErrorAndWithExistingError() { var command = new RegisterAdminUserCommand { Email = "*****@*****.**", Password = "******", Name = "Test", Surname = "Ex", TimeZone = 0 }; var adminUserModel = await _commandHandler.Handle(command, CancellationToken.None); Assert.Equal(1, adminUserModel.NumberOfTotalItems); var adminUser = adminUserModel.Items.Single(); Assert.NotNull(adminUser.CreatedDateTime); Assert.Equal(adminUser.CreatedDateTime.Value.Date, DateTime.Today); var adminUsers = _context.AdminUsers.ToList(); Assert.NotNull(adminUsers.FirstOrDefault()); Assert.Single(adminUsers); Assert.Equal(command.Email, adminUsers.FirstOrDefault().Email.ToLower(), ignoreCase: true); command.Email = "*****@*****.**"; await _commandHandler.Handle(command, CancellationToken.None); adminUsers = _context.AdminUsers.ToList(); Assert.Equal(2, adminUsers.Count); await Assert.ThrowsAsync <ObjectAlreadyExistsException>(async() => await _commandHandler.Handle(command, CancellationToken.None)); }
public void ShouldBeValid() { var item = new RegisterAdminUserCommand { Email = "*****@*****.**", Password = "******", Name = "John", Surname = "Doe" }; Assert.True(_validator.Validate(item).IsValid); }
public async Task <IActionResult> Register([FromBody] RegisterAdminUserCommand command) { try { var model = await Mediator.Send(command); return(StatusCode((int)HttpStatusCode.Created, model)); } catch (ObjectAlreadyExistsException ex) { return(Conflict(new ResponseModel <RegisterAdminUserModel>(new Error(HttpStatusCode.Conflict, ex)))); } catch (Exception ex) { return(StatusCode(500, new ResponseModel <RegisterAdminUserModel>(new Error(HttpStatusCode.InternalServerError, ex)))); } }
public async Task CanRegisterAdminUser() { // The endpoint or route of the controller action. var command = new RegisterAdminUserCommand { Email = "*****@*****.**", Password = "******", Name = "Test", Surname = "Test", TimeZone = 0 }; var json = JsonConvert.SerializeObject(command); var httpResponse = await _client.PostAsync("/AdminUser/Register", new StringContent(json, Encoding.UTF8, StringConstants.ApplicationJson)); // Must be successful. httpResponse.EnsureSuccessStatusCode(); Assert.True(httpResponse.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Created, httpResponse.StatusCode); }