public async void CanCreateTrainerUser()
        {
            var client = SystemTestExtension.GetTokenAuthorizeHttpClient(_factory);

            var command = new CreateTrainerUserCommand
            {
                Name         = "Emre",
                Surname      = "KAS",
                PhoneNumber  = "12412312312",
                Password     = "******",
                DepartmentId = 1,
                CreatedBy    = 1,
                ProfessionId = 1,
                Email        = "*****@*****.**"
            };

            var json = JsonConvert.SerializeObject(command);

            var httpResponse = await client.PostAsync("/TrainerUser", new StringContent(json, Encoding.UTF8, StringConstants.ApplicationJson));

            // Must be successful.
            httpResponse.EnsureSuccessStatusCode();

            Assert.True(httpResponse.IsSuccessStatusCode);
            Assert.Equal(HttpStatusCode.Created, httpResponse.StatusCode);
        }
Example #2
0
        public async Task ShouldThrowErrorWhenInvalidInformation()
        {
            var createTrainerUserCommand = new CreateTrainerUserCommand()
            {
                DepartmentId = _departmentId + 1,
                CreatedBy    = _adminUserId,
                Name         = "testTrainerUser",
                Password     = "******",
                Surname      = "qwdqwdqwd",
                PhoneNumber  = "123123123123",
                ProfessionId = _professionId
            };

            await Assert.ThrowsAsync <NotFoundException>(async() =>
                                                         await _commandHandler.Handle(createTrainerUserCommand, CancellationToken.None));
        }
Example #3
0
        public async Task ShouldGetModelForValidInformation()
        {
            var createTrainerUserCommand = new CreateTrainerUserCommand()
            {
                DepartmentId = _departmentId,
                CreatedBy    = _adminUserId,
                Name         = "testTrainerUser",
                Surname      = "qwdqwdqwd",
                Password     = "******",
                PhoneNumber  = "123123123123",
                ProfessionId = _professionId,
                Email        = "*****@*****.**",
                TenantId     = _tenantId
            };

            var trainerUserModel = await _commandHandler.Handle(createTrainerUserCommand, CancellationToken.None);

            Assert.Null(trainerUserModel.Errors);
            Assert.Equal(expected: createTrainerUserCommand.Name, actual: trainerUserModel.Items.Single().Name, ignoreCase: true);
        }
Example #4
0
        public async Task <ActionResult <ResponseModel <CreateTrainerUserModel> > > Post([FromBody] CreateTrainerUserCommand command)
        {
            try
            {
                var userId = Claims[ClaimTypes.Sid].ToInt();
                command.CreatedBy = userId;
                command.TenantId  = Guid.Parse(Claims[ClaimTypes.UserData]);

                var model = await Mediator.Send(command);

                return(Created($"api/TrainerUser/{model.Items.Single().Name}", model));
            }
            catch (ObjectAlreadyExistsException ex)
            {
                return(Conflict(new ResponseModel <CreateTrainerUserModel>(new Error(HttpStatusCode.Conflict, ex))));
            }
            catch
            {
                return(StatusCode(HttpStatusCode.InternalServerError.ToInt()));
            }
        }