Skip to content

Commit 19a3e23

Browse files
committed
(GH-19) Added new Tests
- To cover functionality of ReleaseNotesExporter
1 parent 0ca8727 commit 19a3e23

9 files changed

+265
-91
lines changed

Source/GitHubReleaseManager.Cli/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ private static async Task<string> ExportReleases(GitHubClient github, string own
272272
{
273273
var releaseNotesExporter = new ReleaseNotesExporter(new DefaultGitHubClient(github, owner, repository), configuration);
274274

275-
var result = await releaseNotesExporter.GetReleases();
275+
var result = await releaseNotesExporter.ExportReleaseNotes();
276276

277277
return result;
278278
}

Source/GitHubReleaseManager.Tests/FakeGitHubClient.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ public class FakeGitHubClient : IGitHubClient
1717
public FakeGitHubClient()
1818
{
1919
this.Milestones = new List<Milestone>();
20-
this.Issues = new List<Issue>();
20+
this.Issues = new List<Issue>();
21+
this.Releases = new List<Release>();
2122
}
2223

2324
public List<Milestone> Milestones { get; private set; }
2425

25-
public List<Issue> Issues { get; private set; }
26+
public List<Issue> Issues { get; private set; }
27+
28+
public List<Release> Releases { get; private set; }
2629

2730
public int NumberOfCommits { private get; set; }
2831

@@ -37,8 +40,8 @@ public Task<List<Issue>> GetIssues(Milestone targetMilestone)
3740
}
3841

3942
public Task<List<Release>> GetReleases()
40-
{
41-
throw new System.NotImplementedException();
43+
{
44+
return Task.FromResult(this.Releases);
4245
}
4346

4447
public ReadOnlyCollection<Milestone> GetMilestones()
Lines changed: 86 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,87 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4-
<PropertyGroup>
5-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{FAD045A3-CF63-48CA-BA49-8F4D79E3EF4F}</ProjectGuid>
8-
<OutputType>Library</OutputType>
9-
<AppDesignerFolder>Properties</AppDesignerFolder>
10-
<RootNamespace>GitHubReleaseManager.Tests</RootNamespace>
11-
<AssemblyName>GitHubReleaseManager.Tests</AssemblyName>
12-
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
13-
<FileAlignment>512</FileAlignment>
14-
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
15-
<RestorePackages>true</RestorePackages>
16-
<TargetFrameworkProfile />
17-
</PropertyGroup>
18-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19-
<DebugSymbols>true</DebugSymbols>
20-
<DebugType>full</DebugType>
21-
<Optimize>false</Optimize>
22-
<OutputPath>bin\Debug\</OutputPath>
23-
<DefineConstants>DEBUG;TRACE</DefineConstants>
24-
<ErrorReport>prompt</ErrorReport>
25-
<WarningLevel>4</WarningLevel>
26-
</PropertyGroup>
27-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28-
<DebugType>full</DebugType>
29-
<Optimize>false</Optimize>
30-
<OutputPath>bin\Release\</OutputPath>
31-
<DefineConstants>TRACE</DefineConstants>
32-
<ErrorReport>prompt</ErrorReport>
33-
<WarningLevel>4</WarningLevel>
34-
<DebugSymbols>true</DebugSymbols>
35-
</PropertyGroup>
36-
<ItemGroup>
37-
<Reference Include="ApprovalTests">
38-
<HintPath>..\packages\ApprovalTests.3.0.7\lib\net40\ApprovalTests.dll</HintPath>
39-
</Reference>
40-
<Reference Include="ApprovalUtilities">
41-
<HintPath>..\packages\ApprovalUtilities.3.0.7\lib\net35\ApprovalUtilities.dll</HintPath>
42-
</Reference>
43-
<Reference Include="nunit.framework">
44-
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
45-
</Reference>
46-
<Reference Include="Octokit, Version=0.4.1.0, Culture=neutral, processorArchitecture=MSIL">
47-
<SpecificVersion>False</SpecificVersion>
48-
<HintPath>..\packages\Octokit.0.4.1\lib\net45\Octokit.dll</HintPath>
49-
</Reference>
50-
<Reference Include="System" />
51-
<Reference Include="System.Core" />
52-
<Reference Include="System.Net.Http" />
53-
<Reference Include="System.Windows.Forms" />
54-
<Reference Include="System.Xml.Linq" />
55-
<Reference Include="System.Data.DataSetExtensions" />
56-
<Reference Include="Microsoft.CSharp" />
57-
<Reference Include="System.Data" />
58-
<Reference Include="System.Xml" />
59-
</ItemGroup>
60-
<ItemGroup>
61-
<Compile Include="ApprovalTestConfig.cs" />
62-
<Compile Include="ClipBoardHelper.cs" />
63-
<Compile Include="FakeGitHubClient.cs" />
64-
<Compile Include="Helper.cs" />
65-
<Compile Include="ReleaseNotesBuilderIntegrationTests.cs" />
66-
<Compile Include="ClientBuilder.cs" />
67-
<Compile Include="ReleaseNotesBuilderTests.cs" />
68-
</ItemGroup>
69-
<ItemGroup>
70-
<None Include="packages.config">
71-
<SubType>Designer</SubType>
72-
</None>
73-
</ItemGroup>
74-
<ItemGroup>
75-
<ProjectReference Include="..\GitHubReleaseManager\GitHubReleaseManager.csproj">
76-
<Project>{b02a026e-ca3a-48f4-bba9-eb337b0a2035}</Project>
77-
<Name>GitHubReleaseManager</Name>
78-
</ProjectReference>
79-
</ItemGroup>
80-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
81-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
82-
<PropertyGroup>
83-
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
84-
</PropertyGroup>
85-
</Target>
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{FAD045A3-CF63-48CA-BA49-8F4D79E3EF4F}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>GitHubReleaseManager.Tests</RootNamespace>
11+
<AssemblyName>GitHubReleaseManager.Tests</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
15+
<RestorePackages>true</RestorePackages>
16+
<TargetFrameworkProfile />
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<DebugType>full</DebugType>
29+
<Optimize>false</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
<DebugSymbols>true</DebugSymbols>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="ApprovalTests">
38+
<HintPath>..\packages\ApprovalTests.3.0.7\lib\net40\ApprovalTests.dll</HintPath>
39+
</Reference>
40+
<Reference Include="ApprovalUtilities">
41+
<HintPath>..\packages\ApprovalUtilities.3.0.7\lib\net35\ApprovalUtilities.dll</HintPath>
42+
</Reference>
43+
<Reference Include="nunit.framework">
44+
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
45+
</Reference>
46+
<Reference Include="Octokit, Version=0.4.1.0, Culture=neutral, processorArchitecture=MSIL">
47+
<SpecificVersion>False</SpecificVersion>
48+
<HintPath>..\packages\Octokit.0.4.1\lib\net45\Octokit.dll</HintPath>
49+
</Reference>
50+
<Reference Include="System" />
51+
<Reference Include="System.Core" />
52+
<Reference Include="System.Net.Http" />
53+
<Reference Include="System.Windows.Forms" />
54+
<Reference Include="System.Xml.Linq" />
55+
<Reference Include="System.Data.DataSetExtensions" />
56+
<Reference Include="Microsoft.CSharp" />
57+
<Reference Include="System.Data" />
58+
<Reference Include="System.Xml" />
59+
</ItemGroup>
60+
<ItemGroup>
61+
<Compile Include="ApprovalTestConfig.cs" />
62+
<Compile Include="ClipBoardHelper.cs" />
63+
<Compile Include="FakeGitHubClient.cs" />
64+
<Compile Include="Helper.cs" />
65+
<Compile Include="ReleaseNotesBuilderIntegrationTests.cs" />
66+
<Compile Include="ClientBuilder.cs" />
67+
<Compile Include="ReleaseNotesBuilderTests.cs" />
68+
<Compile Include="ReleaseNotesExporterTests.cs" />
69+
</ItemGroup>
70+
<ItemGroup>
71+
<None Include="packages.config">
72+
<SubType>Designer</SubType>
73+
</None>
74+
</ItemGroup>
75+
<ItemGroup>
76+
<ProjectReference Include="..\GitHubReleaseManager\GitHubReleaseManager.csproj">
77+
<Project>{b02a026e-ca3a-48f4-bba9-eb337b0a2035}</Project>
78+
<Name>GitHubReleaseManager</Name>
79+
</ProjectReference>
80+
</ItemGroup>
81+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
82+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
83+
<PropertyGroup>
84+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
85+
</PropertyGroup>
86+
</Target>
8687
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Unable to find any releases for specified repository.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## 0.1.0 (March 12, 2015)
2+
3+
4+
As part of this release we had [3 issues](https://github.com/FakeRepository/issues/issues?milestone=0&state=closed) closed.
5+
6+
7+
__Bug__
8+
9+
- [__#1__](http://example.com/1) Issue 1
10+
11+
__Feature__
12+
13+
- [__#2__](http://example.com/2) Issue 2
14+
15+
__Improvement__
16+
17+
- [__#3__](http://example.com/3) Issue 3
18+
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## 0.1.0
2+
3+
4+
As part of this release we had [3 issues](https://github.com/FakeRepository/issues/issues?milestone=0&state=closed) closed.
5+
6+
7+
__Bug__
8+
9+
- [__#1__](http://example.com/1) Issue 1
10+
11+
__Feature__
12+
13+
- [__#2__](http://example.com/2) Issue 2
14+
15+
__Improvement__
16+
17+
- [__#3__](http://example.com/3) Issue 3
18+
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## 0.1.0 (March 12, 2015)
2+
3+
4+
As part of this release we had [3 issues](https://github.com/FakeRepository/issues/issues?milestone=0&state=closed) closed.
5+
6+
7+
__Bug__
8+
9+
- [__#1__](http://example.com/1) Issue 1
10+
11+
__Feature__
12+
13+
- [__#2__](http://example.com/2) Issue 2
14+
15+
__Improvement__
16+
17+
- [__#3__](http://example.com/3) Issue 3
18+
19+
### Where to get it
20+
You can download this release from [chocolatey](https://chocolatey.org/packages/ChocolateyGUI/0.1.0)
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//-----------------------------------------------------------------------
2+
// <copyright file="ReleaseNotesExporterTests.cs" company="gep13">
3+
// Copyright (c) gep13. All rights reserved.
4+
// </copyright>
5+
//-----------------------------------------------------------------------
6+
7+
namespace GitHubReleaseManager.Tests
8+
{
9+
using System;
10+
using System.Text;
11+
12+
using ApprovalTests;
13+
14+
using GitHubReleaseManager.Configuration;
15+
using GitHubReleaseManager.Helpers;
16+
17+
using NUnit.Framework;
18+
19+
using Octokit;
20+
21+
[TestFixture]
22+
public class ReleaseNotesExporterTests
23+
{
24+
private FileSystem fileSystem = new FileSystem();
25+
private string currentDirectory = Environment.CurrentDirectory;
26+
27+
[Test]
28+
public void NoReleases()
29+
{
30+
var configuration = ConfigurationProvider.Provide(this.currentDirectory, this.fileSystem);
31+
AcceptTest(configuration);
32+
}
33+
34+
[Test]
35+
public void SingleRelease()
36+
{
37+
var configuration = ConfigurationProvider.Provide(this.currentDirectory, this.fileSystem);
38+
AcceptTest(configuration, CreateRelease(1, new DateTime(2015, 3, 12), "0.1.0"));
39+
}
40+
41+
[Test]
42+
public void SingleReleaseExcludeCreatedDateInTitle()
43+
{
44+
var configuration = ConfigurationProvider.Provide(this.currentDirectory, this.fileSystem);
45+
configuration.Export.IncludeCreatedDateInTitle = false;
46+
47+
AcceptTest(configuration, CreateRelease(1, new DateTime(2015, 3, 12), "0.1.0"));
48+
}
49+
50+
[Test]
51+
public void SingleReleaseExcludeRegexRemoval()
52+
{
53+
var configuration = ConfigurationProvider.Provide(this.currentDirectory, this.fileSystem);
54+
configuration.Export.PerformRegexRemoval = false;
55+
56+
AcceptTest(configuration, CreateRelease(1, new DateTime(2015, 3, 12), "0.1.0"));
57+
}
58+
59+
private static void AcceptTest(Config configuration, params Release[] releases)
60+
{
61+
var fakeClient = new FakeGitHubClient();
62+
63+
foreach (var release in releases)
64+
{
65+
fakeClient.Releases.Add(release);
66+
}
67+
68+
var builder = new ReleaseNotesExporter(fakeClient, configuration);
69+
var notes = builder.ExportReleaseNotes().Result;
70+
71+
Approvals.Verify(notes);
72+
}
73+
74+
private static Release CreateRelease(int id, DateTime createdDateTime, string milestone)
75+
{
76+
var stringBuilder = new StringBuilder();
77+
stringBuilder.AppendLine("As part of this release we had [3 issues](https://github.com/FakeRepository/issues/issues?milestone=0&state=closed) closed.");
78+
stringBuilder.AppendLine();
79+
stringBuilder.AppendLine();
80+
stringBuilder.AppendLine("__Bug__");
81+
stringBuilder.AppendLine();
82+
stringBuilder.AppendLine("- [__#1__](http://example.com/1) Issue 1");
83+
stringBuilder.AppendLine();
84+
stringBuilder.AppendLine("__Feature__");
85+
stringBuilder.AppendLine();
86+
stringBuilder.AppendLine("- [__#2__](http://example.com/2) Issue 2");
87+
stringBuilder.AppendLine();
88+
stringBuilder.AppendLine("__Improvement__");
89+
stringBuilder.AppendLine();
90+
stringBuilder.AppendLine("- [__#3__](http://example.com/3) Issue 3");
91+
stringBuilder.AppendLine();
92+
stringBuilder.AppendLine("### Where to get it");
93+
stringBuilder.AppendFormat("You can download this release from [chocolatey](https://chocolatey.org/packages/ChocolateyGUI/{0})", milestone);
94+
95+
return new Release
96+
{
97+
CreatedAt = createdDateTime,
98+
TagName = milestone,
99+
Draft = false,
100+
Name = milestone,
101+
Id = id,
102+
TargetCommitish = "master",
103+
Body = stringBuilder.ToString()
104+
};
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)