public async Task Create_ReturnsUser()
        {
            // Prepare
            var createUserCommand = new CreateUserCommand
            {
                Username = "******",
                Email    = "*****@*****.**"
            };

            // Execute
            var responseCreate = await _client.PostAsJsonAsync(Endpoints.USERS, createUserCommand);

            var contentCreate = await responseCreate.Content.ReadAsStringAsync();

            // Check
            var expectedBasicUser = new BasicUserViewModel
            {
                Username = createUserCommand.Username,
                Email    = createUserCommand.Email,
                IsActive = true
            };

            Assert.Equal(HttpStatusCode.Created, responseCreate.StatusCode);
            Assert.Equal(expectedBasicUser.Serialize(), contentCreate);
        }
Example #2
0
        public async Task <IActionResult> Create(BasicUserViewModel user)
        {
            var userDto = _mapper.Map <BasicUserDTO>(user);
            await _service.CreateUser(userDto);

            return(Ok());
        }
Example #3
0
        public async Task <IActionResult> UpdateUser(int id, [FromBody] BasicUserViewModel userInfo)
        {
            var userIdIsValid = await _service.CheckUserById(id);

            if (!userIdIsValid)
            {
                return(BadRequest("Provided Id is invalid"));
            }
            var userDto = _mapper.Map <BasicUserDTO>(userInfo);
            await _service.UpdateUserBasicInfo(id, userDto);

            return(Ok());
        }
Example #4
0
        public WxCaseDetailViewModel _getCaseDetailById(int id)
        {
            BasicUserViewModel respondent = new BasicUserViewModel();
            M_Case             caseinfo   = dbcase.LoadEntities(t => t.ID == id).FirstOrDefault();
            var parts = dbpart.LoadEntities(t => t.CaseId == id);

            if (caseinfo.RespondentId != null)
            {
                respondent = dbuser.GetBasicUserById(caseinfo.RespondentId);
            }
            else
            {
                respondent = new BasicUserViewModel()
                {
                    nickname = caseinfo.Respondent,
                }
            };
            var owner = dbuser.GetBasicUserById(caseinfo.PublisherId);

            return(new WxCaseDetailViewModel()
            {
                user = owner,
                basic = new BasicCaseViewModel()
                {
                    description = caseinfo.StatementOfCase,
                    id = caseinfo.ID,
                    numberOfComment = dbcomment.LoadEntities(t => t.CaseId == id),
                    title = caseinfo.Title,
                    start_at = caseinfo.DateOfBegin.ToShortDateString(),
                    state = caseinfo.StateOfCase,
                    numberOfJoin = dbpart.LoadEntities(t => t.CaseId == id),
                    numberOfFollow = dbfollow.LoadEntities(t => t.caseid == id),
                    otherPay1 = caseinfo.OtherPay1,
                    otherPay2 = caseinfo.OtherPay2,
                    otherPay3 = caseinfo.OtherPay3,
                },
                imageSrc = caseinfo.Photo,
                involves = PartInfo.Current.GetPartsByCaseId(id),
                respondent = respondent,
                respondentturnone = caseinfo.TrunOneComplainByRespondent ?? "",
                respondentturntwo = caseinfo.TrunTwoComplainByRespondent ?? "",
                userturnone = caseinfo.TrunOneComplainByComplainant ?? "",
                userturntwo = caseinfo.TrunTwoComplainByComplainant ?? "",
                condition = caseinfo.Condition,
                orginalpay = caseinfo.originalpay,
            });
        }
    }
        public async Task Create_UserAndThenQuerying_ReturnsUser()
        {
            // Prepare
            var createUserCommand = new CreateUserCommand
            {
                Username = "******",
                Email    = "*****@*****.**"
            };

            // Execute
            var responseCreate = await _client.PostAsJsonAsync(Endpoints.USERS, createUserCommand);

            var contentCreate = await responseCreate.Content.ReadAsStringAsync();

            var responseGetByUsername = await _client.GetAsync(
                $"{Endpoints.USERS}/{createUserCommand.Username}");

            var resultUser = JsonConvert.DeserializeObject <User>(await responseGetByUsername.Content.ReadAsStringAsync());

            // Check
            // Creation
            var expectedBasicUser = new BasicUserViewModel
            {
                Username = createUserCommand.Username,
                Email    = createUserCommand.Email,
                IsActive = true
            };

            Assert.Equal(HttpStatusCode.Created, responseCreate.StatusCode);
            Assert.Equal(expectedBasicUser.Serialize(), contentCreate);

            // GetByUsername
            Assert.Equal(HttpStatusCode.OK, responseGetByUsername.StatusCode);
            Assert.Equal(createUserCommand.Username, resultUser.Username);
            Assert.Equal(createUserCommand.Email, resultUser.Email);
            Assert.True(resultUser.IsActive);
            Assert.NotNull(resultUser.CreatedAt);
            Assert.NotNull(resultUser.UpdatedAt);
        }