Skip to content

Commit

Permalink
UT addition
Browse files Browse the repository at this point in the history
  • Loading branch information
Viji committed Jul 24, 2024
1 parent dcaaad8 commit 79f3f63
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/AritfactoryUploader.UTest/ArtifactoryValidatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,33 @@ public async Task ValidateArtifactoryCredentials_InputAppsettings_ReturnsIsvalid
//Assert
jfrogCommunicationMck.Verify(x => x.GetApiKey(), Times.AtLeastOnce);
}

[Test]
public void ValidateArtifactoryCredentials_InputAppsettings_ThrowsInvalidDataException()
{
//Arrange
JfrogKey jfrogKey = new JfrogKey() { ApiKey = "tyyteye" };
HttpResponseMessage httpResponseMessage = new HttpResponseMessage(HttpStatusCode.Unauthorized)
{
Content = new ObjectContent<JfrogKey>(jfrogKey, new JsonMediaTypeFormatter(), "application/some-format")
};
CommonAppSettings appSettings = new CommonAppSettings()
{
ArtifactoryUploadApiKey = "gegeg",
ArtifactoryUploadUser = "[email protected]"
};
ArtifactoryCredentials artifactoryCredentials = new ArtifactoryCredentials()
{
ApiKey = "tyyteye",
Email = "[email protected]"
};
Mock<NpmJfrogApiCommunication> jfrogCommunicationMck = new Mock<NpmJfrogApiCommunication>(UTParams.JFrogURL, "test", artifactoryCredentials, 100);
ArtifactoryValidator artifactoryValidator = new ArtifactoryValidator(jfrogCommunicationMck.Object);
jfrogCommunicationMck.Setup(x => x.GetApiKey()).ReturnsAsync(httpResponseMessage);

// due to environment .exit the below method will not return anything , it wil break there
// assert will not pass always
// Assert.ThrowsAsync<InvalidDataException>(async () => await artifactoryValidator.ValidateArtifactoryCredentials(appSettings))
}
}
}

0 comments on commit 79f3f63

Please sign in to comment.