-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option for not generating async methods
- Loading branch information
Showing
11 changed files
with
237 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace AsyncGenerator.Core | ||
{ | ||
public enum MethodGeneration | ||
{ | ||
/// <summary> | ||
/// The method will be generated | ||
/// </summary> | ||
Generate = 1, | ||
/// <summary> | ||
/// The method won't be generated | ||
/// </summary> | ||
Ignore = 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System.Threading.Tasks; | ||
using AsyncGenerator.Core; | ||
using AsyncGenerator.Core.Transformation; | ||
using NUnit.Framework; | ||
using AsyncGenerator.Tests.Cref.Input; | ||
|
||
namespace AsyncGenerator.Tests.MethodGeneration | ||
{ | ||
[TestFixture] | ||
public class Fixture : BaseFixture<TestCase> | ||
{ | ||
[Test] | ||
public Task TestAfterTransformation() | ||
{ | ||
return ReadonlyTest(p => p | ||
.ConfigureAnalyzation(a => a | ||
.MethodConversion(symbol => MethodConversion.Smart) | ||
) | ||
.ConfigureTransformation(t => t | ||
.MethodGeneration(m => m.Name == "Read" ? Core.MethodGeneration.Ignore : Core.MethodGeneration.Generate) | ||
.AfterTransformation(ValidateDocument) | ||
) | ||
); | ||
} | ||
|
||
[Test] | ||
public Task TestYamlAfterTransformation() | ||
{ | ||
return YamlReadonlyTest(nameof(TestCase), | ||
@"projects: | ||
- filePath: AsyncGenerator.Tests.csproj | ||
analyzation: | ||
methodConversion: | ||
- conversion: Smart | ||
all: true | ||
transformation: | ||
methodGeneration: | ||
- generation: Ignore | ||
name: Read | ||
", | ||
p => p | ||
.ConfigureTransformation(t => t | ||
.AfterTransformation(ValidateDocument)) | ||
); | ||
} | ||
|
||
[Test] | ||
public Task TestXmlAfterTransformation() | ||
{ | ||
return XmlReadonlyTest(nameof(TestCase), | ||
@" | ||
<AsyncGenerator xmlns=""https://github.com/maca88/AsyncGenerator""> | ||
<Projects> | ||
<Project filePath=""AsyncGenerator.Tests.csproj""> | ||
<Analyzation> | ||
<MethodConversion> | ||
<Method conversion=""Smart"" all=""true"" /> | ||
</MethodConversion> | ||
</Analyzation> | ||
<Transformation> | ||
<MethodGeneration> | ||
<Method generation=""Ignore"" name=""Read"" /> | ||
</MethodGeneration> | ||
</Transformation> | ||
</Project> | ||
</Projects> | ||
</AsyncGenerator> | ||
", | ||
p => p | ||
.ConfigureTransformation(t => t | ||
.AfterTransformation(ValidateDocument)) | ||
); | ||
} | ||
|
||
private void ValidateDocument(IProjectTransformationResult result) | ||
{ | ||
AssertValidAnnotations(result); | ||
Assert.AreEqual(1, result.Documents.Count); | ||
var document = result.Documents[0]; | ||
Assert.NotNull(document.OriginalModified); | ||
Assert.AreEqual(GetOutputFile(nameof(TestCase)), document.Transformed.ToFullString()); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Source/AsyncGenerator.Tests/MethodGeneration/Input/TestCase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using AsyncGenerator.TestCases; | ||
|
||
namespace AsyncGenerator.Tests.MethodGeneration.Input | ||
{ | ||
public class TestCase | ||
{ | ||
public void Read() | ||
{ | ||
SimpleFile.Read(); | ||
} | ||
|
||
public void Read2() | ||
{ | ||
Read(); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Source/AsyncGenerator.Tests/MethodGeneration/Output/TestCase.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using AsyncGenerator.TestCases; | ||
|
||
namespace AsyncGenerator.Tests.MethodGeneration.Input | ||
{ | ||
using System.Threading.Tasks; | ||
public partial class TestCase | ||
{ | ||
|
||
public Task Read2Async() | ||
{ | ||
return ReadAsync(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters