public async Task ExtractFileContainerArtifactFailsIfVstsDropJsonNotFoundTest() { // given var expectedContent = "somestuff"; var entryName = string.Format("{0}/RANDOMNAME", Guid.NewGuid()); var buildClient = new MockBuildClient() { ContentStream = GetZippedStream(expectedContent, entryName) }; var gitClient = new MockGitClient(); var releaseClient = new MockReleaseClient(); var artifactHelper = new VstsArtifactsHelper(buildClient: buildClient, releaseClient: releaseClient, gitClient: gitClient, projectId: Guid.NewGuid(), repoName: "someRepo"); // when var throws = false; try { await artifactHelper.ExtractFileContainerArtifact("someArtifact", 123, default(CancellationToken)); } catch (VstsArtifactsNotFoundException ex) { if (ex.Message.Contains("not found ")) { throws = true; } } // then Assert.IsTrue(throws); }
public async Task WaitForDropArtifactBuildFailedTest() { // given var buildClient = new MockBuildClient() { MockBuild = new Build() { Status = BuildStatus.Completed, Result = BuildResult.Failed, Repository = new BuildRepository() { Name = "someRepo" } }, }; var gitClient = new MockGitClient(); var releaseClient = new MockReleaseClient(); var artifactHelper = new VstsArtifactsHelper(buildClient: buildClient, releaseClient: releaseClient, gitClient: gitClient, projectId: Guid.NewGuid(), repoName: "someRepo"); // when var throws = false; try { await artifactHelper.WaitForDropArtifact("someArtifact", 123, default(CancellationToken)); } catch (VstsArtifactsNotFoundException) { throws = true; } // then Assert.IsTrue(throws); }
public async Task TryGetArtifactBuildIdFromRelease_NoMatchingArtifactSourceAliasTest() { // given var mockArtifactDefinitions = new List <AgentArtifactDefinition>() { new AgentArtifactDefinition() { Alias = "someAlias", Version = "123", } }; var releaseClient = new MockReleaseClient() { MockArtifactDefinitions = mockArtifactDefinitions, }; var gitClient = new MockGitClient(); var buildClient = new MockBuildClient(); var artifactHelper = new VstsArtifactsHelper(buildClient, releaseClient, gitClient, Guid.NewGuid(), "someRepo"); // when var throws = false; try { await artifactHelper.TryGetArtifactBuildIdFromRelease(123, "otherAlias", default(CancellationToken)); } catch (VstsArtifactsNotFoundException) { throws = true; } // then Assert.IsTrue(throws); }
public async Task TryGetArtifactBuildIdFromRelease_MatchingArtifactSourceAliasTest() { // given var mockArtifactDefinitions = new List <AgentArtifactDefinition>() { new AgentArtifactDefinition() { Alias = "someAlias", Version = "123", }, new AgentArtifactDefinition() { Alias = "matchingAlias", Version = "456", }, }; var releaseClient = new MockReleaseClient() { MockArtifactDefinitions = mockArtifactDefinitions, }; var gitClient = new MockGitClient(); var buildClient = new MockBuildClient(); var artifactHelper = new VstsArtifactsHelper(buildClient, releaseClient, gitClient, Guid.NewGuid(), "someRepo"); // when var result = await artifactHelper.TryGetArtifactBuildIdFromRelease(123, "matchingAlias", default(CancellationToken)); // then Assert.IsNotNull(result); Assert.AreEqual(false, result.Failed); Assert.AreEqual(456, result.DropSourceBuildId); }
public async Task WaitForDropArtifactBuildNotFoundTest() { // given var buildClient = new MockBuildClient() { ReturnNullBuild = true, }; var releaseClient = new MockReleaseClient(); var gitClient = new MockGitClient(); var artifactHelper = new VstsArtifactsHelper(buildClient: buildClient, releaseClient: releaseClient, gitClient: gitClient, projectId: Guid.NewGuid(), repoName: "someRepo"); // when var throws = false; try { await artifactHelper.WaitForDropArtifact("someArtifact", 123, default(CancellationToken)); } catch (ArgumentException) { throws = true; } // then Assert.IsTrue(throws); }
public async Task ExtractFileContainerArtifactTest() { // given var expectedContent = "somestuff"; var entryName = string.Format("{0}/{1}", Guid.NewGuid(), VstsArtifactsHelper.VstsDropJsonFileName); var buildClient = new MockBuildClient() { ContentStream = GetZippedStream(expectedContent, entryName) }; var releaseClient = new MockReleaseClient(); var gitClient = new MockGitClient(); var artifactHelper = new VstsArtifactsHelper(buildClient: buildClient, releaseClient: releaseClient, gitClient: gitClient, projectId: Guid.NewGuid(), repoName: "someRepo"); // when var contentString = await artifactHelper.ExtractFileContainerArtifact("someArtifact", 123, default(CancellationToken)); // then Assert.AreEqual(expectedContent, contentString); }
public async Task WaitForDropArtifactGoldenPathTest() { // given var expectedContent = "{\"VstsDropBuildArtifact\":{\"VstsDropUrl\":\"https://someartifacturl\"}}"; var entryName = string.Format("{0}/{1}", Guid.NewGuid(), VstsArtifactsHelper.VstsDropJsonFileName); var buildClient = new MockBuildClient() { MockBuild = new Build() { Status = BuildStatus.Completed, Result = BuildResult.Succeeded }, MockBuildArtifact = new BuildArtifact(), ContentStream = GetZippedStream(expectedContent, entryName), }; var gitClient = new MockGitClient(); var releaseClient = new MockReleaseClient(); var artifactHelper = new VstsArtifactsHelper(buildClient: buildClient, releaseClient: releaseClient, gitClient: gitClient, projectId: Guid.NewGuid(), repoName: "someRepo"); // when var artifactUrl = await artifactHelper.WaitForDropArtifact("someArtifact", 123, default(CancellationToken)); // then Assert.AreEqual("https://someartifacturl", artifactUrl); }