public async Task Execute_adds_Release_metadata_if_the_release_has_release_base(long?ticks) { var releasedAt = ticks.HasValue ? new DateTime(ticks.Value).ToUniversalTime() : default(DateTime?); // ARRANGE m_ReleaseClientMock .Setup(x => x.GetAsync(It.IsAny <ProjectId>(), It.IsAny <Action <ReleaseQueryOptions> >())) .ReturnsAsync(new[] { new Release() { ReleasedAt = releasedAt } }); var sut = new ReadGitLabReleases("namespace", "project", m_ClientFactoryMock.Object); // ACT var output = await ExecuteAsync(sut).SingleAsync(); // ASSERT if (ticks.HasValue) { output.GetGitLabReleaseDate().Should().Be(releasedAt !.Value); } else { output.GetGitLabReleaseDate().Should().BeNull(); } }
public async Task Execute_no_documents_if_there_are_no_GitHub_releases() { // ARRANGE m_ReleaseClientMock .Setup(x => x.GetAsync(It.IsAny <ProjectId>(), It.IsAny <Action <ReleaseQueryOptions> >())) .ReturnsAsync(Array.Empty <Release>()); var sut = new ReadGitLabReleases("namespace", "project", m_ClientFactoryMock.Object); // ACT var outputs = await ExecuteAsync(sut); // ASSERT outputs.Should().NotBeNull().And.BeEmpty(); }
public async Task Execute_uses_the_configured_access_token(string?accessToken) { // ARRANGE m_ReleaseClientMock .Setup(x => x.GetAsync(It.IsAny <ProjectId>(), It.IsAny <Action <ReleaseQueryOptions> >())) .ReturnsAsync(Array.Empty <Release>()); var sut = new ReadGitLabReleases("namespace", "project", m_ClientFactoryMock.Object) .WithAccessToken(accessToken !); // ACT var outputs = await ExecuteAsync(sut); // ASSERT m_ClientFactoryMock.Verify(x => x.CreateClient(It.IsAny <string>(), accessToken), Times.Once); }
public async Task Execute_returns_expected_documents() { // ARRANGE m_ReleaseClientMock .Setup(x => x.GetAsync(It.IsAny <ProjectId>(), It.IsAny <Action <ReleaseQueryOptions> >())) .ReturnsAsync(new[] { new Release() { ReleaseName = "v1.0", TagName = "some-tag", Description = "Body 1" }, new Release() { ReleaseName = "v2.0 Beta", TagName = "some-other-tag", Description = "Body 2" } }); var sut = new ReadGitLabReleases("namespace", "project", m_ClientFactoryMock.Object); // ACT var outputs = await ExecuteAsync(sut); // ASSERT outputs.Should().NotBeNull().And.HaveCount(2); { var document = outputs.First(); document.GetGitLabReleaseName().Should().Be("v1.0"); document.GetGitLabReleaseTagName().Should().Be("some-tag"); document.MediaTypeEquals(MediaTypes.Markdown).Should().BeTrue(); (await document.GetContentStringAsync()).Should().Be("Body 1"); } { var document = outputs.Last(); document.GetGitLabReleaseName().Should().Be("v2.0 Beta"); document.GetGitLabReleaseTagName().Should().Be("some-other-tag"); document.MediaTypeEquals(MediaTypes.Markdown).Should().BeTrue(); (await document.GetContentStringAsync()).Should().Be("Body 2"); } }
public async Task Execute_uses_the_configured_host_name(string?configuredHostName, string expectedHostName) { // ARRANGE m_ReleaseClientMock .Setup(x => x.GetAsync(It.IsAny <ProjectId>(), It.IsAny <Action <ReleaseQueryOptions> >())) .ReturnsAsync(Array.Empty <Release>()); var sut = new ReadGitLabReleases("namespace", "project", m_ClientFactoryMock.Object); if (configuredHostName != null) { sut = sut.WithHostName(configuredHostName); } // ACT var outputs = await ExecuteAsync(sut); // ASSERT m_ClientFactoryMock.Verify(x => x.CreateClient(expectedHostName, It.IsAny <string?>()), Times.Once); }
public async Task Execute_returns_releases_in_the_configured_output_format(OutputFormat?format, string markdown, string html, string expectedContent) { // ARRANGE m_ReleaseClientMock .Setup(x => x.GetAsync(It.IsAny <ProjectId>(), It.IsAny <Action <ReleaseQueryOptions> >())) .ReturnsAsync(new[] { new Release() { Description = markdown, DescriptionHtml = html } }); var sut = new ReadGitLabReleases("namespace", "project", m_ClientFactoryMock.Object); if (format.HasValue) { sut = sut.WithOutputFormat(format.Value); } var expectedMediaType = format switch { OutputFormat.Html => MediaTypes.Html, OutputFormat.Markdown => MediaTypes.Markdown, _ => MediaTypes.Markdown }; // ACT var output = await ExecuteAsync(sut).SingleAsync(); // ASSERT var actualContent = await output.GetContentStringAsync(); actualContent.Should().Be(expectedContent); output.MediaTypeEquals(expectedMediaType).Should().BeTrue(); } }