From 79f3f634695a780f3e51e8a57cfd414e563b681f Mon Sep 17 00:00:00 2001 From: Viji Date: Wed, 24 Jul 2024 14:21:29 +0530 Subject: [PATCH] UT addition --- .../ArtifactoryValidatorTest.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/AritfactoryUploader.UTest/ArtifactoryValidatorTest.cs b/src/AritfactoryUploader.UTest/ArtifactoryValidatorTest.cs index 4fbd5da8..6794c4da 100644 --- a/src/AritfactoryUploader.UTest/ArtifactoryValidatorTest.cs +++ b/src/AritfactoryUploader.UTest/ArtifactoryValidatorTest.cs @@ -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, new JsonMediaTypeFormatter(), "application/some-format") + }; + CommonAppSettings appSettings = new CommonAppSettings() + { + ArtifactoryUploadApiKey = "gegeg", + ArtifactoryUploadUser = "user@test.com" + }; + ArtifactoryCredentials artifactoryCredentials = new ArtifactoryCredentials() + { + ApiKey = "tyyteye", + Email = "user@test.com" + }; + Mock jfrogCommunicationMck = new Mock(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(async () => await artifactoryValidator.ValidateArtifactoryCredentials(appSettings)) + } } }