public void GetV1ConnectionReturnNoConnectionWithEmptyCredentials() { // Arrange _connectionHelper = new ConnectionHelper(new V1UserCredentials(string.Empty, string.Empty)); // Act var response = _connectionHelper.GetV1Connection(); // Assert Assert.IsNotNull(response); Assert.IsFalse(response.IsValid); Assert.AreEqual(response.ErrorMessage, "Invalid Username/Password."); Assert.IsNull(response.Connection); }
public void GetV1ConnectionReturnNoConnectionWithInvalidCredentials() { // Arrange _connectionHelper = new ConnectionHelper(new V1UserCredentials("Test", "Test")); // Act var response = _connectionHelper.GetV1Connection(); // Assert Assert.IsNotNull(response); Assert.IsFalse(response.IsValid); Assert.AreEqual(response.ErrorMessage, "Unauthorized"); Assert.IsNull(response.Connection); }
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 GetV1ConnectionReturnConnectionSuccess() { // Arrange _connectionHelper = new ConnectionHelper(new V1UserCredentials("yourUsername", "yourPassowrd")); IServices _mockServiceConnection = MockRepository.Mock <IServices>(); IAssetType _mockAssetType = MockRepository.Mock <IAssetType>(); Oid oid = new Oid(_mockAssetType, 1, null); _mockServiceConnection.Expect(x => x.LoggedIn).Return(oid); _mockServiceConnection.Expect(x => x.Meta.GetAssetType(null)).IgnoreArguments().Return(_mockAssetType); // Act var response = _connectionHelper.GetV1Connection(); // Assert Assert.IsNotNull(response); Assert.IsTrue(response.IsValid); Assert.AreEqual(response.ErrorMessage, string.Empty); Assert.IsNotNull(response.Connection); _mockAssetType.VerifyAllExpectations(); _mockServiceConnection.VerifyAllExpectations(); }