Ejemplo n.º 1
0
        public async void CanUpdateTraineeUser()
        {
            var client = SystemTestExtension.GetTokenAuthorizeHttpClient(_factory);

            //Init model
            var command = new UpdateTraineeUserCommand
            {
                Id                     = 1,
                Name                   = "tenant1",
                DepartmentId           = 1,
                Gender                 = 1,
                PhoneNumber            = "65468465466",
                Password               = "******",
                Email                  = "*****@*****.**",
                Surname                = "tenant-surname",
                NationalIdentityNumber = "879684684654",
                WorkingStatusId        = 1
            };

            var json = JsonConvert.SerializeObject(command);

            // The endpoint or route of the controller action.
            var httpResponse = await client.PutAsync("/TraineeUser", new StringContent(json, Encoding.UTF8, StringConstants.ApplicationJson));

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

            Assert.True(httpResponse.IsSuccessStatusCode);
            Assert.Equal(HttpStatusCode.OK, httpResponse.StatusCode);
        }
        public async Task ShouldThrowErrorWhenInvalidInformation()
        {
            var updateTraineeUserCommand = new UpdateTraineeUserCommand()
            {
                Id                     = _traineeUserId + 1,
                DepartmentId           = _departmentId,
                UpdatedBy              = _adminUserId,
                Name                   = "testTraineeUser",
                Gender                 = 1,
                NationalIdentityNumber = "1231231231231",
                Surname                = "qwdqwdqwd",
                PhoneNumber            = "123123123123",
                WorkingStatusId        = _workingStatusId
            };

            await Assert.ThrowsAsync <NotFoundException>(async() =>
                                                         await _commandHandler.Handle(updateTraineeUserCommand, CancellationToken.None));
        }
        public async Task ShouldGetModelForValidInformation()
        {
            var updateTraineeUserCommand = new UpdateTraineeUserCommand
            {
                Id                     = _traineeUserId,
                DepartmentId           = _departmentId,
                UpdatedBy              = _adminUserId,
                Name                   = "testTraineeUser",
                Gender                 = 1,
                Password               = "******",
                Email                  = "*****@*****.**",
                NationalIdentityNumber = "1231231231231",
                Surname                = "qwdqwdqwd",
                PhoneNumber            = "123123123123",
                WorkingStatusId        = _workingStatusId,
                TenantId               = _tenantId
            };

            var traineeUserModel = await _commandHandler.Handle(updateTraineeUserCommand, CancellationToken.None);

            Assert.Null(traineeUserModel.Errors);
            Assert.Equal(expected: updateTraineeUserCommand.Name, actual: traineeUserModel.Items.Single().Name, ignoreCase: true);
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <ResponseModel <UpdateTraineeUserModel> > > Put([FromBody] UpdateTraineeUserCommand command)
        {
            try
            {
                command.Id       = Claims[ClaimTypes.Sid].ToInt();
                command.TenantId = Guid.Parse(Claims[ClaimTypes.UserData]);

                var updateTraineeUserModel = await Mediator.Send(command);

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