Example #1
0
        public void TestInterfaceMethodsOnProperty()
        {
            UIThreadInvoker.Invoke((ThreadInvoker) delegate()
            {
                //Get the global service provider and the dte
                IServiceProvider sp = VsIdeTestHostContext.ServiceProvider;
                DTE dte             = (DTE)sp.GetService(typeof(DTE));

                string destination = Path.Combine(TestContext.TestDir, TestContext.TestName);
                Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true);

                OAProject automation = Utilities.FindExtObject(sp, Utilities.NestedProjectGuid, TestContext.TestName) as OAProject;
                Assert.IsNotNull(automation, "Failed to create a project using automation");

                ProjectNode projectNode = automation.Project;

                // Get Project Property object
                EnvDTE.Property property = automation.Properties.Item("RootNamespace");
                Assert.IsNotNull(property, "Could not retrieve valid RootNamespace property");
                Assert.IsFalse(property is OANullProperty, "Could not retrieve valid RootNamespace property");
                object retValue = property.Application;
                Assert.IsNull(retValue);

                Assert.IsTrue((string)property.Value == "Application", "Failed to retrieve the Value property.");
                property.Value = "Test1";
                Assert.AreEqual(property.Value, "Test1");


                // Get Collection object from property object
                EnvDTE.Properties properties = property.Collection;
                Assert.IsNotNull(properties, "Collection property failed to retrieve an object");

                // Get the DTE
                retValue = property.DTE;
                Assert.IsNotNull(retValue);

                // Get the Indexed value
                retValue = property.get_IndexedValue(1, 2, 3, 4);
                Assert.IsNull(retValue);

                property.let_Value(1);
                Assert.AreEqual(property.Value, "1");

                // Check the name.
                string name = property.Name;
                Assert.IsNotNull(name);
                Assert.IsTrue(name == "RootNamespace", "RootNamespace property was not set correctly");

                short numIndeces = property.NumIndices;
                //Currently it gives back 0
                //It must be Assertd when the method changes
                Assert.IsTrue(numIndeces == 0);

                // Assert the Object property
                retValue = property.Object;
                Assert.AreEqual(retValue, property.Value);
                property.Object = "test1";
                retValue        = property.Object;
                Assert.AreEqual(retValue, "test1");

                // Test the parent property
                EnvDTE.Properties parent = property.Parent;
                Assert.IsTrue(parent is OAProperties, "Parent property failed to return the parent of a property");

                //It does nothing currently. Cannot be Assertd.
                property.set_IndexedValue(1, 2, 3, 4, 5);

                // Try a non string value on the Value.
                ArrayList list = new ArrayList();
                property.Value = list;
                retValue       = property.Value;
                Assert.AreEqual(retValue, list.ToString());

                // Test the iterators for enumeration.
                // We are interested to see that we advance with the iteration.
                bool[] found = new bool[2];

                foreach (EnvDTE.Property aProperty in automation.Properties)
                {
                    if (aProperty.Name == "RootNamespace")
                    {
                        found[0] = true;
                    }
                    else if (aProperty.Name == "AssemblyName")
                    {
                        found[1] = true;
                    }
                }

                foreach (bool foundValue in found)
                {
                    Assert.IsTrue(foundValue, "The iterator on property collection has not been implemented correctly");
                }
            });
        }