/// <summary>
        /// Map the model object 'WorkItemDetailInfoModel' to 'WorkItemDetailInfo'
        /// </summary>
        public static WorkItemDetailInfoModel MapWorkItemDetailInfoToWorkItemDetailInfoModel(this WorkItemDetailInfo workItemDetailInfo)
        {
            var workItemDetailInfoModel = new WorkItemDetailInfoModel()
            {
                WorkItemDetails = workItemDetailInfo.Details?
                                  .Where(d => !string.IsNullOrEmpty(d.DetailValue))
                                  .Select(d => new WorkItemDetailModel
                {
                    Name           = d.DetailDescription,
                    Value          = d.DetailValue,
                    TranslationKey = (d.RequestInformationEntity?.TranslationKey ?? string.Empty),
                    SortOrder      = d.Order
                })
                                  .OrderBy(d => d.SortOrder)
                                  .ToArray()
            };

            if (!string.IsNullOrEmpty(workItemDetailInfo.NoteText))
            {
                var note = new WorkItemDetailModel
                {
                    Name           = workItemDetailInfo.NoteLabel.NullSafeTrim(),
                    Value          = workItemDetailInfo.NoteText.NullSafeTrim(),
                    TranslationKey = workItemDetailInfo.NoteLabelTranslationKey.NullSafeTrim(),
                };

                workItemDetailInfoModel.WorkItemDetails = workItemDetailInfoModel.WorkItemDetails.Concat(new WorkItemDetailModel[] { note }).ToArray();
            }

            return(workItemDetailInfoModel);
        }
コード例 #2
0
        public void return_work_item_details_when_note_is_present()
        {
            const int workItemDetailArrayLengthIncludingNoteLabel = 3;

            var workItemDetailInfo = new WorkItemDetailInfo
            {
                NoteLabel = Any.String(),
                NoteText  = Any.String(),
                NoteLabelTranslationKey = string.Empty,
                Details = Any.WorkItemDetails(2)
            };

            var expectedWorkItemDetail = new WorkItemDetailModel
            {
                Name           = workItemDetailInfo.NoteLabel,
                Value          = workItemDetailInfo.NoteText,
                TranslationKey = workItemDetailInfo.NoteLabelTranslationKey
            };

            var response = GetWorkItemDetails(workItemDetailInfo) as OkObjectResult;

            var actualWorkItemDetails = ((response.Value as ApiOkResponse).Result as ResourceWrapper <WorkItemDetailInfoModel>).Value as WorkItemDetailInfoModel;

            Assert.Equal(200, response.StatusCode);
            Assert.Equal(workItemDetailArrayLengthIncludingNoteLabel, actualWorkItemDetails.WorkItemDetails.Length);
            Assert.Contains(JsonConvert.SerializeObject(expectedWorkItemDetail), JsonConvert.SerializeObject(actualWorkItemDetails.WorkItemDetails));
        }