Skip to content

Commit 5937515

Browse files
committed
Annotations done. :)
1 parent bc05b32 commit 5937515

40 files changed

+1042
-212
lines changed

Umbraco.CodeGen.Tests/CodeGeneratorAcceptanceTests.cs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,52 @@
99

1010
namespace Umbraco.CodeGen.Tests
1111
{
12-
[TestFixture]
13-
public class CodeGeneratorAcceptanceTests
14-
{
15-
[Test]
16-
public void BuildCode_GeneratesCodeForDocumentType()
17-
{
18-
TestBuildCode("SomeDocumentType", "DocumentType");
19-
}
20-
21-
[Test]
22-
public void BuildCode_GeneratesCodeForMediaType()
23-
{
24-
TestBuildCode("SomeMediaType", "MediaType");
25-
}
26-
27-
private static void TestBuildCode(string fileName, string contentTypeName)
28-
{
29-
ContentType contentType;
30-
var expectedOutput = "";
31-
using (var inputReader = File.OpenText(@"..\..\TestFiles\" + fileName + ".xml"))
32-
{
12+
[TestFixture]
13+
public class CodeGeneratorAcceptanceTests
14+
{
15+
[Test]
16+
public void BuildCode_GeneratesCodeForDocumentType()
17+
{
18+
TestBuildCode("SomeDocumentType", "DocumentType");
19+
}
20+
21+
[Test]
22+
public void BuildCode_GeneratesCodeForMediaType()
23+
{
24+
TestBuildCode("SomeMediaType", "MediaType");
25+
}
26+
27+
private static void TestBuildCode(string fileName, string contentTypeName)
28+
{
29+
ContentType contentType;
30+
var expectedOutput = "";
31+
using (var inputReader = File.OpenText(@"..\..\TestFiles\" + fileName + ".xml"))
32+
{
3333
contentType = new ContentTypeSerializer().Deserialize(inputReader);
3434
}
3535
using (var goldReader = File.OpenText(@"..\..\TestFiles\" + fileName + ".cs"))
36-
{
37-
expectedOutput = goldReader.ReadToEnd();
38-
}
36+
{
37+
expectedOutput = goldReader.ReadToEnd();
38+
}
3939

40-
var configuration = new CodeGeneratorConfiguration();
41-
configuration.TypeMappings.Add(new TypeMapping("1413afcb-d19a-4173-8e9a-68288d2a73b8", "Int32"));
42-
var typeConfig = configuration.Get(contentTypeName);
43-
typeConfig.BaseClass = "DocumentTypeBase";
44-
typeConfig.Namespace = "Umbraco.CodeGen.Models";
40+
var configuration = new CodeGeneratorConfiguration();
41+
configuration.TypeMappings.Add(new TypeMapping("1413afcb-d19a-4173-8e9a-68288d2a73b8", "Int32"));
42+
var typeConfig = configuration.Get(contentTypeName);
43+
typeConfig.BaseClass = "Umbraco.Core.Models.TypedModelBase";
44+
typeConfig.Namespace = "Umbraco.CodeGen.Models";
4545

46-
var sb = new StringBuilder();
47-
var writer = new StringWriter(sb);
46+
var sb = new StringBuilder();
47+
var writer = new StringWriter(sb);
4848

49-
var factory = new DefaultCodeGeneratorFactory();
50-
var dataTypeProvider = new TestDataTypeProvider();
51-
var generator = new CodeGenerator(typeConfig, dataTypeProvider, factory);
52-
generator.Generate(contentType, writer);
49+
var factory = new DefaultCodeGeneratorFactory();
50+
var dataTypeProvider = new TestDataTypeProvider();
51+
var generator = new CodeGenerator(typeConfig, dataTypeProvider, factory);
52+
generator.Generate(contentType, writer);
5353

5454
writer.Flush();
5555
Console.WriteLine(sb.ToString());
5656

57-
Assert.AreEqual(expectedOutput, sb.ToString());
58-
}
59-
}
57+
Assert.AreEqual(expectedOutput, sb.ToString());
58+
}
59+
}
6060
}

Umbraco.CodeGen.Tests/CodeParserTests.cs renamed to Umbraco.CodeGen.Tests/CodeParserAcceptanceTests.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,42 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
1+
using System.IO;
42
using System.Linq;
5-
using System.Text;
63
using NUnit.Framework;
74
using Umbraco.CodeGen.Configuration;
85
using Umbraco.CodeGen.Definitions;
6+
using Umbraco.CodeGen.Generators;
97
using Umbraco.CodeGen.Parsers;
108
using Umbraco.CodeGen.Tests.TestHelpers;
119

1210
namespace Umbraco.CodeGen.Tests
1311
{
1412
[TestFixture]
15-
class CodeParserTests
13+
public class CodeParserAcceptanceTests
1614
{
1715
[Test]
1816
public void Parse_ReturnsDocumentType()
1917
{
20-
TestParse("SomeDocumentType", "DocumentType", TestFactory.CreateExpectedDocumentType());
18+
TestParse("SomeDocumentType", "DocumentType", TestFactory.CreateExpectedDocumentType(), new DefaultParserFactory());
2119
}
2220

2321
[Test]
2422
public void Parse_ReturnsMediaType()
2523
{
26-
TestParse("SomeMediaType", "MediaType", TestFactory.CreateExpectedMediaType());
24+
TestParse("SomeMediaType", "MediaType", TestFactory.CreateExpectedMediaType(), new DefaultParserFactory());
2725
}
2826

29-
private static void TestParse<T>(string fileName, string contentTypeName, T expectedContentType)
27+
[Test]
28+
public void Parse_Annotated_ReturnsDocumentType()
29+
{
30+
TestParse("SomeAnnotatedDocumentType", "DocumentType", TestFactory.CreateExpectedDocumentType(), new AnnotatedParserFactory());
31+
}
32+
33+
[Test]
34+
public void Parse_Annotated_ReturnsMediaType()
35+
{
36+
TestParse("SomeAnnotatedMediaType", "MediaType", TestFactory.CreateExpectedMediaType(), new AnnotatedParserFactory());
37+
}
38+
39+
private static void TestParse<T>(string fileName, string contentTypeName, T expectedContentType, ParserFactory factory)
3040
where T : ContentType
3141
{
3242
string code;
@@ -41,7 +51,7 @@ private static void TestParse<T>(string fileName, string contentTypeName, T expe
4151
var parser = new CodeParser(
4252
config,
4353
TestDataTypeProvider.All,
44-
new DefaultParserFactory()
54+
factory
4555
);
4656

4757
var contentType = parser.Parse(new StringReader(code)).SingleOrDefault();

Umbraco.CodeGen.Tests/CodeParserToXmlAcceptanceTests.cs

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,58 @@
1010

1111
namespace Umbraco.CodeGen.Tests
1212
{
13-
[TestFixture]
14-
public class CodeParserToXmlAcceptanceTests
15-
{
16-
[Test]
17-
public void Generate_ReturnsXmlForDocumentType()
18-
{
19-
const string fileName = "SomeDocumentType";
20-
const string contentTypeName = "DocumentType";
21-
22-
TestGeneratedXml(fileName, contentTypeName);
23-
}
24-
25-
[Test]
26-
public void Generate_ReturnsXmlForMediaType()
27-
{
28-
const string fileName = "SomeMediaType";
29-
const string contentTypeName = "MediaType";
30-
31-
TestGeneratedXml(fileName, contentTypeName);
32-
}
33-
34-
private static void TestGeneratedXml(string fileName, string contentTypeName)
35-
{
36-
ContentType contentType;
37-
string expectedOutput;
38-
39-
using (var goldReader = File.OpenText(@"..\..\TestFiles\" + fileName + ".xml"))
40-
{
41-
expectedOutput = goldReader.ReadToEnd();
42-
}
43-
44-
var contentTypeConfig = new CodeGeneratorConfiguration().Get(contentTypeName);
45-
contentTypeConfig.BaseClass = "DocumentTypeBase";
46-
47-
using (var inputReader = File.OpenText(@"..\..\TestFiles\" + fileName + ".cs"))
48-
{
49-
var codeParser = new CodeParser(contentTypeConfig, TestDataTypeProvider.All, new DefaultParserFactory());
50-
contentType = codeParser.Parse(inputReader).Single();
51-
}
52-
53-
var serializer = new ContentTypeSerializer();
54-
var xml = serializer.Serialize(contentType);
13+
[TestFixture]
14+
public class CodeParserToXmlAcceptanceTests
15+
{
16+
[Test]
17+
public void Generate_ReturnsXmlForDocumentType()
18+
{
19+
TestGeneratedXml("SomeDocumentType", "SomeDocumentType", "DocumentType", new DefaultParserFactory());
20+
}
21+
22+
[Test]
23+
public void Generate_ReturnsXmlForMediaType()
24+
{
25+
TestGeneratedXml("SomeMediaType", "SomeMediaType", "MediaType", new DefaultParserFactory());
26+
}
27+
28+
[Test]
29+
public void Generate_Annotated_ReturnsXmlForDocumentType()
30+
{
31+
TestGeneratedXml("SomeAnnotatedDocumentType", "SomeDocumentType", "DocumentType", new AnnotatedParserFactory());
32+
}
33+
34+
[Test]
35+
public void Generate_Annotated_ReturnsXmlForMediaType()
36+
{
37+
TestGeneratedXml("SomeAnnotatedMediaType", "SomeMediaType", "MediaType", new AnnotatedParserFactory());
38+
}
39+
40+
private static void TestGeneratedXml(string classFileName, string xmlFileName, string contentTypeName, ParserFactory factory)
41+
{
42+
ContentType contentType;
43+
string expectedOutput;
44+
45+
using (var goldReader = File.OpenText(@"..\..\TestFiles\" + xmlFileName + ".xml"))
46+
{
47+
expectedOutput = goldReader.ReadToEnd();
48+
}
49+
50+
var contentTypeConfig = new CodeGeneratorConfiguration().Get(contentTypeName);
51+
contentTypeConfig.BaseClass = "Umbraco.Core.Models.TypedModelBase";
52+
53+
using (var inputReader = File.OpenText(@"..\..\TestFiles\" + classFileName + ".cs"))
54+
{
55+
var codeParser = new CodeParser(contentTypeConfig, TestDataTypeProvider.All, factory);
56+
contentType = codeParser.Parse(inputReader).Single();
57+
}
58+
59+
var serializer = new ContentTypeSerializer();
60+
var xml = serializer.Serialize(contentType);
5561

5662
Console.WriteLine(xml);
5763

58-
Assert.AreEqual(expectedOutput, xml);
59-
}
60-
}
64+
Assert.AreEqual(expectedOutput, xml);
65+
}
66+
}
6167
}

Umbraco.CodeGen.Tests/Generators/Annotated/CommonInfoGeneratorTests.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ public class CommonInfoGeneratorTests : AnnotationCodeGeneratorTestBase
1515
private Info info;
1616
private CodeTypeDeclaration type;
1717
private CodeAttributeDeclaration attribute;
18+
private MediaType contentType;
1819

1920
[SetUp]
2021
public void SetUp()
2122
{
2223
Configuration = new CodeGeneratorConfiguration().MediaTypes;
2324
Candidate = type = new CodeTypeDeclaration();
24-
info = new Info {Alias = "anEntity"};
25+
contentType = new MediaType
26+
{
27+
Info = info = new Info {Alias = "anEntity"}
28+
};
2529

2630
attribute = new CodeAttributeDeclaration("MediaType");
2731
type.CustomAttributes.Add(attribute);
@@ -33,7 +37,7 @@ public void SetUp()
3337
[ExpectedException(typeof(InvalidCastException), ExpectedMessage = "Unable to cast object of type 'System.CodeDom.CodeMemberProperty' to type 'System.CodeDom.CodeAttributeDeclaration'.")]
3438
public void Generate_NotCodeAttributeDeclaration_Throws()
3539
{
36-
Generator.Generate(new CodeMemberProperty(), info);;
40+
Generator.Generate(new CodeMemberProperty(), contentType); ;
3741
}
3842

3943
[Test]
@@ -94,7 +98,7 @@ public void Generate_AllowAtRoot_False_OmitsAllowAtRootArgument()
9498

9599
private void Generate()
96100
{
97-
Generator.Generate(attribute, info);
101+
Generator.Generate(attribute, contentType);
98102
}
99103
}
100104
}

Umbraco.CodeGen.Tests/Generators/Annotated/DocumentTypeInfoGeneratorTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ public class DocumentTypeInfoGeneratorTests : AnnotationCodeGeneratorTestBase
1414
private DocumentTypeInfoGenerator generator;
1515
private DocumentTypeInfo info;
1616
private CodeAttributeDeclaration attribute;
17+
private DocumentType documentType;
1718

1819
[SetUp]
1920
public void SetUp()
2021
{
2122
Configuration = new CodeGeneratorConfiguration().MediaTypes;
2223
attribute = new CodeAttributeDeclaration("DocumentType");
2324
generator = new DocumentTypeInfoGenerator(Configuration);
24-
info = new DocumentTypeInfo{ Alias = "aClass" };
25+
documentType = new DocumentType
26+
{
27+
Info = info = new DocumentTypeInfo {Alias = "aClass"}
28+
};
2529
}
2630

2731
[Test]
@@ -90,7 +94,7 @@ public void Generate_AllowedTemplates_AllNullOrEmptyItems_OmitsArgument()
9094

9195
private void Generate()
9296
{
93-
generator.Generate(attribute, info);
97+
generator.Generate(attribute, documentType);
9498
}
9599
}
96100
}

Umbraco.CodeGen.Tests/Generators/ImportsGeneratorTests.cs renamed to Umbraco.CodeGen.Tests/Generators/Annotated/ImportsGeneratorTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
using System.Linq;
55
using System.Text;
66
using NUnit.Framework;
7-
using Umbraco.CodeGen.Definitions;
8-
using Umbraco.CodeGen.Generators;
7+
using Umbraco.CodeGen.Generators.Annotated;
98

10-
namespace Umbraco.CodeGen.Tests.Generators
9+
namespace Umbraco.CodeGen.Tests.Generators.Annotated
1110
{
1211
[TestFixture]
1312
public class ImportsGeneratorTests
@@ -22,8 +21,7 @@ public void Generate_AddsImports()
2221
new[]
2322
{
2423
"System",
25-
"System.ComponentModel",
26-
"System.ComponentModel.DataAnnotations",
24+
"Umbraco.CodeGen.Annotations",
2725
"Umbraco.Core.Models",
2826
"Umbraco.Web"
2927
}.SequenceEqual(

0 commit comments

Comments
 (0)