Skip to content

Commit 65a31e0

Browse files
committed
** Version 3 **
1 parent e326945 commit 65a31e0

File tree

388 files changed

+66797
-11367
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

388 files changed

+66797
-11367
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
[Dd]ebugPublic/
1717
[Rr]elease/
1818
[Rr]eleases/
19+
Generator/[Tt]ools/
1920
x64/
2021
x86/
2122
bld/
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\NUnit.3.11.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" />
4+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
5+
<PropertyGroup>
6+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8+
<ProjectGuid>{78040713-6968-4B7A-8446-0DE34C7EB3C3}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>BuildTT.UnitTests</RootNamespace>
12+
<AssemblyName>BuildTT.UnitTests</AssemblyName>
13+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
<Deterministic>true</Deterministic>
16+
<NuGetPackageImportStamp>
17+
</NuGetPackageImportStamp>
18+
</PropertyGroup>
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="nunit.framework, Version=3.11.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
38+
<HintPath>..\packages\NUnit.3.11.0\lib\net45\nunit.framework.dll</HintPath>
39+
</Reference>
40+
<Reference Include="System" />
41+
<Reference Include="System.Core" />
42+
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
43+
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
44+
</Reference>
45+
<Reference Include="System.Xml.Linq" />
46+
<Reference Include="System.Data.DataSetExtensions" />
47+
<Reference Include="Microsoft.CSharp" />
48+
<Reference Include="System.Data" />
49+
<Reference Include="System.Net.Http" />
50+
<Reference Include="System.Xml" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<Compile Include="FileReaderTests.cs" />
54+
<Compile Include="FileWriterTests.cs" />
55+
<Compile Include="Properties\AssemblyInfo.cs" />
56+
<Compile Include="StringReaderStrategy.cs" />
57+
</ItemGroup>
58+
<ItemGroup>
59+
<None Include="packages.config" />
60+
</ItemGroup>
61+
<ItemGroup>
62+
<ProjectReference Include="..\BuildTT\BuildTT.csproj">
63+
<Project>{f27f0c08-ff2c-40c8-8658-4b8c291d36f3}</Project>
64+
<Name>BuildTT</Name>
65+
</ProjectReference>
66+
</ItemGroup>
67+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
68+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
69+
<PropertyGroup>
70+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
71+
</PropertyGroup>
72+
<Error Condition="!Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.11.0\build\NUnit.props'))" />
73+
</Target>
74+
</Project>
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
using System.Collections.Generic;
2+
using BuildTT.Application;
3+
using NUnit.Framework;
4+
5+
namespace BuildTT.UnitTests
6+
{
7+
[TestFixture]
8+
public class FileReaderTests
9+
{
10+
[Test]
11+
public void NoUsings()
12+
{
13+
// Arrange
14+
string[] data =
15+
{
16+
"namespace Efrpg.FileManagement",
17+
"{",
18+
" public interface IFileManager",
19+
" {",
20+
" void StartHeader();",
21+
" void Process(bool split = true);",
22+
" void StartNewFile(string name);",
23+
" }",
24+
"}"
25+
};
26+
string[] expected =
27+
{
28+
" public interface IFileManager",
29+
" {",
30+
" void StartHeader();",
31+
" void Process(bool split = true);",
32+
" void StartNewFile(string name);",
33+
" }"
34+
};
35+
var reader = new StringReaderStrategy(data);
36+
var fileReader = new FileReader(reader);
37+
38+
// Act
39+
var result = fileReader.ReadFile(null);
40+
41+
// Assert
42+
Assert.IsTrue(result);
43+
Assert.AreEqual("FileManagement", fileReader.Namespace());
44+
Assert.IsEmpty(fileReader.Usings());
45+
Assert.AreEqual(expected, fileReader.Code());
46+
}
47+
48+
[Test]
49+
public void WithComments()
50+
{
51+
// Arrange
52+
string[] data =
53+
{
54+
"file comment",
55+
"another file comment",
56+
"namespace Efrpg.Simon",
57+
"{",
58+
" // Code comment",
59+
" blah",
60+
"}"
61+
};
62+
string[] expected =
63+
{
64+
"file comment",
65+
"another file comment",
66+
" // Code comment",
67+
" blah"
68+
};
69+
var reader = new StringReaderStrategy(data);
70+
var fileReader = new FileReader(reader);
71+
72+
// Act
73+
var result = fileReader.ReadFile(null);
74+
75+
// Assert
76+
Assert.IsTrue(result);
77+
Assert.AreEqual("Simon", fileReader.Namespace());
78+
Assert.IsEmpty(fileReader.Usings());
79+
Assert.AreEqual(expected, fileReader.Code());
80+
}
81+
82+
[Test]
83+
[TestCase(true)]
84+
[TestCase(false)]
85+
public void WithUsings(bool includeBlanks)
86+
{
87+
// Arrange
88+
var data = new List<string>
89+
{
90+
"using Hello;",
91+
"using World;",
92+
"using Efrpg.Gear;"
93+
};
94+
95+
if (includeBlanks)
96+
data.AddRange(new List<string> { "", "", "", "" });
97+
98+
var expectedCode = new List<string>
99+
{
100+
" public interface IFileManager",
101+
" {",
102+
" void StartHeader();",
103+
" void Process(bool split = true);",
104+
" void StartNewFile(string name);",
105+
" }"
106+
};
107+
108+
data.Add("namespace Efrpg.FileManagement");
109+
data.Add("{");
110+
data.AddRange(expectedCode);
111+
data.Add("}");
112+
113+
if (includeBlanks)
114+
expectedCode.InsertRange(0, new List<string> { "", "", "", "" });
115+
116+
var expectedUsings = new List<string>
117+
{
118+
"Hello",
119+
"World"
120+
};
121+
var reader = new StringReaderStrategy(data.ToArray());
122+
var fileReader = new FileReader(reader);
123+
124+
// Act
125+
var result = fileReader.ReadFile(null);
126+
127+
// Assert
128+
Assert.IsTrue(result);
129+
Assert.AreEqual("FileManagement", fileReader.Namespace());
130+
Assert.AreEqual(expectedUsings, fileReader.Usings());
131+
Assert.AreEqual(expectedCode, fileReader.Code());
132+
}
133+
}
134+
}
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Text;
5+
using BuildTT.Application;
6+
using NUnit.Framework;
7+
8+
namespace BuildTT.UnitTests
9+
{
10+
[TestFixture]
11+
public class FileWriterTests
12+
{
13+
private List<IFileReader> _fileReaders;
14+
15+
[OneTimeSetUp]
16+
public void SetUp()
17+
{
18+
_fileReaders = new List<IFileReader>();
19+
string[] data1 =
20+
{
21+
"using System.Text;",
22+
"using Efrpg.aaa;",
23+
"using System.Text;",
24+
"using System.Text;",
25+
"using System.Text;",
26+
"using System.Text;",
27+
"using Efrpg.bbb.ccc;",
28+
"using System.Fred;",
29+
"namespace Efrpg.FileManagement",
30+
"{",
31+
" void abc()",
32+
" {",
33+
" var Efrpg.a = new Efrpg.blah();",
34+
" var b = new Something(Efrpg.Hello);",
35+
" }",
36+
"}"
37+
};
38+
string[] data2 =
39+
{
40+
"using System.XYZ;",
41+
"using Efrpg.ddd;",
42+
"using System.Crypt;",
43+
"using Efrpg.eee;",
44+
"using System.Text;",
45+
"using System.Text;",
46+
"using System.Text;",
47+
"namespace Efrpg.Generator",
48+
"{",
49+
" void def()",
50+
" {",
51+
" var a = new Efrpg.something();",
52+
" var Efrpg.b = new AnotherThing(Efrpg.World);",
53+
" }",
54+
"}"
55+
};
56+
string[] data3 =
57+
{
58+
"using System.XYZ;",
59+
"",
60+
"namespace Efrpg",
61+
"{",
62+
" public static class AssemblyHelper",
63+
" {",
64+
" // todo",
65+
" }",
66+
"}"
67+
};
68+
var reader1 = new StringReaderStrategy(data1);
69+
var reader2 = new StringReaderStrategy(data2);
70+
var reader3 = new StringReaderStrategy(data3);
71+
_fileReaders.Add(new FileReader(reader1));
72+
_fileReaders.Add(new FileReader(reader2));
73+
_fileReaders.Add(new FileReader(reader3));
74+
}
75+
76+
[Test]
77+
public void NamespaceReplacement()
78+
{
79+
// Arrange
80+
string[] expectedCode =
81+
{
82+
"using System.Crypt;",
83+
"using System.Fred;",
84+
"using System.Text;",
85+
"using System.XYZ;",
86+
" void abc()",
87+
" {",
88+
" var a = new blah();",
89+
" var b = new Something(Hello);",
90+
" }",
91+
" void def()",
92+
" {",
93+
" var a = new something();",
94+
" var b = new AnotherThing(World);",
95+
" }",
96+
"",
97+
" public static class AssemblyHelper",
98+
" {",
99+
" // todo",
100+
" }"
101+
};
102+
103+
// Act
104+
var result = Act(new WriterStrategy());
105+
106+
// Assert
107+
Assert.IsNotNull(result);
108+
foreach (var s in result)
109+
{
110+
Console.WriteLine(s);
111+
}
112+
Assert.AreEqual(expectedCode, result);
113+
}
114+
115+
[Test]
116+
public void TTNamespaceReplacement()
117+
{
118+
// Arrange
119+
string[] expectedCode =
120+
{
121+
"<#@ import namespace=\"System.Crypt\" #>",
122+
"<#@ import namespace=\"System.Fred\" #>",
123+
"<#@ import namespace=\"System.Text\" #>",
124+
"<#@ import namespace=\"System.XYZ\" #>",
125+
" void abc()",
126+
" {",
127+
" var a = new blah();",
128+
" var b = new Something(Hello);",
129+
" }",
130+
" void def()",
131+
" {",
132+
" var a = new something();",
133+
" var b = new AnotherThing(World);",
134+
" }",
135+
"",
136+
" public static class AssemblyHelper",
137+
" {",
138+
" // todo",
139+
" }"
140+
};
141+
142+
// Act
143+
var result = Act(new TTWriterStrategy());
144+
145+
// Assert
146+
Assert.IsNotNull(result);
147+
foreach (var s in result)
148+
{
149+
Console.WriteLine(s);
150+
}
151+
Assert.AreEqual(expectedCode, result);
152+
}
153+
154+
private string[] Act(IWriterStrategy writerStrategy)
155+
{
156+
foreach (var reader in _fileReaders)
157+
{
158+
var readerResult = reader.ReadFile(null);
159+
Assert.IsTrue(readerResult);
160+
}
161+
162+
var sb = new StringBuilder();
163+
using (var sw = new StringWriter(sb))
164+
{
165+
var writer = new FileWriter(sw, writerStrategy, _fileReaders);
166+
writer.WriteUsings();
167+
writer.WriteCode();
168+
sw.Close();
169+
}
170+
171+
return sb
172+
.ToString()
173+
.Trim()
174+
.Replace(Environment.NewLine, "\r")
175+
.Split('\r');
176+
}
177+
}
178+
}

0 commit comments

Comments
 (0)