Esempio n. 1
0
        public void DeleteWorkType_OK_正常値で削除()
        {
            var requestObject = new WorkTypeCreateRequest
            {
                WorkTypeCode = new String('T', 20),
                WorkTypeTree = new String('1', 8),
                Name         = new String('X', 256),
                Description  = new String('X', 1024),
                Status       = WorkTypeStatus.NORMAL.ToString(),
                SortNo       = int.MaxValue,
                Tags         = new List <string> {
                    new String('X', 100)
                },
            };

            var request = new HttpRequestMessage(HttpMethod.Post, "/api/v1/workTypes");

            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "normal-write");
            request.Content = new StringContent(JsonUtil.Serialize(requestObject), Encoding.UTF8, "application/json");
            var response     = _httpclient.SendAsync(request).ConfigureAwait(false).GetAwaiter().GetResult();
            var responseBody = response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult();
            var workType     = JsonUtil.Deserialize <WorkType>(responseBody);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            request = new HttpRequestMessage(HttpMethod.Delete, $"/api/v1/workTypes/{workType.WorkTypeId}");
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "normal-write");
            response = _httpclient.SendAsync(request).ConfigureAwait(false).GetAwaiter().GetResult();

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
Esempio n. 2
0
        public void CreateWorkType_ValidationError_すべての値が異常値()
        {
            var requestObject = new WorkTypeCreateRequest
            {
                WorkTypeCode = new String('Z', 21),
                WorkTypeTree = new String('Z', 9),
                Name         = new String('Z', 257),
                Description  = new String('Z', 1025),
                Status       = "ERROR",
                SortNo       = -1,
                Tags         = new List <string> {
                    new String('Z', 101)
                },
            };

            var request = new HttpRequestMessage(HttpMethod.Post, "/api/v1/workTypes");

            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "normal-write");
            request.Content = new StringContent(JsonUtil.Serialize(requestObject), Encoding.UTF8, "application/json");
            var response     = _httpclient.SendAsync(request).ConfigureAwait(false).GetAwaiter().GetResult();
            var responseBody = response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult();
            var error        = JsonUtil.Deserialize <Error>(responseBody);

            Assert.AreEqual(ErrorCodes.ValidationError, error.Code);
            Assert.IsTrue(error.Details.Exists(e => e.Target.Equals("WorkTypeCode", StringComparison.OrdinalIgnoreCase)));
            Assert.IsTrue(error.Details.Exists(e => e.Target.Equals("WorkTypeTree", StringComparison.OrdinalIgnoreCase)));
            Assert.IsTrue(error.Details.Exists(e => e.Target.Equals("Name", StringComparison.OrdinalIgnoreCase)));
            Assert.IsTrue(error.Details.Exists(e => e.Target.Equals("Description", StringComparison.OrdinalIgnoreCase)));
            Assert.IsTrue(error.Details.Exists(e => e.Target.Equals("Status", StringComparison.OrdinalIgnoreCase)));
            Assert.IsTrue(error.Details.Exists(e => e.Target.Equals("SortNo", StringComparison.OrdinalIgnoreCase)));
            Assert.IsTrue(error.Details.Exists(e => e.Target.Equals("Tags", StringComparison.OrdinalIgnoreCase)));
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Esempio n. 3
0
        public void UpdateWorkType_ValidationError_WorkTypeTreeを重複する値で更新()
        {
            var requestObject = new WorkTypeCreateRequest
            {
                WorkTypeCode = new String('S', 20),
                WorkTypeTree = new String('4', 8),
                Name         = new String('S', 256),
                Description  = new String('S', 1024),
                Status       = WorkTypeStatus.NORMAL.ToString(),
                SortNo       = int.MaxValue,
                Tags         = new List <string> {
                    new String('S', 100)
                },
            };

            var request = new HttpRequestMessage(HttpMethod.Post, "/api/v1/workTypes");

            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "normal-write");
            request.Content = new StringContent(JsonUtil.Serialize(requestObject), Encoding.UTF8, "application/json");
            var response     = _httpclient.SendAsync(request).ConfigureAwait(false).GetAwaiter().GetResult();
            var responseBody = response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult();
            var workType     = JsonUtil.Deserialize <WorkType>(responseBody);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            var updateRequestObject = new WorkTypeUpdateRequest
            {
                WorkTypeTree = "01",
            };

            request = new HttpRequestMessage(HttpMethod.Patch, $"/api/v1/workTypes/{workType.WorkTypeId}");
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "normal-write");
            request.Content = new StringContent(JsonUtil.Serialize(updateRequestObject), Encoding.UTF8, "application/json");
            response        = _httpclient.SendAsync(request).ConfigureAwait(false).GetAwaiter().GetResult();
            responseBody    = response.Content.ReadAsStringAsync().ConfigureAwait(false).GetAwaiter().GetResult();
            var error = JsonUtil.Deserialize <Error>(responseBody);

            Assert.AreEqual(ErrorCodes.ValidationError, error.Code);
            Assert.IsTrue(error.Details.Exists(e => e.Target.Equals("WorkTypeTree", StringComparison.OrdinalIgnoreCase)));
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public ActionResult <WorkType> CreateWorkType([FromBody] WorkTypeCreateRequest request)
        {
            if (_workTypeQueryService.ExistsWorkTypeCode(request.WorkTypeCode))
            {
                return(ErrorObjectResultFactory.ValidationErrorDetail(
                           string.Format(ErrorMessages.ValidationDuplicated, ErrorMessages.DisplayWorkTypeWorkTypeCode),
                           "workTypeCode"));
            }

            if (_workTypeQueryService.ExistsWorkTypeTree(request.WorkTypeTree))
            {
                return(ErrorObjectResultFactory.ValidationErrorDetail(
                           string.Format(ErrorMessages.ValidationDuplicated, ErrorMessages.DisplayWorkTypeWorkTypeTree),
                           "workTypeTree"));
            }

            var dto    = _mapper.Map <WorkTypeCreateRequest, WorkTypeCreateDto>(request);
            var entity = _workTypeService.CreateWorkType(dto);

            return(_mapper.Map <Domain.Entities.WorkType, WorkType>(entity));
        }