Skip to content

Commit 1af78d8

Browse files
committed
added test for jburzynski#184 Interface dependencies no longer generated across multiple 'outputDir' directories; updated project URL in nuspec
1 parent ddd2b45 commit 1af78d8

File tree

10 files changed

+135
-78
lines changed

10 files changed

+135
-78
lines changed

nuget-dotnetcli/dotnet-typegen.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<authors>Jacek Burzynski</authors>
77
<owners>Jacek Burzynski</owners>
88
<license type="file">LICENSE</license>
9-
<projectUrl>http://jburzynski.net/TypeGen</projectUrl>
9+
<projectUrl>https://github.com/jburzynski/TypeGen</projectUrl>
1010
<iconUrl>https://raw.githubusercontent.com/jburzynski/type-gen/master/docs/icon.png</iconUrl>
1111
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1212
<description>TypeGen .NET Core CLI tool (TypeGen is a single-class-per-file C# to TypeScript generator)</description>

nuget/TypeGen.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<authors>Jacek Burzynski</authors>
77
<owners>Jacek Burzynski</owners>
88
<license type="file">LICENSE</license>
9-
<projectUrl>http://jburzynski.net/TypeGen</projectUrl>
9+
<projectUrl>https://github.com/jburzynski/TypeGen</projectUrl>
1010
<iconUrl>https://raw.githubusercontent.com/jburzynski/type-gen/master/docs/icon.png</iconUrl>
1111
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1212
<description>TypeGen is a single-class-per-file C# to TypeScript generator</description>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using TypeGen.Core.TypeAnnotations;
2+
3+
namespace TypeGen.FileContentTest.MultipleOutputDirsWithDependencies.Entities;
4+
5+
public class Class1 : Interface1
6+
{
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using TypeGen.Core.TypeAnnotations;
2+
3+
namespace TypeGen.FileContentTest.MultipleOutputDirsWithDependencies.Entities;
4+
5+
public class Class2 : Interface2
6+
{
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace TypeGen.FileContentTest.MultipleOutputDirsWithDependencies.Entities;
2+
3+
public interface Interface1
4+
{
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace TypeGen.FileContentTest.MultipleOutputDirsWithDependencies.Entities;
2+
3+
public interface Interface2
4+
{
5+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using FluentAssertions;
4+
using TypeGen.Core.Generator;
5+
using TypeGen.Core.SpecGeneration;
6+
using TypeGen.FileContentTest.MultipleOutputDirsWithDependencies.Entities;
7+
using TypeGen.FileContentTest.TestingUtils;
8+
using Xunit;
9+
10+
namespace TypeGen.FileContentTest.MultipleOutputDirsWithDependencies;
11+
12+
public class MultipleOutputDirsWithDependenciesTest
13+
{
14+
[Fact]
15+
public async Task TestMultipleOutputDirsWithDependencies()
16+
{
17+
const string class1OutputBase = "./class1/output/";
18+
const string class2OutputBase = "./class2/output/";
19+
const string class1Output = $"{class1OutputBase}class1.ts";
20+
const string class2Output = $"{class2OutputBase}class2.ts";
21+
const string interface1Output = $"{class1OutputBase}interface1.ts";
22+
const string interface2Output = $"{class2OutputBase}interface2.ts";
23+
24+
var generationSpec = new MultipleOutputDirsWithDependenciesGenerationSpec();
25+
var generatorOptions = new GeneratorOptions();
26+
27+
var generator = new Generator(generatorOptions);
28+
var interceptor = GeneratorOutputInterceptor.CreateInterceptor(generator);
29+
30+
await generator.GenerateAsync(generationSpec);
31+
32+
interceptor.GeneratedOutputs.Should().ContainKey(typeof(Class1));
33+
interceptor.GeneratedOutputs.Should().ContainKey(typeof(Class2));
34+
interceptor.GeneratedOutputs.Should().ContainKey(typeof(Interface1));
35+
interceptor.GeneratedOutputs.Should().ContainKey(typeof(Interface2));
36+
37+
interceptor.GeneratedOutputs[typeof(Class1)].Path.Should().Be(class1Output);
38+
interceptor.GeneratedOutputs[typeof(Class2)].Path.Should().Be(class2Output);
39+
interceptor.GeneratedOutputs[typeof(Interface1)].Path.Should().Be(interface1Output);
40+
interceptor.GeneratedOutputs[typeof(Interface2)].Path.Should().Be(interface2Output);
41+
}
42+
43+
private class MultipleOutputDirsWithDependenciesGenerationSpec : GenerationSpec
44+
{
45+
public MultipleOutputDirsWithDependenciesGenerationSpec()
46+
{
47+
AddClass<Class1>("./class1/output");
48+
AddClass<Class2>("./class2/output");
49+
}
50+
}
51+
}
Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,34 @@
11
using System;
22
using Gen = TypeGen.Core.Generator;
33

4-
namespace TypeGen.FileContentTest.TestingUtils
4+
namespace TypeGen.FileContentTest.TestingUtils;
5+
6+
public class GeneratedOutput
57
{
6-
public class GeneratedOutput
8+
/// <summary>
9+
/// Constructs output from <see cref="Gen.FileContentGeneratedArgs" /> produced
10+
/// by a <see cref="Gen.Generator" />
11+
/// </summary>
12+
/// <param name="e"></param>
13+
public GeneratedOutput(Gen.FileContentGeneratedArgs e)
714
{
8-
#region Properties
9-
10-
/// <summary>
11-
/// The path of the generated file
12-
/// </summary>
13-
public string Path { get; set; } = "";
14-
15-
/// <summary>
16-
/// The content of the generated file
17-
/// </summary>
18-
public string Content { get; set; } = "";
15+
Path = e.FilePath;
16+
Content = e.FileContent;
17+
GeneratedFor = e.Type;
18+
}
1919

20-
/// <summary>
21-
/// The type the file was created for
22-
/// </summary>
23-
public Type GeneratedFor { get; set; }
20+
/// <summary>
21+
/// The path of the generated file
22+
/// </summary>
23+
public string Path { get; set; }
2424

25-
/// <summary>
26-
/// Constructs output from <see cref="Gen.FileContentGeneratedArgs"/> produced
27-
/// by a <see cref="Gen.Generator"/>
28-
/// </summary>
29-
/// <param name="e"></param>
30-
public GeneratedOutput(Gen.FileContentGeneratedArgs e)
31-
{
32-
Path = e.FilePath;
33-
Content = e.FileContent;
34-
GeneratedFor = e.Type;
35-
}
25+
/// <summary>
26+
/// The content of the generated file
27+
/// </summary>
28+
public string Content { get; set; }
3629

37-
#endregion
38-
}
39-
}
30+
/// <summary>
31+
/// The type the file was created for
32+
/// </summary>
33+
public Type GeneratedFor { get; set; }
34+
}

src/TypeGen/TypeGen.FileContentTest/TestingUtils/GeneratorOutputInterceptor.cs

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,39 @@
22
using System.Collections.Generic;
33
using Gen = TypeGen.Core.Generator;
44

5-
namespace TypeGen.FileContentTest.TestingUtils
5+
namespace TypeGen.FileContentTest.TestingUtils;
6+
7+
/// <summary>
8+
/// Intercepts the output produced by the <see cref="Gen.Generator" />
9+
/// so it can be evaluated in tests
10+
/// </summary>
11+
public class GeneratorOutputInterceptor
612
{
7-
/// <summary>
8-
/// Intercepts the output produced by the <see cref="Gen.Generator"/>
9-
/// so it can be evaluated in tests
10-
/// </summary>
11-
public class GeneratorOutputInterceptor
13+
private GeneratorOutputInterceptor()
1214
{
15+
}
1316

14-
#region Constructors
15-
16-
/// <summary>
17-
///
18-
/// </summary>
19-
/// <param name="generator"></param>
20-
/// <param name="disableDefaultOutput"></param>
21-
/// <returns></returns>
22-
public static GeneratorOutputInterceptor CreateInterceptor(Gen.Generator generator, bool disableDefaultOutput = true)
23-
{
24-
var interceptor = new GeneratorOutputInterceptor();
25-
if (disableDefaultOutput)
26-
generator.UnsubscribeDefaultFileContentGeneratedHandler();
27-
28-
generator.FileContentGenerated += interceptor.OnOutputCreated;
29-
return interceptor;
30-
31-
}
32-
33-
private GeneratorOutputInterceptor()
34-
{
35-
}
36-
37-
#endregion
38-
39-
#region Properties
40-
41-
42-
public IReadOnlyDictionary<Type, GeneratedOutput> GeneratedOutputs => _GeneratedOutputs;
43-
44-
private Dictionary<Type, GeneratedOutput> _GeneratedOutputs { get; set; } = new Dictionary<Type, GeneratedOutput>();
17+
private Dictionary<Type, GeneratedOutput> _GeneratedOutputs { get; } = new();
4518

46-
#endregion
19+
public IReadOnlyDictionary<Type, GeneratedOutput> GeneratedOutputs => _GeneratedOutputs;
4720

48-
#region Generator interception
21+
/// <summary>
22+
/// </summary>
23+
/// <param name="generator"></param>
24+
/// <param name="disableDefaultOutput"></param>
25+
/// <returns></returns>
26+
public static GeneratorOutputInterceptor CreateInterceptor(Gen.Generator generator, bool disableDefaultOutput = true)
27+
{
28+
var interceptor = new GeneratorOutputInterceptor();
29+
if (disableDefaultOutput)
30+
generator.UnsubscribeDefaultFileContentGeneratedHandler();
4931

50-
private void OnOutputCreated(object sender, Gen.FileContentGeneratedArgs e)
51-
{
52-
_GeneratedOutputs[e.Type] = new GeneratedOutput(e);
53-
}
32+
generator.FileContentGenerated += interceptor.OnOutputCreated;
33+
return interceptor;
34+
}
5435

55-
#endregion
36+
private void OnOutputCreated(object sender, Gen.FileContentGeneratedArgs e)
37+
{
38+
_GeneratedOutputs[e.Type] = new GeneratedOutput(e);
5639
}
57-
}
40+
}

src/TypeGen/TypeGen.FileContentTest/TypeGen.FileContentTest.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<IsPackable>false</IsPackable>
77

88
<PackageId>TypeGen.FileContentTest</PackageId>
9+
10+
<AssemblyVersion>1.0.0.0</AssemblyVersion>
11+
12+
<FileVersion>1.0.0.0</FileVersion>
913
</PropertyGroup>
1014

1115
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">

0 commit comments

Comments
 (0)