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 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 TemplateHostHelperConstructorWithNullArguments() { // fields MockTemplateHost host = null; // Create the ServiceContainer TemplateHostInitializer hostHelper = new TemplateHostInitializer(host); }
public void TemplateHostHelperWithValidArguments() { // fields string path = Directory.GetCurrentDirectory(); MockTemplateHost host = new MockTemplateHost(path); // Create the ServiceContainer TemplateHostInitializer hostHelper = new TemplateHostInitializer(host); }
public void InitializeHostIsNull() { // fields MockTemplateHost mockHost = null; CompilerErrorCollection errors = new CompilerErrorCollection(); // Create the PropertiesDirectiveProcessor PropertiesDirectiveProcessor pdp = new PropertiesDirectiveProcessor(); pdp.Initialize(mockHost); }
public void Initialize() { // fields string path = Directory.GetCurrentDirectory(); MockTemplateHost mockHost = new MockTemplateHost(path); CompilerErrorCollection errors = new CompilerErrorCollection(); // Create the PropertiesDirectiveProcessor PropertiesDirectiveProcessor pdp = new PropertiesDirectiveProcessor(); pdp.Initialize(mockHost); }
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 TemplateHostHelperGetValueFromStaticObject() { // fields string path = Directory.GetCurrentDirectory(); MockTemplateHost host = new MockTemplateHost(path); host.Arguments.Add("TestKey", new PropertyData("TestValue", typeof(string))); // Create the ServiceContainer TemplateHostInitializer hostHelper = new TemplateHostInitializer(host); string result = (string)MockTemplateHost.CurrentHost.Arguments["TestKey"].Value; Assert.AreEqual("TestValue", result); }
public void IsDirectiveSupported() { // fields string path = Directory.GetCurrentDirectory(); string directiveName = "property"; MockTemplateHost mockHost = new MockTemplateHost(path); CompilerErrorCollection errors = new CompilerErrorCollection(); // Create the PropertiesDirectiveProcessor PropertiesDirectiveProcessor pdp = new PropertiesDirectiveProcessor(); pdp.Initialize(mockHost); Assert.IsTrue(pdp.IsDirectiveSupported(directiveName)); }
public void IsDirectiveSupportedWithNull() { // fields string path = Directory.GetCurrentDirectory(); string directiveName = null; MockTemplateHost mockHost = new MockTemplateHost(path); CompilerErrorCollection errors = new CompilerErrorCollection(); // Create the PropertiesDirectiveProcessor PropertiesDirectiveProcessor pdp = new PropertiesDirectiveProcessor(); pdp.Initialize(mockHost); bool result = pdp.IsDirectiveSupported(directiveName); }
public void TemplateHostHelperWithCustomObject() { // fields string path = Directory.GetCurrentDirectory(); MockTemplateHost host = new MockTemplateHost(path); MockTemplateHostHelperValue value = new MockTemplateHostHelperValue(); host.Arguments.Add("TestKey", new PropertyData(value, typeof(MockTemplateHostHelperValue))); // Create the ServiceContainer TemplateHostInitializer hostHelper = new TemplateHostInitializer(host); MockTemplateHostHelperValue result = (MockTemplateHostHelperValue)MockTemplateHost.CurrentHost.Arguments["TestKey"].Value; Assert.AreEqual("MockTemplateHostHelperValueName", result.Name); }
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); }
public void GetClassCodeForProcessingRunWithoutStartProcessing() { // fields string path = Directory.GetCurrentDirectory(); MockTemplateHost mockHost = new MockTemplateHost(path); CompilerErrorCollection errors = new CompilerErrorCollection(); // Create the PropertiesDirectiveProcessor PropertiesDirectiveProcessor pdp = new PropertiesDirectiveProcessor(); pdp.Initialize(mockHost); try { string result = pdp.GetClassCodeForProcessingRun(); } catch (InvalidOperationException) { return; } Assert.Fail("The method 'GetClassCodeForProcessingRun' do not throw an exception."); }
public void ProcessDirective() { // fields string path = Directory.GetCurrentDirectory(); string directiveName = "property"; MockTemplateHost mockHost = new MockTemplateHost(path); CompilerErrorCollection errors = new CompilerErrorCollection(); CodeDomProvider languageProvider = new CSharpCodeProvider(); IDictionary <string, string> arguments = new Dictionary <string, string>(0); PropertyData propertyData = new PropertyData("ClientName", typeof(string)); mockHost.Arguments.Add("Client", propertyData); arguments.Add("name", "Client"); // Create the PropertiesDirectiveProcessor PropertiesDirectiveProcessor pdp = new PropertiesDirectiveProcessor(); pdp.Initialize(mockHost); pdp.StartProcessingRun(languageProvider, null, new CompilerErrorCollection()); pdp.ProcessDirective(directiveName, arguments); }