public void GetAllDefectDetailsByProjectNameReturnsValidResponseTest() { // Arrange V1ConnectionDto v1ConnectionDto = new V1ConnectionDto() { IsValid = true, ErrorMessage = string.Empty, Connection = _mockServiceConnection }; _v1Service = new V1Service(_projectName, _mockConnectionHelper); Asset asset = new Asset(_mockAssetType); AssetList assets = new AssetList { asset }; QueryResult result = new QueryResult(assets, 1, null); _mockConnectionHelper.Expect(x => x.GetV1Connection()).Return(v1ConnectionDto); _mockServiceConnection.Expect(x => x.Meta.GetAssetType("Defect")).IgnoreArguments().Return(_mockAssetType); _mockServiceConnection.Expect(x => x.Retrieve(null)).IgnoreArguments().Return(result); // Act var response = _v1Service.GetAllDefectDetailsByProjectName(); //Assert Assert.IsNotNull(response); Assert.AreEqual(response.Count, 1); _mockConnectionHelper.VerifyAllExpectations(); _mockAssetType.VerifyAllExpectations(); _mockServiceConnection.VerifyAllExpectations(); }
public V1ConnectionDto GetV1Connection() { V1ConnectionDto v1ConnectionDto = new V1ConnectionDto(); try { if (!string.IsNullOrEmpty(_credentials.Username) && !string.IsNullOrEmpty(_credentials.Password)) { V1Connector connector = V1Connector .WithInstanceUrl(ConfigHelper.V1Url) .WithUserAgentHeader(ConfigHelper.V1Name, ConfigHelper.V1Version) .WithUsernameAndPassword(_credentials.Username, _credentials.Password) .Build(); IServices connection = new VersionOne.SDK.APIClient.Services(connector); if (connection.LoggedIn != null) { v1ConnectionDto.IsValid = true; v1ConnectionDto.ErrorMessage = string.Empty; v1ConnectionDto.Connection = connection; } } else { v1ConnectionDto.IsValid = false; v1ConnectionDto.ErrorMessage = "Invalid Username/Password."; } } catch (Exception ex) { v1ConnectionDto.IsValid = false; if ((ex.InnerException != null) && (ex.InnerException.Message.Equals("Unauthorized"))) { v1ConnectionDto.ErrorMessage = "Unauthorized"; } else { v1ConnectionDto.ErrorMessage = "Exception Occured"; } } return(v1ConnectionDto); }
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; } }