public void PropertyTypeMatchesTemplatePropertyTypeIfSpecified()
        {
            string                       path                = Directory.GetCurrentDirectory();
            MockTemplateHost             mockHost            = new MockTemplateHost(path);
            CompilerErrorCollection      errors              = new CompilerErrorCollection();
            CodeDomProvider              languageProvider    = new CSharpCodeProvider();
            string                       directiveName       = "property";
            IDictionary <string, string> directiveAttributes = new Dictionary <string, string>();

            PropertyData propertyData = new PropertyData("TheProperty", typeof(string));

            mockHost.Arguments.Add("TheProperty", propertyData);
            directiveAttributes.Add("name", "TheProperty");
            directiveAttributes.Add("type", typeof(object).FullName);

            PropertiesDirectiveProcessor pdp = new PropertiesDirectiveProcessor();

            pdp.Initialize(mockHost);
            pdp.StartProcessingRun(languageProvider, null, new CompilerErrorCollection());;
            pdp.ProcessDirective(directiveName, directiveAttributes);
            pdp.FinishProcessingRun();

            string result = pdp.GetClassCodeForProcessingRun();

            Assert.IsTrue(result.Contains("public object TheProperty"));
        }
        public void CanProcessEditorAttribute()
        {
            string                       path                = Directory.GetCurrentDirectory();
            MockTemplateHost             mockHost            = new MockTemplateHost(path);
            CompilerErrorCollection      errors              = new CompilerErrorCollection();
            CodeDomProvider              languageProvider    = new CSharpCodeProvider();
            string                       directiveName       = "property";
            IDictionary <string, string> directiveAttributes = new Dictionary <string, string>();

            PropertyData propertyData = new PropertyData("TheProperty", typeof(string));

            mockHost.Arguments.Add("TheProperty", propertyData);
            directiveAttributes.Add("name", "TheProperty");
            directiveAttributes.Add("editor", typeof(UITypeEditor).FullName);

            PropertiesDirectiveProcessor pdp = new PropertiesDirectiveProcessor();

            pdp.Initialize(mockHost);
            pdp.StartProcessingRun(languageProvider, null, new CompilerErrorCollection());;
            pdp.ProcessDirective(directiveName, directiveAttributes);
            pdp.FinishProcessingRun();

            string result = pdp.GetClassCodeForProcessingRun();

            Assert.IsTrue(result.Contains("[System.ComponentModel.EditorAttribute(typeof(System.Drawing.Design.UITypeEditor))]"));
        }
        public void GetClassCodeForProcessingRunWithSeveralProcessDirective()
        {
            // fields
            string                       path             = Directory.GetCurrentDirectory();
            MockTemplateHost             mockHost         = new MockTemplateHost(path);
            CompilerErrorCollection      errors           = new CompilerErrorCollection();
            CodeDomProvider              languageProvider = new CSharpCodeProvider();
            string                       directiveName    = "property";
            IDictionary <string, string> argumentsClient  = new Dictionary <string, string>(0);
            IDictionary <string, string> argumentsAmount  = new Dictionary <string, string>(0);

            PropertyData dataClient = new PropertyData("ClientName", typeof(string));

            mockHost.Arguments.Add("Client", dataClient);
            argumentsClient.Add("name", "Client");

            PropertyData dataAmount = new PropertyData(1200.33, typeof(decimal));

            mockHost.Arguments.Add("Amount", dataAmount);
            argumentsAmount.Add("name", "Amount");

            // Create the PropertiesDirectiveProcessor
            PropertiesDirectiveProcessor pdp = new PropertiesDirectiveProcessor();

            pdp.Initialize(mockHost);
            pdp.StartProcessingRun(languageProvider, null, new CompilerErrorCollection());;
            pdp.ProcessDirective(directiveName, argumentsClient);
            pdp.ProcessDirective(directiveName, argumentsAmount);
            pdp.FinishProcessingRun();

            string result         = pdp.GetClassCodeForProcessingRun();
            string expectedResult = @"
[Microsoft.Practices.RecipeFramework.VisualStudio.Library.Templates.TemplatePropertyAttribute()]
public string Client
{
    get
    {
        return ((string)(Microsoft.Practices.RecipeFramework.VisualStudio.Library.Templates.TemplateHost.CurrentHost.Arguments[""Client""].Value));
    }
}

[Microsoft.Practices.RecipeFramework.VisualStudio.Library.Templates.TemplatePropertyAttribute()]
public decimal Amount
{
    get
    {
        return ((decimal)(Microsoft.Practices.RecipeFramework.VisualStudio.Library.Templates.TemplateHost.CurrentHost.Arguments[""Amount""].Value));
    }
}
";

            Assert.AreEqual(expectedResult, result);
        }
        public void GetClassCodeForProcessingRun()
        {
            // fields
            string                  path             = Directory.GetCurrentDirectory();
            CodeDomProvider         languageProvider = new CSharpCodeProvider();
            MockTemplateHost        mockHost         = new MockTemplateHost(path);
            CompilerErrorCollection errors           = new CompilerErrorCollection();

            // Create the PropertiesDirectiveProcessor
            PropertiesDirectiveProcessor pdp = new PropertiesDirectiveProcessor();

            pdp.Initialize(mockHost);
            pdp.StartProcessingRun(languageProvider, null, new CompilerErrorCollection());
            pdp.FinishProcessingRun();

            string result = pdp.GetClassCodeForProcessingRun();

            Assert.IsTrue(result == "");
        }
        public void GetClassCodeForProcessingRunWithWrongDirectiveName()
        {
            // fields
            string                       path             = Directory.GetCurrentDirectory();
            CodeDomProvider              languageProvider = new CSharpCodeProvider();
            MockTemplateHost             mockHost         = new MockTemplateHost(path);
            CompilerErrorCollection      errors           = new CompilerErrorCollection();
            string                       directiveName    = "WrongDirectiveName";
            IDictionary <string, string> arguments        = new Dictionary <string, string>(0);

            // Create the PropertiesDirectiveProcessor
            PropertiesDirectiveProcessor pdp = new PropertiesDirectiveProcessor();

            pdp.Initialize(mockHost);
            pdp.StartProcessingRun(languageProvider, null, new CompilerErrorCollection());
            pdp.ProcessDirective(directiveName, arguments);
            pdp.FinishProcessingRun();

            string result = pdp.GetClassCodeForProcessingRun();

            Assert.AreEqual("", result);
        }