Example #1
0
        public void ResolveToProviderIfNoWorkItem()
        {
            MockSPI        spi = new MockSPI();
            MockSPProvider sp  = new MockSPProvider(spi);
            MockWorkspace  ws  = new MockWorkspace();

            ws.Show(sp);

            Assert.AreSame(spi, ws.LastSPI);
        }
Example #2
0
        public void GenerateCodeForSmartPartInfoCompiles()
        {
            DesignerSerializerAttribute attr = (DesignerSerializerAttribute)Attribute.GetCustomAttribute(
                typeof(SmartPartInfo), typeof(DesignerSerializerAttribute));
            CodeDomSerializer serializer = (CodeDomSerializer)Activator.CreateInstance(Type.GetType(attr.SerializerTypeName));

            UserControl smartPart = new UserControl();

            Container     container = new Container();
            SmartPartInfo info1     = new SmartPartInfo("foo", "");

            container.Add(info1, "info1");
            MockSPI info2 = new MockSPI("bar", "");

            container.Add(info2, "info2");

            MockManager manager = new MockManager(container.Components);

            manager.Services.Add(typeof(IDesignerHost), new MockDesignerHost(smartPart, container));
            manager.Services.Add(typeof(IReferenceService), new MockReferenceService(container.Components));
            manager.Services.Add(typeof(IContainer), container);
            manager.Services.Add(typeof(IDesignerSerializationManager), manager);

            CodeTypeDeclaration declaration = new CodeTypeDeclaration("UserControl1");
            CodeMemberMethod    init        = new CodeMemberMethod();

            init.Name = "InitializeComponent";
            declaration.Members.Add(init);
            // Add empty fields for both SPIs.
            declaration.Members.Add(new CodeMemberField(typeof(ISmartPartInfo), "info1"));
            declaration.Members.Add(new CodeMemberField(typeof(ISmartPartInfo), "info2"));

            manager.Services.Add(typeof(CodeTypeDeclaration), declaration);

            serializer.Serialize(manager, info1);
            serializer.Serialize(manager, info2);

            StringWriter sw = new StringWriter();

            new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromType(
                declaration, sw, new CodeGeneratorOptions());

            sw.Flush();

            //Console.WriteLine(sw.ToString());

            CompilerResults results = new Microsoft.CSharp.CSharpCodeProvider().CompileAssemblyFromSource(
                new CompilerParameters(new string[] {
                "System.dll",
                new Uri(typeof(SmartPartInfo).Assembly.CodeBase).LocalPath
            }),
                sw.ToString());

            Assert.IsFalse(results.Errors.HasErrors, ErrorsToString(results.Errors));
        }
        public void CanRetrieveSpecificSPI()
        {
            MockSPI spi = new MockSPI();

            provider.Items.Add(new SmartPartInfo());
            provider.Items.Add(spi);

            MockSPI result = (MockSPI)provider.GetSmartPartInfo(typeof(MockSPI));

            Assert.AreSame(spi, result);
        }
Example #4
0
        public void ResolveToProviderIfGenericSPIRegistered()
        {
            MockSPI        spprovider = new MockSPI();
            SmartPartInfo  spworkitem = new SmartPartInfo();
            MockSPProvider sp         = new MockSPProvider(spprovider);

            workItem.RegisterSmartPartInfo(sp, spworkitem);

            workspace.Show(sp);

            Assert.AreSame(spprovider, workspace.LastSPI);
        }
Example #5
0
        public void ResolveToWorkItemIfConcreteSPIRegistered()
        {
            MockSPI        spprovider = new MockSPI();
            MockSPI        spworkitem = new MockSPI();
            MockSPProvider sp         = new MockSPProvider(spprovider);

            workItem.RegisterSmartPartInfo(sp, spworkitem);

            workspace.Show(sp);

            Assert.AreSame(spworkitem, workspace.LastSPI);
        }
Example #6
0
        public void SmartPartShowInChildWorkItemParentWorkspaceUsesChildSmartPartInfo()
        {
            WorkItem workItemA = new TestableRootWorkItem();
            WorkItem workItemB = workItemA.WorkItems.AddNew <WorkItem>();
            MockSP   sp        = new MockSP();
            MockSPI  spi       = new MockSPI("Title", "Description");

            MockWorkspace workspace = workItemA.Workspaces.AddNew <MockWorkspace>();

            workItemB.RegisterSmartPartInfo(sp, spi);

            workspace.Show(sp);

            Assert.AreSame(spi, workspace.LastSPI);
        }
Example #7
0
        public void SmartPartInfoIsRemovedWhenChildWorkItemIsDisposed()
        {
            WorkItem workItemA = new TestableRootWorkItem();
            WorkItem workItemB = workItemA.WorkItems.AddNew <WorkItem>();
            MockSP   sp        = new MockSP();
            MockSPI  spi       = new MockSPI("Title", "Description");

            MockWorkspace workspace = workItemA.Workspaces.AddNew <MockWorkspace>();

            workItemB.RegisterSmartPartInfo(sp, spi);

            workItemB.Dispose();

            workspace.Show(sp);

            Assert.IsFalse(spi == workspace.LastSPI);
        }