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

            var command = new UpdateTrainerUserCommand
            {
                Id           = 1,
                Name         = "Yunus Emre",
                Surname      = "KAS",
                PhoneNumber  = "5555555555",
                Password     = "******",
                DepartmentId = 1,
                UpdatedBy    = 1,
                ProfessionId = 1,
                Email        = "*****@*****.**"
            };

            var json = JsonConvert.SerializeObject(command);

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

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

            Assert.True(httpResponse.IsSuccessStatusCode);
            Assert.Equal(HttpStatusCode.OK, httpResponse.StatusCode);
        }
예제 #2
0
        public async Task ShouldThrowErrorWhenInvalidInformation()
        {
            var updateTrainerUserCommand = new UpdateTrainerUserCommand()
            {
                Id           = _trainerUserId + 1,
                DepartmentId = _departmentId,
                UpdatedBy    = _adminUserId,
                Name         = "testTrainerUser",
                Password     = "******",
                Surname      = "qwdqwdqwd",
                PhoneNumber  = "123123123123",
                ProfessionId = _professionId,
                TenantId     = _tenantId
            };

            await Assert.ThrowsAsync <NotFoundException>(async() =>
                                                         await _commandHandler.Handle(updateTrainerUserCommand, CancellationToken.None));
        }
예제 #3
0
        public async Task ShouldGetModelForValidInformation()
        {
            var updateTrainerUserCommand = new UpdateTrainerUserCommand()
            {
                Id           = _trainerUserId,
                DepartmentId = _departmentId,
                UpdatedBy    = _adminUserId,
                Name         = "testTraineasdasdr",
                Surname      = "qwdqwdqasdwd",
                Password     = "******",
                PhoneNumber  = "123123123123",
                ProfessionId = _professionId,
                Email        = "*****@*****.**",
                TenantId     = _tenantId
            };

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

            Assert.Null(trainerUserModel.Errors);
            Assert.Equal(expected: updateTrainerUserCommand.Name, actual: trainerUserModel.Items.Single().Name, ignoreCase: true);
        }
예제 #4
0
        public async Task <ActionResult <ResponseModel <UpdateTrainerUserModel> > > Put([FromBody] UpdateTrainerUserCommand command)
        {
            try
            {
                var userId = Claims[ClaimTypes.Sid].ToInt();
                command.UpdatedBy = userId;
                command.TenantId  = Guid.Parse(Claims[ClaimTypes.UserData]);

                var model = await Mediator.Send(command);

                return(Ok(model));
            }
            catch (NotFoundException)
            {
                return(NotFound());
            }
            catch (ObjectAlreadyExistsException ex)
            {
                return(Conflict(new ResponseModel <UpdateTrainerUserModel>(new Error(HttpStatusCode.Conflict, ex))));
            }
            catch
            {
                return(StatusCode(HttpStatusCode.InternalServerError.ToInt()));
            }
        }