-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
137 additions
and
1 deletion.
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
41 changes: 41 additions & 0 deletions
41
Src/Kent.Boogaart.PCLMock.UnitTests/CodeGeneration/Models/ConfigurationFixture.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,41 @@ | ||
namespace Kent.Boogaart.PCLMock.UnitTests.CodeGeneration.Models | ||
{ | ||
using System.Xml.Linq; | ||
using Kent.Boogaart.PCLMock.CodeGeneration.Models; | ||
using Xunit; | ||
|
||
public sealed class ConfigurationFixture | ||
{ | ||
[Fact] | ||
public void from_xdocument_works_as_expected() | ||
{ | ||
var inputResourceName = "Kent.Boogaart.PCLMock.UnitTests.CodeGeneration.Models.ConfigurationFixtureResources.Input.txt"; | ||
|
||
using (var inputStream = this.GetType().Assembly.GetManifestResourceStream(inputResourceName)) | ||
{ | ||
var document = XDocument.Load(inputStream); | ||
var configuration = Configuration.FromXDocument(document); | ||
|
||
Assert.Equal(2, configuration.NamespaceTransformations.Count); | ||
Assert.Equal("(?<name>.+)", configuration.NamespaceTransformations[0].Pattern); | ||
Assert.Equal("${name}.Mocks", configuration.NamespaceTransformations[0].Replacement); | ||
Assert.Equal("Up", configuration.NamespaceTransformations[1].Pattern); | ||
Assert.Equal("Down", configuration.NamespaceTransformations[1].Replacement); | ||
|
||
Assert.Equal(3, configuration.NameTransformations.Count); | ||
Assert.Equal("I(?<name>[A-Z].*)", configuration.NameTransformations[0].Pattern); | ||
Assert.Equal("${name}", configuration.NameTransformations[0].Replacement); | ||
Assert.Equal("(?<name>[A-Z].*)\\<.*\\>", configuration.NameTransformations[1].Pattern); | ||
Assert.Equal("${name}", configuration.NameTransformations[1].Replacement); | ||
Assert.Equal("(?<name>.+)", configuration.NameTransformations[2].Pattern); | ||
Assert.Equal("${name}Mock", configuration.NameTransformations[2].Replacement); | ||
|
||
Assert.Equal(2, configuration.InterfaceFilters.Count); | ||
Assert.Equal(FilterType.Include, configuration.InterfaceFilters[0].Type); | ||
Assert.Equal(".*", configuration.InterfaceFilters[0].Pattern); | ||
Assert.Equal(FilterType.Exclude, configuration.InterfaceFilters[1].Type); | ||
Assert.Equal("FooBar", configuration.InterfaceFilters[1].Pattern); | ||
} | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
....Boogaart.PCLMock.UnitTests/CodeGeneration/Models/ConfigurationFixtureResources/Input.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,91 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
|
||
<!-- | ||
This input file to PCLMock's mock generation T4 template allows you to control which mocks are generated, and how they are named. | ||
All patterns specified in this file are .NET regular expressions. | ||
--> | ||
<Mocks> | ||
<!-- | ||
Namespace transformations allow you to transform the original namespace into a new namespace in which the mock will be placed. | ||
Each transformation receives the output from the previous transformation, and the first transformation receives the original namespace. | ||
--> | ||
<NamespaceTransformations> | ||
<!-- | ||
append ".Mocks" onto the namespace | ||
--> | ||
<Transformation> | ||
<Pattern><![CDATA[(?<name>.+)]]></Pattern> | ||
<Replacement>${name}.Mocks</Replacement> | ||
</Transformation> | ||
|
||
<!-- | ||
<Transformation> | ||
<Pattern><![CDATA[(?<name>.+)]]></Pattern> | ||
<Replacement>${name}.Mocks</Replacement> | ||
</Transformation> | ||
--> | ||
|
||
<Transformation> | ||
<!-- hello! --> | ||
<Pattern>Up</Pattern> | ||
<Replacement>Down</Replacement> | ||
</Transformation> | ||
</NamespaceTransformations> | ||
|
||
<!-- | ||
Name transformations allow you to transform the original type name into a new name for the generated mock class. | ||
Each transformation receives the output from the previous transformation, and the first transformation receives the original type name. | ||
--> | ||
<NameTransformations> | ||
<!-- | ||
if the name is prefixed with "I", strip it off | ||
--> | ||
<Transformation> | ||
<Pattern><![CDATA[I(?<name>[A-Z].*)]]></Pattern> | ||
<Replacement>${name}</Replacement> | ||
</Transformation> | ||
<!-- | ||
if the name includes generic arguments, strip them out | ||
--> | ||
<Transformation> | ||
<Pattern><![CDATA[(?<name>[A-Z].*)\<.*\>]]></Pattern> | ||
<Replacement>${name}</Replacement> | ||
</Transformation> | ||
<!-- | ||
append "Mock" onto the name | ||
--> | ||
<Transformation> | ||
<Pattern><![CDATA[(?<name>.+)]]></Pattern> | ||
<Replacement>${name}Mock</Replacement> | ||
</Transformation> | ||
|
||
<!-- | ||
<Transformation> | ||
<Pattern><![CDATA[(?<name>.+)]]></Pattern> | ||
<Replacement>${name}Mock</Replacement> | ||
</Transformation> | ||
--> | ||
</NameTransformations> | ||
|
||
<!-- | ||
To determine whether a mock should be generated for a given interface, its assembly-qualified name (e.g. "Name.Space.TypeName, AssemblyName") is matched | ||
against the filters specified below. Filters either Include or Exclude interfaces that match their pattern. Filters are executed in the order | ||
they appear, so latter filters can override the result of an earlier filter. | ||
--> | ||
<Interfaces> | ||
<Include> | ||
<Pattern>.*</Pattern> | ||
</Include> | ||
|
||
<Exclude> | ||
<!-- I don't like foo bar! --> | ||
<Pattern>FooBar</Pattern> | ||
</Exclude> | ||
|
||
<!-- | ||
<Include> | ||
<Pattern>Whatever</Pattern> | ||
</Include> | ||
--> | ||
</Interfaces> | ||
</Mocks> |
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