Skip to content

Commit

Permalink
Create NSwagStudioCodeGenerator tests with mock data
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhelle committed Nov 9, 2019
1 parent b02737b commit e41729d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ApiClientCodeGen.Tests/ApiClientCodeGen.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<Compile Include="Generators\CSharpFileMergerTests.cs" />
<Compile Include="DeploymentItemTests.cs" />
<Compile Include="Generators\CodeGeneratorTests.cs" />
<Compile Include="Generators\NSwagStudio\NSwagStudioCodeGeneratorTests.cs" />
<Compile Include="Generators\NSwagStudio\NSwagStudioFileHelperTests.cs" />
<Compile Include="Generators\NSwag\NSwagCodeGeneratorSettingsFactoryTests.cs" />
<Compile Include="Generators\NSwag\NSwagCSharpCodeGeneratorTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.IO;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Core;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Core.Generators;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Core.Generators.NSwagStudio;
using ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Core.Options.General;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace ChristianHelle.DeveloperTools.CodeGenerators.ApiClient.Tests.Generators.NSwagStudio
{
[TestClass]
[TestCategory("SkipWhenLiveUnitTesting")]
[DeploymentItem("Resources/Swagger.nswag")]
[DeploymentItem("Resources/Swagger.json")]
public class NSwagStudioCodeGeneratorTests
{
private Mock<IGeneralOptions> optionsMock;
private Mock<IProcessLauncher> processMock;
private Mock<IProgressReporter> progressMock;
private IGeneralOptions options;

[TestInitialize]
public void Init()
{
optionsMock = new Mock<IGeneralOptions>();
optionsMock.Setup(c => c.NSwagPath).Returns(Path.GetTempFileName());
options = optionsMock.Object;

processMock = new Mock<IProcessLauncher>();
progressMock = new Mock<IProgressReporter>();
}

[TestMethod]
public void NSwagStudio_Generate_Code_Using_NSwagStudio()
=> new NSwagStudioCodeGenerator(Path.GetFullPath("Swagger.nswag"), options, processMock.Object)
.GenerateCode(progressMock.Object)
.Should()
.BeNull();

[TestMethod]
public void Reads_NSwagPath_From_Options()
{
progressMock = new Mock<IProgressReporter>();
new NSwagStudioCodeGenerator(
Path.GetFullPath("Swagger.nswag"),
options,
processMock.Object)
.GenerateCode(progressMock.Object);

optionsMock.Verify(c => c.NSwagPath);
}
}
}

0 comments on commit e41729d

Please sign in to comment.