public async void CanCreateTraineeUser() { var client = SystemTestExtension.GetTokenAuthorizeHttpClient(_factory); // The endpoint or route of the controller action. var command = new CreateTraineeUserCommand { Name = "tenant1", DepartmentId = 1, Gender = 1, CreatedBy = 1, Password = "******", Email = "*****@*****.**", PhoneNumber = "65468465466", Surname = "tenant-surname", NationalIdentityNumber = "879684684654", WorkingStatusId = 1 }; var json = JsonConvert.SerializeObject(command); var httpResponse = await client.PostAsync("/TraineeUser", new StringContent(json, Encoding.UTF8, StringConstants.ApplicationJson)); // Must be successful. httpResponse.EnsureSuccessStatusCode(); Assert.True(httpResponse.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Created, httpResponse.StatusCode); }
public async Task ShouldThrowErrorWhenInvalidInformation() { var createTraineeUserCommand = new CreateTraineeUserCommand() { DepartmentId = _departmentId + 1, CreatedBy = _adminUserId, Name = "testTraineeUser", Gender = 1, Password = "******", Email = "*****@*****.**", NationalIdentityNumber = "1231231231231", Surname = "qwdqwdqwd", PhoneNumber = "123123123123", WorkingStatusId = _workingStatusId }; await Assert.ThrowsAsync <NotFoundException>(async() => await _commandHandler.Handle(createTraineeUserCommand, CancellationToken.None)); }
public async Task ShouldGetModelForValidInformation() { var createTraineeUserCommand = new CreateTraineeUserCommand { DepartmentId = _departmentId, CreatedBy = _adminUserId, Name = "testTraineeUser", Gender = 1, Password = "******", Email = "*****@*****.**", NationalIdentityNumber = "1231231231231", Surname = "qwdqwdqwd", PhoneNumber = "123123123123", WorkingStatusId = _workingStatusId, TenantId = _tenantId }; var traineeUserModel = await _commandHandler.Handle(createTraineeUserCommand, CancellationToken.None); Assert.Null(traineeUserModel.Errors); Assert.Equal(expected: createTraineeUserCommand.Name, actual: traineeUserModel.Items.Single().Name, ignoreCase: true); }
public async Task <ActionResult <ResponseModel <CreateTraineeUserModel> > > Post([FromBody] CreateTraineeUserCommand command) { try { command.CreatedBy = Claims[ClaimTypes.Sid].ToInt(); command.TenantId = Guid.Parse(Claims[ClaimTypes.UserData]); var createTraineeUserModel = await Mediator.Send(command); return(Created($"api/traineeUser/{createTraineeUserModel.Items.Single().Name}", createTraineeUserModel)); } catch (ObjectAlreadyExistsException ex) { return(Conflict(new ResponseModel <CreateTraineeUserModel>(new Error(HttpStatusCode.Conflict, ex)))); } catch { return(StatusCode(HttpStatusCode.InternalServerError.ToInt())); } }