public void Can_get_super_simple_output() { var csharpCode = @" namespace ExpansionFirstTemplateTests { using System.ComponentModel; using System; #region _xf_MakeFileForEach(Over=asdf) namespace _xf_Class_namespaceName {} #endregion } "; var root = RDom.CSharp.Load(csharpCode); var verify = RDom.CSharp.GetSyntaxNode(root).ToFullString(); Assert.AreEqual(csharpCode, verify); var xfTemplate = ExpansionFirstCSharp.Load(csharpCode); var metadataLoader = new CodeFirstMetadataLoader <CodeFirstSemanticLogGroup>(); CodeFirstSemanticLogGroup metadata = metadataLoader.LoadFromString(logMetadataSource, logAttributeIdentifier); var newRoots = xfTemplate.Run(metadata); var newRDomRoot = newRoots.First() as RDomRoot; var outputSyntax = RDom.CSharp.GetSyntaxNode(newRDomRoot); var output = outputSyntax.ToFullString(); var expected = "\r\nnamespace ExpansionFirstTemplateTests\r\n{\r\n\r\n using System.ComponentModel;\r\n using System;\r\n #region _xf_MakeFileForEach(Over=asdf) \r\n\r\n namespace _xf_Class_namespaceName\r\n {}\r\n #endregion\r\n}\r\n"; Assert.AreEqual(expected, output); }
private void TestCodeFirstClassGroup(string templateFileName) { var xfTemplate = ExpansionFirstCSharp.LoadFromFile(templateFileName); var metadataLoader = new CodeFirstMetadataLoader <CodeFirstClassGroup>(); CodeFirstClassGroup metadata = metadataLoader.LoadFromString(propChangedMetadataSource, propChangedAttributeIdentifier); var newRoots = xfTemplate.Run(metadata); var newRDomRoot = newRoots.First() as RDomRoot; var outputSyntax = RDom.CSharp.GetSyntaxNode(newRDomRoot); var output = outputSyntax.ToFullString(); output = CleanOutput(output); Assert.Inconclusive(); }
public void Can_get_simple_output() { var xfTemplate = ExpansionFirstCSharp.Load(template); var metadataLoader = new CodeFirstMetadataLoader <CodeFirstSemanticLogGroup>(); CodeFirstSemanticLogGroup metadata = metadataLoader.LoadFromString(logMetadataSource, logAttributeIdentifier); var newRoots = xfTemplate.Run(metadata); var newRDomRoot = newRoots.First() as RDomRoot; var outputSyntax = RDom.CSharp.GetSyntaxNode(newRDomRoot); var output = outputSyntax.ToString(); var expected = "using System;\r\nnamespace _xf_class_namespaceName\r\n{\r\n public class _xf_logClass_ClassName\r\n { \r\n public string FirstProperty {get; } }\r\n}"; Assert.AreEqual(expected, output); }
public void DomainGeneration_can_handle_nested_ForEach() { var template = @" namespace ExpansionFirstTemplatesTests.PropertyChangedTemplate { #region [[ _xf_TemplateStart() ]] using System; using System.ComponentModel; #region [[ _xf_ForEach(LoopOver=""Meta.Classes"", VarName=""Class"") ]] namespace _xf_Class_dot_Namespace { public sealed partial class _xf_Class_dot_Name : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; #region [[ _xf_ForEach(LoopOver=""Class.Properties"", VarName=""Property"") ]] // Class name: _xf_Class_dot_Name / _xf_Class_dot_Name_as_CamelCase // Field/Property name: _xf_Property_dot_Name_as_CamelCase/_xf_Property_dot_Name private _xf_Property_dot_PropertyType_dot_Name _xf_Property_dot_Name_as_CamelCase; public _xf_Property_dot_PropertyType_dot_Name _xf_Property_dot_Name { get { return _xf_Property_dot_Name_as_CamelCase; } set { SetProperty(ref _xf_Property_dot_Name_as_CamelCase, value); } } #endregion } } #endregion #endregion }"; var provider = new ServiceProvider(); var xfTemplate = ExpansionFirstCSharp.Load <CodeFirstClassGroup>(template); Assert.IsNotNull(xfTemplate); var metadataLoader = provider.GetMetadataLoader <CodeFirstClassGroup>(); var metadata = metadataLoader.LoadFromString(propChangedMetadataSource, ""); Assert.IsNotNull(metadata); var newRoots = xfTemplate.Run(metadata); var newRDomRoot = newRoots.First() as RDomRoot; var outputSyntax = RDom.CSharp.GetSyntaxNode(newRDomRoot); var output = outputSyntax.ToString(); var expected = "using System;\r\n using System.ComponentModel;\r\n\r\n namespace ExpansionFirstExample\r\n {\r\n public sealed class Customer : INotifyPropertyChanged\r\n {\r\n public event PropertyChangedEventHandler PropertyChanged;\r\n\r\n // Class name: Customer / customer\r\n // Field/Property name: firstName/FirstName \r\n private String firstName;\r\n public String FirstName\r\n {\r\n get { return firstName; }\r\n set { SetProperty(ref firstName, value); }\r\n }\r\n\r\n // Class name: Customer / customer\r\n // Field/Property name: lastName/LastName \r\n private String lastName;\r\n public String LastName\r\n {\r\n get { return lastName; }\r\n set { SetProperty(ref lastName, value); }\r\n }\r\n\r\n // Class name: Customer / customer\r\n // Field/Property name: id/Id \r\n private Int32 id;\r\n public Int32 Id\r\n {\r\n get { return id; }\r\n set { SetProperty(ref id, value); }\r\n }\r\n\r\n // Class name: Customer / customer\r\n // Field/Property name: birthDate/BirthDate \r\n private DateTime birthDate;\r\n public DateTime BirthDate\r\n {\r\n get { return birthDate; }\r\n set { SetProperty(ref birthDate, value); }\r\n }\r\n }\r\n }\r\n"; Assert.AreEqual(expected, output); }
public void DomainGeneration_creates_correct_output_for_NotifyPropertyChanged() { var provider = new ServiceProvider(); var template = File.ReadAllText(propertyChangedTemplateName); var xfTemplate = ExpansionFirstCSharp.Load <CodeFirstClassGroup>(template); Assert.IsNotNull(xfTemplate); var metadataLoader = provider.GetMetadataLoader <CodeFirstClassGroup>(); var metadata = metadataLoader.LoadFromString(propChangedMetadataSource, ""); var newRoots = xfTemplate.Run(metadata); var newRDomRoot = newRoots.First() as RDomRoot; var outputSyntax = RDom.CSharp.GetSyntaxNode(newRDomRoot); var output = outputSyntax.ToString(); var expected = "using System;\r\n using System.ComponentModel;\r\n\r\n namespace ExpansionFirstExample\r\n {\r\n public class Customer : INotifyPropertyChanged\r\n {\r\n public event PropertyChangedEventHandler PropertyChanged;\r\n\r\n private String firstName;\r\n public String FirstName\r\n {\r\n get { return firstName; }\r\n set { SetProperty(ref firstName, value); }\r\n }\r\n\r\n private String lastName;\r\n public String LastName\r\n {\r\n get { return lastName; }\r\n set { SetProperty(ref lastName, value); }\r\n }\r\n\r\n private Int32 id;\r\n public Int32 Id\r\n {\r\n get { return id; }\r\n set { SetProperty(ref id, value); }\r\n }\r\n\r\n private DateTime birthDate;\r\n public DateTime BirthDate\r\n {\r\n get { return birthDate; }\r\n set { SetProperty(ref birthDate, value); }\r\n }\r\n }\r\n }\r\n"; Assert.AreEqual(expected, output); }
public void DomainGeneration_can_get_simple_output() { var provider = new ServiceProvider(); var template = File.ReadAllText(superSimpleTemplateName); var xfTemplate = ExpansionFirstCSharp.Load <CodeFirstClassGroup>(template); Assert.IsNotNull(xfTemplate); var metadataLoader = provider.GetMetadataLoader <CodeFirstClassGroup>(); var metadata = metadataLoader.LoadFromString(propChangedMetadataSource, ""); Assert.IsNotNull(metadata); var newRoots = xfTemplate.Run(metadata); var newRDomRoot = newRoots.First() as RDomRoot; var outputSyntax = RDom.CSharp.GetSyntaxNode(newRDomRoot); var output = outputSyntax.ToString(); var expected = "namespace ExpansionFirstTemplatesTests.SuperSimpleClassTemplate\r\n{\r\n namespace ExpansionFirstExample\r\n {\r\n public sealed class Customer\r\n { }\r\n }\r\n}\r\n"; Assert.AreEqual(expected, output); }
public void DomainGeneration_excludes_code_outside_start_block() { var template = @" namespace ExpansionFirstTemplatesTests.PropertyChangedTemplate { #region [[ _xf_TemplateStart() ]] using System; using System.ComponentModel; #region [[ _xf_ForEach(LoopOver=""Meta.Classes"", VarName=""Class"") ]] namespace _xf_Class_dot_Namespace { public sealed partial class _xf_Class_dot_Name { } } #endregion #endregion }"; var provider = new ServiceProvider(); var xfTemplate = ExpansionFirstCSharp.Load <CodeFirstClassGroup>(template); Assert.IsNotNull(xfTemplate); var metadataLoader = provider.GetMetadataLoader <CodeFirstClassGroup>(); var metadata = metadataLoader.LoadFromString(propChangedMetadataSource, ""); Assert.IsNotNull(metadata); var newRoots = xfTemplate.Run(metadata); var newRDomRoot = newRoots.First() as RDomRoot; var outputSyntax = RDom.CSharp.GetSyntaxNode(newRDomRoot); var output = outputSyntax.ToString(); var expected = "using System;\r\n using System.ComponentModel;\r\n\r\n namespace ExpansionFirstExample\r\n {\r\n public sealed class Customer\r\n { }\r\n }\r\n"; Assert.AreEqual(expected, output); }