|
| 1 | +using LCT.APICommunications.Model; |
| 2 | +using Moq; |
| 3 | +using Moq.Protected; |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Linq; |
| 7 | +using System.Net; |
| 8 | +using System.Text; |
| 9 | +using System.Threading.Tasks; |
| 10 | + |
| 11 | +namespace LCT.APICommunications.UTest |
| 12 | +{ |
| 13 | + [TestFixture] |
| 14 | + public class JfrogAqlApiCommunicationUTest |
| 15 | + { |
| 16 | + |
| 17 | + |
| 18 | + [Test] |
| 19 | + public void JfrogAqlApiCommunication_CheckConnection_ReturnsInvalidOperationException() |
| 20 | + { |
| 21 | + // Arrange |
| 22 | + ArtifactoryCredentials repoCredentials = new ArtifactoryCredentials(); |
| 23 | + string invalidDomainName = ""; // Invalid domain name |
| 24 | + int timeout = 30; // Timeout in seconds |
| 25 | + |
| 26 | + JfrogAqlApiCommunication jfrogApiCommunication = new JfrogAqlApiCommunication(invalidDomainName, repoCredentials, timeout); |
| 27 | + |
| 28 | + // Act & Assert |
| 29 | + Assert.ThrowsAsync<InvalidOperationException>(async () => await jfrogApiCommunication.CheckConnection()); |
| 30 | + } |
| 31 | + |
| 32 | + [Test] |
| 33 | + public void JfrogAqlApiCommunication_GetInternalComponentDataByRepo_ReturnsInvalidOperationException() |
| 34 | + { |
| 35 | + // Arrange |
| 36 | + ArtifactoryCredentials repoCredentials = new ArtifactoryCredentials(); |
| 37 | + string invalidDomainName = ""; // Invalid domain name |
| 38 | + int timeout = 30; // Timeout in seconds |
| 39 | + string invalidRepoName = "invalid-repo-name"; // Invalid repo name |
| 40 | + |
| 41 | + JfrogAqlApiCommunication jfrogApiCommunication = new JfrogAqlApiCommunication(invalidDomainName, repoCredentials, timeout); |
| 42 | + |
| 43 | + // Act & Assert |
| 44 | + Assert.ThrowsAsync<InvalidOperationException>(async () => await jfrogApiCommunication.GetInternalComponentDataByRepo(invalidRepoName)); |
| 45 | + } |
| 46 | + [Test] |
| 47 | + public void JfrogAqlApiCommunication_GetNpmComponentDataByRepo_ReturnsInvalidOperationException() |
| 48 | + { |
| 49 | + // Arrange |
| 50 | + ArtifactoryCredentials repoCredentials = new ArtifactoryCredentials(); |
| 51 | + string invalidDomainName = ""; // Invalid domain name |
| 52 | + int timeout = 30; // Timeout in seconds |
| 53 | + string invalidRepoName = "invalid-npm-repo"; // Invalid repo name |
| 54 | + |
| 55 | + JfrogAqlApiCommunication jfrogApiCommunication = new JfrogAqlApiCommunication(invalidDomainName, repoCredentials, timeout); |
| 56 | + |
| 57 | + // Act & Assert |
| 58 | + Assert.ThrowsAsync<InvalidOperationException>(async () => await jfrogApiCommunication.GetNpmComponentDataByRepo(invalidRepoName)); |
| 59 | + } |
| 60 | + [Test] |
| 61 | + public void JfrogAqlApiCommunication_GetPypiComponentDataByRepo_ReturnsInvalidOperationException() |
| 62 | + { |
| 63 | + // Arrange |
| 64 | + ArtifactoryCredentials repoCredentials = new ArtifactoryCredentials(); |
| 65 | + string invalidDomainName = ""; // Invalid domain name |
| 66 | + int timeout = 30; // Timeout in seconds |
| 67 | + string invalidRepoName = "invalid-pypi-repo"; // Invalid repo name |
| 68 | + |
| 69 | + JfrogAqlApiCommunication jfrogApiCommunication = new JfrogAqlApiCommunication(invalidDomainName, repoCredentials, timeout); |
| 70 | + |
| 71 | + // Act & Assert |
| 72 | + Assert.ThrowsAsync<InvalidOperationException>(async () => await jfrogApiCommunication.GetPypiComponentDataByRepo(invalidRepoName)); |
| 73 | + } |
| 74 | + [Test] |
| 75 | + public void JfrogAqlApiCommunication_GetPackageInfo_ReturnsArgumentException_WhenNoPackageNameOrPathProvided() |
| 76 | + { |
| 77 | + // Arrange |
| 78 | + ArtifactoryCredentials repoCredentials = new ArtifactoryCredentials(); |
| 79 | + string invalidDomainName = ""; // Invalid domain name |
| 80 | + int timeout = 30; // Timeout in seconds |
| 81 | + |
| 82 | + JfrogAqlApiCommunication jfrogApiCommunication = new JfrogAqlApiCommunication(invalidDomainName, repoCredentials, timeout); |
| 83 | + |
| 84 | + // Create a ComponentsToArtifactory object with invalid parameters (both packageName and path are null or empty) |
| 85 | + ComponentsToArtifactory component = new ComponentsToArtifactory |
| 86 | + { |
| 87 | + JfrogPackageName = null, |
| 88 | + Path = null |
| 89 | + }; |
| 90 | + |
| 91 | + // Act & Assert |
| 92 | + Assert.ThrowsAsync<ArgumentException>(async () => await jfrogApiCommunication.GetPackageInfo(component)); |
| 93 | + } |
| 94 | + |
| 95 | + } |
| 96 | +} |
0 commit comments