Esempio n. 1
0
        private string FormatSingleDefect(V1DefectAssetDto assetDto)
        {
            StringBuilder sbHtml = new StringBuilder(string.Empty);

            sbHtml.Append("<div class='card'>");
            sbHtml.Append("<h2>" + assetDto.OidToken + " - " + assetDto.ItemName + "</h2><h5>");
            sbHtml.Append("<br/>PROJECT:  " + assetDto.ScopeName);
            sbHtml.Append("<br/>OWNERS:  " + assetDto.OwnersName);
            sbHtml.Append("<br/>STATUS:  " + assetDto.StatusName);
            sbHtml.Append("<br/>ESTIMATED POINTS:  " + assetDto.EstimatedPoints);
            sbHtml.Append("<br/>PRIORITY:  " + assetDto.PriorityName);
            sbHtml.Append("<br/>TAGS:  " + assetDto.TaggedWith);
            sbHtml.Append("<br/>PRODUCT AREA:  " + assetDto.ProductArea);
            sbHtml.Append("<br/>REPORTING SITE:  " + assetDto.ReportingSite);
            sbHtml.Append("<br/>SEVERITY:  " + assetDto.Severity);
            sbHtml.Append("<br/>SOURCE:  " + assetDto.SourceName);
            sbHtml.Append("<br/>VERSION AFFECTED:  " + assetDto.VersionAffected);
            sbHtml.Append("<br/>FOUND BY:  " + assetDto.FoundBy);
            sbHtml.Append("<br/>RESOLUTIION DETAILS:  " + assetDto.ResolutionDetails);
            sbHtml.Append("<br/>ITEM NUMBER:  " + assetDto.ItemNumber);
            sbHtml.Append("<br/>ASSET STATE:  " + assetDto.AssetState);
            sbHtml.Append("</h5><p>Description: " + assetDto.Description + "</p>");
            sbHtml.Append("</div>");
            return(sbHtml.ToString());
        }
        public V1DefectAssetDto MapDefectAssetToAssetDto()
        {
            V1DefectAssetDto defectAssetDto = null;

            if (_asset != null && _assetType != null)
            {
                defectAssetDto          = new V1DefectAssetDto();
                defectAssetDto.OidToken = _asset.Oid.Token;
                if (_asset.Attributes.Count > 0)
                {
                    defectAssetDto.ItemName = (_asset.GetAttribute(_assetType.GetAttributeDefinition("Name")).Value != null) ? _asset.GetAttribute(_assetType.GetAttributeDefinition("Name")).Value.ToString() : string.Empty;

                    defectAssetDto.ItemNumber = (_asset.GetAttribute(_assetType.GetAttributeDefinition("Number")).Value != null) ? _asset.GetAttribute(_assetType.GetAttributeDefinition("Number")).Value.ToString() : string.Empty;

                    defectAssetDto.EstimatedPoints = (_asset.GetAttribute(_assetType.GetAttributeDefinition("Estimate")).Value != null) ? _asset.GetAttribute(_assetType.GetAttributeDefinition("Estimate")).Value.ToString() : string.Empty;

                    defectAssetDto.AssetState = (_asset.GetAttribute(_assetType.GetAttributeDefinition("AssetState")).Value != null) ? _asset.GetAttribute(_assetType.GetAttributeDefinition("AssetState")).Value.ToString() : string.Empty;

                    defectAssetDto.ScopeName = (_asset.GetAttribute(_assetType.GetAttributeDefinition("Scope.Name")).Value != null) ? _asset.GetAttribute(_assetType.GetAttributeDefinition("Scope.Name")).Value.ToString() : string.Empty;

                    defectAssetDto.StatusName = (_asset.GetAttribute(_assetType.GetAttributeDefinition("Status.Name")).Value != null) ? _asset.GetAttribute(_assetType.GetAttributeDefinition("Status.Name")).Value.ToString() : string.Empty;

                    defectAssetDto.PriorityName = (_asset.GetAttribute(_assetType.GetAttributeDefinition("Priority.Name")).Value != null) ? _asset.GetAttribute(_assetType.GetAttributeDefinition("Priority.Name")).Value.ToString() : string.Empty;

                    defectAssetDto.TaggedWith = (_asset.GetAttribute(_assetType.GetAttributeDefinition("TaggedWith")).Value != null) ? _asset.GetAttribute(_assetType.GetAttributeDefinition("TaggedWith")).Value.ToString() : string.Empty;

                    defectAssetDto.Description = (_asset.GetAttribute(_assetType.GetAttributeDefinition("Description")).Value != null) ? _asset.GetAttribute(_assetType.GetAttributeDefinition("Description")).Value.ToString() : string.Empty;

                    defectAssetDto.SourceName = (_asset.GetAttribute(_assetType.GetAttributeDefinition("Source.Name")).Value != null) ? _asset.GetAttribute(_assetType.GetAttributeDefinition("Source.Name")).Value.ToString() : string.Empty;

                    defectAssetDto.VersionAffected = (_asset.GetAttribute(_assetType.GetAttributeDefinition("VersionAffected")).Value != null) ? _asset.GetAttribute(_assetType.GetAttributeDefinition("VersionAffected")).Value.ToString() : string.Empty;

                    defectAssetDto.FoundBy = (_asset.GetAttribute(_assetType.GetAttributeDefinition("FoundBy")).Value != null) ? _asset.GetAttribute(_assetType.GetAttributeDefinition("FoundBy")).Value.ToString() : string.Empty;

                    defectAssetDto.ProductArea = (_asset.GetAttribute(_assetType.GetAttributeDefinition("Custom_ProductArea4.Name")).Value != null) ? _asset.GetAttribute(_assetType.GetAttributeDefinition("Custom_ProductArea4.Name")).Value.ToString() : string.Empty;

                    defectAssetDto.ReportingSite = (_asset.GetAttribute(_assetType.GetAttributeDefinition("Custom_ReportingSite4.Name")).Value != null) ? _asset.GetAttribute(_assetType.GetAttributeDefinition("Custom_ReportingSite4.Name")).Value.ToString() : string.Empty;

                    defectAssetDto.Severity = (_asset.GetAttribute(_assetType.GetAttributeDefinition("Custom_Severity3.Name")).Value != null) ? _asset.GetAttribute(_assetType.GetAttributeDefinition("Custom_Severity3.Name")).Value.ToString() : string.Empty;

                    defectAssetDto.ResolutionDetails = (_asset.GetAttribute(_assetType.GetAttributeDefinition("ResolutionReason.Name")).Value != null) ? _asset.GetAttribute(_assetType.GetAttributeDefinition("ResolutionReason.Name")).Value.ToString() : string.Empty;

                    if (_asset.GetAttribute(_assetType.GetAttributeDefinition("Owners.Name")).ValuesList != null &&
                        _asset.GetAttribute(_assetType.GetAttributeDefinition("Owners.Name")).ValuesList.Count > 0)
                    {
                        foreach (var owner in _asset.GetAttribute(_assetType.GetAttributeDefinition("Owners.Name")).ValuesList)
                        {
                            defectAssetDto.OwnersName += owner.ToString() + ", ";
                        }
                        if (defectAssetDto.OwnersName.Length > 0)
                        {
                            defectAssetDto.OwnersName = defectAssetDto.OwnersName.Substring(0, defectAssetDto.OwnersName.Length - 2);
                        }
                    }
                }
            }

            return(defectAssetDto);
        }
        public void BuildJsonPatchDocumentsReturnsEmptyWithOneNullDefectAssetDtoInListDefectAssetDtos()
        {
            // Arrange
            IList <V1DefectAssetDto> v1DefectAssetDtos = new List <V1DefectAssetDto>();
            V1DefectAssetDto         v1DefectAssetDto  = null;

            v1DefectAssetDtos.Add(v1DefectAssetDto);
            _aDOIssuePatchDocumentBuilder = new ADOIssuePatchDocumentBuilder(v1DefectAssetDtos);

            // Act
            var response = _aDOIssuePatchDocumentBuilder.BuildJsonPatchDocuments();

            // Assert
            Assert.AreEqual(response.Count, 1);
            Assert.IsNull(response[0]);
        }
        public void ADOServiceReturnsOneWorkItemsForOneDefectAssetDtoTest()
        {
            // Arrange
            _aDOService = new ADOService(_projectName, _mockConnectionHelper);
            IList <V1DefectAssetDto> v1DefectAssetDtos = new List <V1DefectAssetDto>();
            V1DefectAssetDto         v1DefectAssetDto  = new V1DefectAssetDto()
            {
                ItemName = "Test", ItemNumber = "1"
            };

            v1DefectAssetDtos.Add(v1DefectAssetDto);

            _mockConnectionHelper.Expect(x => x.GetADOWorkItemTrackingHttpClient()).Return(null);

            // Act
            IList <WorkItem> response = _aDOService.MigrateAllV1DefectsByProjectName(v1DefectAssetDtos);

            // Assert
            Assert.IsNotNull(response);
            Assert.AreEqual(response.Count, 1);
        }
        public IList <V1DefectAssetDto> GetAllDefectDetailsByProjectName()
        {
            V1ConnectionDto V1ConnectionDto = null;

            try
            {
                V1ConnectionDto = _connectionHelper.GetV1Connection();
                if (V1ConnectionDto.Connection != null && V1ConnectionDto.IsValid && string.IsNullOrEmpty(V1ConnectionDto.ErrorMessage))
                {
                    IList <V1DefectAssetDto> defectAssetDtos = new List <V1DefectAssetDto>();
                    // Create AssetType object
                    IAssetType assetType = V1ConnectionDto.Connection.Meta.GetAssetType(DEFECT);

                    //Build a query to fetch data from V1 database
                    V1QueryBuilder queryBuilder = new V1QueryBuilder(assetType);
                    Query          query        = queryBuilder.BuildDefectQuery(_projectName);

                    // We do the actually query on the server here and get our results to be processed soon after
                    QueryResult result = V1ConnectionDto.Connection.Retrieve(query);

                    //Map result assets to DefectAssetDto objects and add to list
                    foreach (Asset asset in result.Assets)
                    {
                        V1AssetToAssetDtoMapper defectMapper   = new V1AssetToAssetDtoMapper(assetType, asset);
                        V1DefectAssetDto        defectAssetDto = defectMapper.MapDefectAssetToAssetDto();
                        defectAssetDtos.Add(defectAssetDto);
                    }

                    return(defectAssetDtos);
                }
                else
                {
                    throw new Exception(V1ConnectionDto.ErrorMessage);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void BuildJsonPatchDocumentsReturnsEmptyWithOneValidDefectAssetDtoInListDefectAssetDtos()
        {
            // Arrange
            IList <V1DefectAssetDto> v1DefectAssetDtos = new List <V1DefectAssetDto>();
            V1DefectAssetDto         v1DefectAssetDto  = new V1DefectAssetDto()
            {
                ItemName = "Test", ItemNumber = "1"
            };

            v1DefectAssetDtos.Add(v1DefectAssetDto);
            _aDOIssuePatchDocumentBuilder = new ADOIssuePatchDocumentBuilder(v1DefectAssetDtos);

            // Act
            IList <JsonPatchDocument> response = _aDOIssuePatchDocumentBuilder.BuildJsonPatchDocuments();

            // Assert
            Assert.IsNotNull(response[0]);
            Assert.AreEqual(response.Count, 1);
            Assert.AreEqual(response[0][0].Operation, Operation.Add);
            Assert.AreEqual(response[0][0].Path, "/fields/System.Title");
            Assert.AreEqual(response[0][0].Value, "PROJECT: , ITEM NUMBER: 1, ITEM NAME: Test");
        }
Esempio n. 7
0
        private JsonPatchDocument BuildADOIssuePatchDocumentFromV1DefectAssetdto(V1DefectAssetDto v1DefectAssetDto)
        {
            JsonPatchDocument patchDocument = null;

            if (v1DefectAssetDto != null)
            {
                patchDocument = new JsonPatchDocument();

                if (!string.IsNullOrEmpty(v1DefectAssetDto.ScopeName) ||
                    !string.IsNullOrEmpty(v1DefectAssetDto.ItemNumber) ||
                    !string.IsNullOrEmpty(v1DefectAssetDto.ItemName))
                {
                    patchDocument.Add(
                        new JsonPatchOperation()
                    {
                        Operation = Operation.Add,
                        Path      = "/fields/System.Title",
                        Value     = string.Format("PROJECT: {0}, ITEM NUMBER: {1}, ITEM NAME: {2}", v1DefectAssetDto.ScopeName, v1DefectAssetDto.ItemNumber, v1DefectAssetDto.ItemName)
                    }
                        );
                }

                if (!string.IsNullOrEmpty(v1DefectAssetDto.EstimatedPoints))
                {
                    patchDocument.Add(
                        new JsonPatchOperation()
                    {
                        Operation = Operation.Add,
                        Path      = "/fields/Microsoft.VSTS.Scheduling.StoryPoints",
                        Value     = v1DefectAssetDto.EstimatedPoints
                    }
                        );
                }

                //if (!string.IsNullOrEmpty(v1DefectAssetDto.StatusName)
                //    || !string.IsNullOrEmpty(v1DefectAssetDto.AssetState))
                //{
                //    patchDocument.Add(
                //        new JsonPatchOperation()
                //        {
                //            Operation = Operation.Add,
                //            Path = "/fields/System.State",
                //            Value = string.Format("STATUS NAME: {0}, ASSET STATE: {1}", v1DefectAssetDto.StatusName, v1DefectAssetDto.AssetState)
                //        }
                //    );
                //}

                //if (!string.IsNullOrEmpty(v1DefectAssetDto.PriorityName))
                //{
                //    patchDocument.Add(
                //        new JsonPatchOperation()
                //        {
                //            Operation = Operation.Add,
                //            Path = "/fields/Microsoft.VSTS.Common.Priority",
                //            Value = v1DefectAssetDto.PriorityName
                //        }
                //    );
                //}

                if (!string.IsNullOrEmpty(v1DefectAssetDto.TaggedWith))
                {
                    patchDocument.Add(
                        new JsonPatchOperation()
                    {
                        Operation = Operation.Add,
                        Path      = "/fields/System.Tags",
                        Value     = v1DefectAssetDto.TaggedWith
                    }
                        );
                }

                if (!string.IsNullOrEmpty(v1DefectAssetDto.Description))
                {
                    patchDocument.Add(
                        new JsonPatchOperation()
                    {
                        Operation = Operation.Add,
                        Path      = "/fields/System.Description",
                        Value     = v1DefectAssetDto.Description
                    }
                        );
                }

                if (!string.IsNullOrEmpty(v1DefectAssetDto.SourceName) ||
                    !string.IsNullOrEmpty(v1DefectAssetDto.VersionAffected) ||
                    !string.IsNullOrEmpty(v1DefectAssetDto.FoundBy) ||
                    !string.IsNullOrEmpty(v1DefectAssetDto.ProductArea))
                {
                    patchDocument.Add(
                        new JsonPatchOperation()
                    {
                        Operation = Operation.Add,
                        Path      = "/fields/Microsoft.VSTS.TCM.SystemInfo",
                        Value     = string.Format("SOURCE: {0}, VERSION AFFECTED: {1}, FOUND BY: {2}, PRODUCT AREA: {3}", v1DefectAssetDto.SourceName, v1DefectAssetDto.VersionAffected, v1DefectAssetDto.FoundBy, v1DefectAssetDto.ProductArea)
                    }
                        );
                }

                if (!string.IsNullOrEmpty(v1DefectAssetDto.ReportingSite))
                {
                    patchDocument.Add(
                        new JsonPatchOperation()
                    {
                        Operation = Operation.Add,
                        Path      = "/fields/Microsoft.VSTS.Build.FoundIn",
                        Value     = v1DefectAssetDto.ReportingSite
                    }
                        );
                }

                //if (!string.IsNullOrEmpty(v1DefectAssetDto.Severity))
                //{
                //    patchDocument.Add(
                //        new JsonPatchOperation()
                //        {
                //            Operation = Operation.Add,
                //            Path = "/fields/Microsoft.VSTS.Common.Severity",
                //            Value = v1DefectAssetDto.Severity
                //        }
                //    );
                //}

                if (!string.IsNullOrEmpty(v1DefectAssetDto.ResolutionDetails))
                {
                    patchDocument.Add(
                        new JsonPatchOperation()
                    {
                        Operation = Operation.Add,
                        Path      = "/fields/Microsoft.VSTS.Common.ResolvedReason",
                        Value     = v1DefectAssetDto.ResolutionDetails
                    }
                        );
                }

                //if (!string.IsNullOrEmpty(v1DefectAssetDto.OwnersName))
                //{
                //    patchDocument.Add(
                //        new JsonPatchOperation()
                //        {
                //            Operation = Operation.Add,
                //            Path = "/fields/System.AssignedTo",
                //            Value = v1DefectAssetDto.OwnersName
                //        }
                //    );
                //}
            }
            return(patchDocument);
        }