public void FullPath_ValidPath_ShouldBeFine()
        {
            using (TemporaryDirectory directory = new TemporaryDirectory())
            {
                var expectations = new ExpectationCollection <string, string>();

                // Ensure the path is always normalized properly.
                string rootTempPath = Path.GetFullPath(FileIO.GetRootTemporaryDirectory()).ToUpperInvariant();

                // Note: These relative paths work properly because the unit test temporary directories are always
                // created as a subfolder off the AppDomain.CurrentDomain.BaseDirectory.
                expectations.Add(".", Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ".")).ToUpperInvariant());
                expectations.Add(FileIO.RootTemporaryDirectoryName, rootTempPath);
                expectations.Add(FileIO.GetRootTemporaryDirectory(), rootTempPath);
                expectations.Add(directory.DirectoryPath, Path.GetFullPath(directory.DirectoryPath).ToUpperInvariant());

                foreach (var e in expectations)
                {
                    var cat   = CreateDirectoryCatalog(e.Input, DirectoryCatalogTests.NonExistentSearchPattern);
                    var proxy = new DirectoryCatalog.DirectoryCatalogDebuggerProxy(cat);

                    Assert.AreEqual(e.Output, proxy.FullPath);
                }
            }
        }
Esempio n. 2
0
        public void TryParseConstraint_MetadataContainsKeyAsConstraintArgument_CanParse()
        {
            var expectations = new ExpectationCollection <Expression <Func <ExportDefinition, bool> >, Dictionary <string, Type> >();

            expectations.Add(
                item => typeof(string).IsInstanceOfType(item.Metadata[""]),
                new Dictionary <string, Type> {
                { "", typeof(string) }
            });
            expectations.Add(
                item => typeof(string).IsInstanceOfType(item.Metadata["value"]),
                new Dictionary <string, Type> {
                { "value", typeof(string) }
            });
            expectations.Add(
                item => typeof(string).IsInstanceOfType(item.Metadata["Value"]),
                new Dictionary <string, Type> {
                { "Value", typeof(string) }
            });
            expectations.Add(
                item => typeof(string).IsInstanceOfType(item.Metadata["Value"]) && typeof(int).IsInstanceOfType(item.Metadata["value"]),
                new Dictionary <string, Type> {
                { "Value", typeof(string) }, { "value", typeof(int) }
            });
            expectations.Add(
                item => typeof(string).IsInstanceOfType(item.Metadata["Value"]) && typeof(int).IsInstanceOfType(item.Metadata["value"]) && typeof(object).IsInstanceOfType(item.Metadata["Metadata"]),
                new Dictionary <string, Type> {
                { "Value", typeof(string) }, { "value", typeof(int) }, { "Metadata", typeof(object) }
            });

            foreach (var e in expectations)
            {
                AssertCanParse(e.Input, (string)null, e.Output);
            }
        }
Esempio n. 3
0
        public void TryParseConstraint_ContractNameOperatorEqualsAndMetadataContainsKeyAsConstraintArgumen_CanParse()
        {
            var expectations = new ExpectationCollection <Expression <Func <ExportDefinition, bool> >, KeyValuePair <string, Type>[]>();

            expectations.Add(
                item => item.ContractName == "ContractName" && typeof(string).IsInstanceOfType(item.Metadata[""]),
                new KeyValuePair <string, Type>[] { new KeyValuePair <string, Type>("", typeof(string)) });
            expectations.Add(
                item => item.ContractName == "ContractName" && typeof(string).IsInstanceOfType(item.Metadata["value"]),
                new KeyValuePair <string, Type>[] { new KeyValuePair <string, Type>("value", typeof(string)) });
            expectations.Add(
                item => item.ContractName == "ContractName" && typeof(string).IsInstanceOfType(item.Metadata["Value"]),
                new KeyValuePair <string, Type>[] { new KeyValuePair <string, Type>("Value", typeof(string)) });
            expectations.Add(
                item => item.ContractName == "ContractName" && typeof(string).IsInstanceOfType(item.Metadata["Value"]) && typeof(int).IsInstanceOfType(item.Metadata["value"]),
                new KeyValuePair <string, Type>[] { new KeyValuePair <string, Type>("Value", typeof(string)), new KeyValuePair <string, Type>("value", typeof(int)) });
            expectations.Add(
                item => item.ContractName == "ContractName" && typeof(string).IsInstanceOfType(item.Metadata["Value"]) && typeof(int).IsInstanceOfType(item.Metadata["value"]) && typeof(object).IsInstanceOfType(item.Metadata["Metadata"]),
                new KeyValuePair <string, Type>[] { new KeyValuePair <string, Type>("Value", typeof(string)), new KeyValuePair <string, Type>("value", typeof(int)), new KeyValuePair <string, Type>("Metadata", typeof(object)) });

            foreach (var e in expectations)
            {
                AssertCanParse(e.Input, "ContractName", e.Output);
            }
        }
        public void Message_ShouldIncludeElementGraph()
        {
            var expectations       = new ExpectationCollection <CompositionError, string>();
            CompositionError error = null;

            error = CreateCompositionErrorWithElementChain(1);
            expectations.Add(error, GetElementGraphString(error));

            error = CreateCompositionErrorWithElementChain(2);
            expectations.Add(error, GetElementGraphString(error));

            error = CreateCompositionErrorWithElementChain(3);
            expectations.Add(error, GetElementGraphString(error));

            error = CreateCompositionErrorWithElementChain(10);
            expectations.Add(error, GetElementGraphString(error));

            foreach (var e in expectations)
            {
                var exception = CreateCompositionException(new CompositionError[] { e.Input });

                string result   = exception.ToString();
                string expected = FixMessage(e.Output);
                AssertExtensions.Contains(result, expected);
            }
        }
Esempio n. 5
0
        public void ToString_ValueAsConstraintArgument_ShouldReturnConstraintProperty()
        {
            var expectations = new ExpectationCollection <Expression <Func <ExportDefinition, bool> >, string>();

            expectations.Add(d => d.ContractName == "ContractName", @"d.ContractName ==? ""ContractName""");
            expectations.Add(d => d.ContractName.Equals("ContractName"), @"d.ContractName.Equals\(""ContractName""\)");
            expectations.Add(d => (string)d.Metadata["Name"] == "Value", @"Convert\(d.Metadata.get_Item\(""Name""\)\) ==? ""Value""");
            expectations.Add(d => true, "True");

            foreach (var e in expectations)
            {
                var item = new ImportDefinition(e.Input, "", ImportCardinality.ExactlyOne, false, false);

                Assert.Matches(e.Output, item.ToString());
            }
        }
Esempio n. 6
0
        public void ToString_DerivedImportDefinition_ShouldReturnOverriddenConstraintProperty()
        {
            var expectations = new ExpectationCollection <Expression <Func <ExportDefinition, bool> >, string>();

            expectations.Add(d => d.ContractName == "ContractName", @"d.ContractName ==? ""ContractName""");
            expectations.Add(d => d.ContractName.Equals("ContractName"), @"d.ContractName.Equals\(""ContractName""\)");
            expectations.Add(d => (string)d.Metadata["Name"] == "Value", @"Convert\(d.Metadata.get_Item\(""Name""\)\) ==? ""Value""");
            expectations.Add(d => true, "True");

            foreach (var e in expectations)
            {
                var item = new DerivedImportDefinition(e.Input);

                Assert.Matches(e.Output, item.ToString());
            }
        }
Esempio n. 7
0
        public void Path_ValidPath_ShouldBeFine()
        {
            var expectations = new ExpectationCollection <string, string>();

            expectations.Add(".", ".");
            expectations.Add(TemporaryFileCopier.RootTemporaryDirectoryName, TemporaryFileCopier.RootTemporaryDirectoryName);
            expectations.Add(TemporaryFileCopier.GetRootTemporaryDirectory(), TemporaryFileCopier.GetRootTemporaryDirectory());
            expectations.Add(TemporaryFileCopier.GetTemporaryDirectory(), TemporaryFileCopier.GetTemporaryDirectory());

            foreach (var e in expectations)
            {
                var cat = CreateDirectoryCatalog(e.Input, NonExistentSearchPattern);

                Assert.Equal(e.Output, cat.Path);
            }
        }
Esempio n. 8
0
        [ActiveIssue("https://github.com/dotnet/runtime/issues/24240", TestPlatforms.AnyUnix)] // System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
        public void Constuctor_ValueAsCatalogArgument_ShouldSetSearchPatternProperty()
        {
            string directoryPath = GetTemporaryDirectory();
            var    expectations  = new ExpectationCollection <string, string>();

            expectations.Add("*.*", "*.*");
            expectations.Add("*.doc", "*.doc");
            expectations.Add("*.exe", "*.exe");
            expectations.Add("*.dll", "*.dll");

            foreach (var e in expectations)
            {
                var catalog = CreateDirectoryCatalog(directoryPath, e.Input);
                var proxy   = new DirectoryCatalog.DirectoryCatalogDebuggerProxy(catalog);

                Assert.Equal(e.Output, proxy.SearchPattern);
            }
        }
Esempio n. 9
0
        public void Path_ValidPath_ShouldBeFine()
        {
            using (var directory = CreateTemporaryDirectory())
            {
                var expectations = new ExpectationCollection <string, string>();

                expectations.Add(".", ".");
                expectations.Add(FileIO.RootTemporaryDirectoryName, FileIO.RootTemporaryDirectoryName);
                expectations.Add(FileIO.GetRootTemporaryDirectory(), FileIO.GetRootTemporaryDirectory());
                expectations.Add(directory.DirectoryPath, directory.DirectoryPath);

                foreach (var e in expectations)
                {
                    var cat = CreateDirectoryCatalog(e.Input, NonExistentSearchPattern);

                    Assert.AreEqual(e.Output, cat.Path);
                }
            }
        }
Esempio n. 10
0
        public void Constructor2_ContractName_ShouldSetAppropriately()
        {
            var expectations = new ExpectationCollection <string, string>();

            expectations.Add(null, string.Empty);
            expectations.Add(string.Empty, string.Empty);
            expectations.Add("Contract", "Contract");

            string cn = AttributedModelServices.GetContractName(typeof(ImportDefinitionTests));

            expectations.Add(cn, cn);

            foreach (var e in expectations)
            {
                var definition = new ImportDefinition(d => true, e.Input, ImportCardinality.ExactlyOne, false, false);

                Assert.Equal(e.Output, definition.ContractName);
            }
        }
        public void Constuctor_ValueAsCatalogArgument_ShouldSetSearchPatternProperty()
        {
            using (TemporaryDirectory directory = new TemporaryDirectory())
            {
                var expectations = new ExpectationCollection<string, string>();

                expectations.Add("*.*", "*.*");
                expectations.Add("*.doc", "*.doc");
                expectations.Add("*.exe", "*.exe");
                expectations.Add("*.dll", "*.dll");

                foreach (var e in expectations)
                {
                    var catalog = CreateDirectoryCatalog(directory.DirectoryPath, e.Input);
                    var proxy = new DirectoryCatalog.DirectoryCatalogDebuggerProxy(catalog);

                    Assert.AreEqual(e.Output, proxy.SearchPattern);
                }
            }
        }
Esempio n. 12
0
        public void ICompositionElementDisplayName_ValueAsTypesArgument_ShouldIncludeCatalogTypeNameAndTypeFullNames()
        {
            var expectations = new ExpectationCollection <Type[], string>();

            expectations.Add(new Type[] { typeof(Type) },
                             GetDisplayName(false, typeof(TypeCatalog)));

            expectations.Add(new Type[] { typeof(ExportValueTypeSingleton) },
                             GetDisplayName(false, typeof(TypeCatalog), typeof(ExportValueTypeSingleton)));

            expectations.Add(new Type[] { typeof(ExportValueTypeSingleton), typeof(ExportValueTypeSingleton) },
                             GetDisplayName(false, typeof(TypeCatalog), typeof(ExportValueTypeSingleton), typeof(ExportValueTypeSingleton)));

            expectations.Add(new Type[] { typeof(ExportValueTypeSingleton), typeof(string), typeof(ExportValueTypeSingleton) },
                             GetDisplayName(false, typeof(TypeCatalog), typeof(ExportValueTypeSingleton), typeof(ExportValueTypeSingleton)));

            expectations.Add(new Type[] { typeof(ExportValueTypeSingleton), typeof(ExportValueTypeFactory) },
                             GetDisplayName(false, typeof(TypeCatalog), typeof(ExportValueTypeSingleton), typeof(ExportValueTypeFactory)));

            expectations.Add(new Type[] { typeof(ExportValueTypeSingleton), typeof(ExportValueTypeFactory), typeof(CallbackExecuteCodeDuringCompose) },
                             GetDisplayName(true, typeof(TypeCatalog), typeof(ExportValueTypeSingleton), typeof(ExportValueTypeFactory)));

            foreach (var e in expectations)
            {
                var catalog = (ICompositionElement)CreateTypeCatalog(e.Input);

                Assert.Equal(e.Output, catalog.DisplayName);
            }
        }
Esempio n. 13
0
        public void TryParseConstraint_ContractNameReverseOperatorEqualsAsConstraintArgument_CanParse()
        {
            var expectations = new ExpectationCollection <Expression <Func <ExportDefinition, bool> >, string>();

            expectations.Add(item => "" == item.ContractName, "");
            expectations.Add(item => " " == item.ContractName, " ");
            expectations.Add(item => "   " == item.ContractName, "   ");
            expectations.Add(item => "ContractName" == item.ContractName, "ContractName");
            expectations.Add(item => "contractName" == item.ContractName, "contractName");
            expectations.Add(item => "{ContractName}" == item.ContractName, "{ContractName}");
            expectations.Add(item => "{ContractName}Name" == item.ContractName, "{ContractName}Name");
            expectations.Add(item => "System.Windows.Forms.Control" == item.ContractName, "System.Windows.Forms.Control");
            expectations.Add(item => "{System.Windows.Forms}Control" == item.ContractName, "{System.Windows.Forms}Control");

            foreach (var e in expectations)
            {
                AssertCanParse(e.Input, e.Output, new Dictionary <string, Type>());
            }
        }
        public void CreatePartDefinition_NotEnsureIsDiscoverable()
        {
            var expectations = new ExpectationCollection <Type, bool>();

            expectations.Add(typeof(ClassWithTwoZeroParameterConstructors), true);
            expectations.Add(typeof(SimpleConstructorInjectedObject), true);
            expectations.Add(typeof(StaticExportClass), true);
            expectations.Add(typeof(PublicComponentWithPublicExports), true);
            expectations.Add(typeof(ClassWithMultipleMarkedConstructors), true);
            expectations.Add(typeof(ClassWithNoMarkedOrDefaultConstructor), true);
            expectations.Add(typeof(ClassWhichOnlyHasDefaultConstructor), false);
            expectations.Add(typeof(ClassWithOnlyHasImportingConstructorButInherits), true);
            expectations.Add(typeof(ClassWithOnlyHasMultipleImportingConstructorButInherits), true);

            foreach (var e in expectations)
            {
                var definition = AttributedModelServices.CreatePartDefinition(e.Input, null, false);
                Assert.NotNull(definition);
            }
        }
        public void IsDiscoverable()
        {
            var expectations = new ExpectationCollection <Type, bool>();

            expectations.Add(typeof(ClassWithTwoZeroParameterConstructors), true);
            expectations.Add(typeof(SimpleConstructorInjectedObject), true);
            expectations.Add(typeof(StaticExportClass), true);
            expectations.Add(typeof(PublicComponentWithPublicExports), true);
            expectations.Add(typeof(ClassWithMultipleMarkedConstructors), true);
            expectations.Add(typeof(ClassWithNoMarkedOrDefaultConstructor), true);
            expectations.Add(typeof(ClassWhichOnlyHasDefaultConstructor), false);
            expectations.Add(typeof(ClassWithOnlyHasImportingConstructorButInherits), true);
            expectations.Add(typeof(ClassWithOnlyHasMultipleImportingConstructorButInherits), true);

            foreach (var e in expectations)
            {
                var definition = AttributedModelDiscovery.CreatePartDefinitionIfDiscoverable(e.Input, (ICompositionElement)null);

                bool result = (definition != null);

                Assert.Equal(e.Output, result);
            }
        }
        public void Messsage_ShouldIncludeCountOfRootCauses()
        {
            var expectations = new ExpectationCollection <IEnumerable <CompositionError>, int>();

            expectations.Add(ErrorFactory.CreateFromDsl("Error"), 1);
            expectations.Add(ErrorFactory.CreateFromDsl("Error|Error"), 2);
            expectations.Add(ErrorFactory.CreateFromDsl("Error|Error|Error"), 3);
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error)"), 1);
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error)|Error(Error)"), 2);
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error|Error)"), 2);
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error|Error|Exception)"), 3);

            foreach (var e in expectations)
            {
                var exception = CreateCompositionException(e.Input);

                AssertMessage(exception, e.Output, CultureInfo.CurrentCulture);
            }
        }
Esempio n. 17
0
        public void TryParseConstraint_ContractNameReverseOperatorEqualsAsConstraintArgument_CanParse()
        {
            var expectations = new ExpectationCollection<Expression<Func<ExportDefinition, bool>>, string>();
            expectations.Add(item => "" == item.ContractName, "");
            expectations.Add(item => " " == item.ContractName, " ");
            expectations.Add(item => "   " == item.ContractName, "   ");
            expectations.Add(item => "ContractName" == item.ContractName, "ContractName");
            expectations.Add(item => "contractName" == item.ContractName, "contractName");
            expectations.Add(item => "{ContractName}" == item.ContractName, "{ContractName}");
            expectations.Add(item => "{ContractName}Name" == item.ContractName, "{ContractName}Name");
            expectations.Add(item => "System.Windows.Forms.Control" == item.ContractName, "System.Windows.Forms.Control");
            expectations.Add(item => "{System.Windows.Forms}Control" == item.ContractName, "{System.Windows.Forms}Control");

            foreach (var e in expectations)
            {
                AssertCanParse(e.Input, e.Output, new Dictionary<string, Type>());
            }
        }
Esempio n. 18
0
        public void TryParseConstraint_ContractNameOperatorEqualsAndMetadataContainsKeyAsConstraintArgumen_CanParse()
        {
            var expectations = new ExpectationCollection<Expression<Func<ExportDefinition, bool>>, KeyValuePair<string, Type>[]>();
            expectations.Add(
                item => item.ContractName == "ContractName" && typeof(string).IsInstanceOfType(item.Metadata[""]),
                new KeyValuePair<string, Type>[] { new KeyValuePair<string, Type>("", typeof(string)) });
            expectations.Add(
                item => item.ContractName == "ContractName" && typeof(string).IsInstanceOfType(item.Metadata["value"]),
                new KeyValuePair<string, Type>[] { new KeyValuePair<string, Type>("value", typeof(string)) });
            expectations.Add(
                item => item.ContractName == "ContractName"  && typeof(string).IsInstanceOfType(item.Metadata["Value"]),
                new KeyValuePair<string, Type>[] { new KeyValuePair<string, Type>("Value", typeof(string)) });
            expectations.Add(
                item => item.ContractName == "ContractName"  && typeof(string).IsInstanceOfType(item.Metadata["Value"]) && typeof(int).IsInstanceOfType(item.Metadata["value"]),
                new KeyValuePair<string, Type>[] { new KeyValuePair<string, Type>("Value", typeof(string)), new KeyValuePair<string, Type>("value", typeof(int)) });
            expectations.Add(
                item => item.ContractName == "ContractName"  && typeof(string).IsInstanceOfType(item.Metadata["Value"]) && typeof(int).IsInstanceOfType(item.Metadata["value"]) && typeof(object).IsInstanceOfType(item.Metadata["Metadata"]),
                new KeyValuePair<string, Type>[] { new KeyValuePair<string, Type>("Value", typeof(string)), new KeyValuePair<string, Type>("value", typeof(int)), new KeyValuePair<string, Type>("Metadata", typeof(object)) });

            foreach (var e in expectations)
            {
                AssertCanParse(e.Input, "ContractName", e.Output);
            }
        }
Esempio n. 19
0
        public void TryParseConstraint_MetadataContainsKeyAsConstraintArgument_CanParse()
        {
            var expectations = new ExpectationCollection<Expression<Func<ExportDefinition, bool>>, Dictionary<string, Type>>();
            expectations.Add(
                item => typeof(string).IsInstanceOfType(item.Metadata[""]), 
                new Dictionary<string, Type>{ {"", typeof(string) }});
            expectations.Add(
                item => typeof(string).IsInstanceOfType(item.Metadata["value"]), 
                new Dictionary<string, Type>{ {"value", typeof(string) } });
            expectations.Add(
                item => typeof(string).IsInstanceOfType(item.Metadata["Value"]), 
                new Dictionary<string, Type>{ {"Value", typeof(string) } });
            expectations.Add(
                item => typeof(string).IsInstanceOfType(item.Metadata["Value"]) && typeof(int).IsInstanceOfType(item.Metadata["value"]),
                new Dictionary<string, Type>{ {"Value", typeof(string)}, {"value", typeof(int) }});
            expectations.Add(
                item => typeof(string).IsInstanceOfType(item.Metadata["Value"]) && typeof(int).IsInstanceOfType(item.Metadata["value"]) && typeof(object).IsInstanceOfType(item.Metadata["Metadata"]),
                new Dictionary<string, Type>{ {"Value", typeof(string)}, {"value", typeof(int)}, {"Metadata", typeof(object) } });          

            foreach (var e in expectations)
            {
                AssertCanParse(e.Input, (string)null, e.Output);
            }
        }
Esempio n. 20
0
        public void GetDefaultContractNameTest()
        {
            ExpectationCollection<Type, string> expectations = new ExpectationCollection<Type, string>();

            expectations.Add(typeof(string), "System.String");
            expectations.Add(typeof(int?), "System.Nullable(System.Int32)");
            expectations.Add(typeof(NestedParent.NestedChild), "System.ComponentModel.Composition.NestedParent+NestedChild");
            expectations.Add(typeof(int[,]), "System.Int32[,]");
            expectations.Add(typeof(int[,][][]), "System.Int32[,][][]");
            expectations.Add(typeof(Array[,][][]).MakePointerType(), "System.Array[,][][]*");
            expectations.Add(typeof(int).MakePointerType(), "System.Int32*");
            expectations.Add(typeof(int).MakePointerType().MakeArrayType(3).MakeArrayType().MakePointerType(), "System.Int32*[][,,]*");
            expectations.Add(typeof(int).MakeByRefType(), "System.Int32&");
            expectations.Add(typeof(int).MakePointerType().MakeArrayType(4).MakeArrayType().MakeByRefType(), "System.Int32*[][,,,]&");
            expectations.Add(typeof(List<>), "System.Collections.Generic.List()");
            expectations.Add(typeof(Dictionary<int,double>), "System.Collections.Generic.Dictionary(System.Int32,System.Double)");
            expectations.Add(typeof(Dictionary<Dictionary<int,double>,double>), "System.Collections.Generic.Dictionary(System.Collections.Generic.Dictionary(System.Int32,System.Double),System.Double)");
            expectations.Add(typeof(GenericContract1<int>.GenericContract2.GenericContract3<double>), "System.ComponentModel.Composition.GenericContract1(System.Int32)+GenericContract2+GenericContract3(System.Double)");
            expectations.Add(typeof(GenericContract4<int,double>.GenericContract5<double,int>.GenericContract6<int,double>), "System.ComponentModel.Composition.GenericContract4(System.Int32,System.Double)+GenericContract5(System.Double,System.Int32)+GenericContract6(System.Int32,System.Double)");
            expectations.Add(typeof(GenericContract4<,>.GenericContract5<,>.GenericContract6<,>), "System.ComponentModel.Composition.GenericContract4(,)+GenericContract5(,)+GenericContract6(,)");
            expectations.Add(typeof(GenericContract7), "System.ComponentModel.Composition.GenericContract7");
            expectations.Add(typeof(GenericContract8<int>), "System.ComponentModel.Composition.GenericContract8(System.Int32)");
            expectations.Add(typeof(GenericContract4<int,double>.GenericContract5<double,int>[][,,,,]), "System.ComponentModel.Composition.GenericContract4(System.Int32,System.Double)+GenericContract5(System.Double,System.Int32)[][,,,,]");
            expectations.Add(typeof(GenericContract4<int,double>.GenericContract5<double,int>).MakePointerType(), "System.ComponentModel.Composition.GenericContract4(System.Int32,System.Double)+GenericContract5(System.Double,System.Int32)*");
            expectations.Add(typeof(GenericContract4<int,double>.GenericContract5<double,int>[][,]).MakePointerType().MakeArrayType(4), "System.ComponentModel.Composition.GenericContract4(System.Int32,System.Double)+GenericContract5(System.Double,System.Int32)[][,]*[,,,]");            expectations.Add(typeof(OuterClassWithGenericNested.GenericNested<int>), "System.ComponentModel.Composition.OuterClassWithGenericNested+GenericNested(System.Int32)");
            expectations.Add(typeof(Delegate), "System.Delegate");
            expectations.Add(typeof(MulticastDelegate), "System.MulticastDelegate");
            expectations.Add(typeof(Action), "System.Void()");
            expectations.Add(typeof(Func<Func<string>>), "System.Func(System.String)()");
            expectations.Add(typeof(DelegateCompositionTests.DoWorkDelegate), "System.Object(System.Int32,System.Object&,System.String&)");
            expectations.Add(typeof(DelegateCompositionTests.DelegateOneArg), "System.Int32(System.Int32)");
            expectations.Add(typeof(DelegateCompositionTests.DelegateTwoArgs), "System.Int32(System.Int32,System.Int32)");
            expectations.Add(typeof(DelegateCompositionTests.SimpleDelegate), "System.Int32()");
            expectations.Add(typeof(DelegateCompositionTests.ActionWith9Args), "System.Void(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)");
            expectations.Add(typeof(DelegateCompositionTests.FuncWith9Args), "System.Int32(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)");
            expectations.Add(EmitGenericType("MyGeneratedType", typeof(int)), "MyGeneratedType(System.Int32)");
            expectations.Add(EmitGenericType("MyGeneratedType`1", typeof(string)), "MyGeneratedType(System.String)");
            expectations.Add(EmitGenericType("_name_", typeof(List<>)), "_name_(System.Collections.Generic.List())");

            // This particular case can clash with the name generation for methods because we use () for both generics and methods
            // we may want to fix this clash by changing the generic markers but it is likely to be very rare.
            expectations.Add(EmitGenericType("System.Void", typeof(int)), "System.Void(System.Int32)");

            foreach (var e in expectations)
            {
                string typeIdentity = AttributedModelServices.GetTypeIdentity(e.Input);
                Assert.AreEqual(e.Output, typeIdentity);
            }

            // Do it again to excerise the cache.
            foreach (var e in expectations)
            {
                string typeIdentity = AttributedModelServices.GetTypeIdentity(e.Input);
                Assert.AreEqual(e.Output, typeIdentity);
            }
        }
        public void IsDiscoverable()
        {
            var expectations = new ExpectationCollection<Type, bool>();
            expectations.Add(typeof(ClassWithTwoZeroParameterConstructors), true);
            expectations.Add(typeof(SimpleConstructorInjectedObject), true);
            expectations.Add(typeof(StaticExportClass), true);
            expectations.Add(typeof(PublicComponentWithPublicExports), true);
            expectations.Add(typeof(ClassWithMultipleMarkedConstructors), true);
            expectations.Add(typeof(ClassWithNoMarkedOrDefaultConstructor), true);
            expectations.Add(typeof(ClassWhichOnlyHasDefaultConstructor), false);
            expectations.Add(typeof(ClassWithOnlyHasImportingConstructorButInherits), true);
            expectations.Add(typeof(ClassWithOnlyHasMultipleImportingConstructorButInherits), true);

            foreach (var e in expectations)
            {
                var definition = AttributedModelDiscovery.CreatePartDefinitionIfDiscoverable(e.Input, (ICompositionElement)null);

                bool result = (definition != null);

                Assert.AreEqual(e.Output, result);
            }
        }
        public void CreatePartDefinition_NotEnsureIsDiscoverable()
        {
            var expectations = new ExpectationCollection<Type, bool>();
            expectations.Add(typeof(ClassWithTwoZeroParameterConstructors), true);
            expectations.Add(typeof(SimpleConstructorInjectedObject), true);
            expectations.Add(typeof(StaticExportClass), true);
            expectations.Add(typeof(PublicComponentWithPublicExports), true);
            expectations.Add(typeof(ClassWithMultipleMarkedConstructors), true);
            expectations.Add(typeof(ClassWithNoMarkedOrDefaultConstructor), true);
            expectations.Add(typeof(ClassWhichOnlyHasDefaultConstructor), false);
            expectations.Add(typeof(ClassWithOnlyHasImportingConstructorButInherits), true);
            expectations.Add(typeof(ClassWithOnlyHasMultipleImportingConstructorButInherits), true);

            foreach (var e in expectations)
            {
                var definition = AttributedModelServices.CreatePartDefinition(e.Input, null, false);
                Assert.IsNotNull(definition);
            }
        }
Esempio n. 23
0
        public void Message_ShouldIncludeErrors()
        { 
            var expectations = new ExpectationCollection<IEnumerable<CompositionError>, string>();
            expectations.Add(ErrorFactory.CreateFromDsl("Error"),                           "1<Separator> Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error|Error"),                     "1<Separator> Error|2<Separator> Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error|Error|Error"),               "1<Separator> Error|2<Separator> Error|3<Separator> Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error)"),                    "1<Separator> Error|<Prefix>Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error|Error)"),              "1<Separator> Error|<Prefix>Error|2<Separator> Error|<Prefix>Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error|Error|Error)"),        "1<Separator> Error|<Prefix>Error|2<Separator> Error|<Prefix>Error|3<Separator> Error|<Prefix>Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error(Exception))"),         "1<Separator> Exception|<Prefix>Error|<Prefix>Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error|Exception)"),          "1<Separator> Error|<Prefix>Error|2<Separator> Exception|<Prefix>Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Exception)"),                "1<Separator> Exception|<Prefix>Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Exception(Exception))"),     "1<Separator> Exception|<Prefix>Exception|<Prefix>Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error(Exception)|Error)"),   "1<Separator> Exception|<Prefix>Error|<Prefix>Error|2<Separator> Error|<Prefix>Error");

            foreach (var e in expectations)
            {
                var exception = CreateCompositionException(e.Input);

                AssertMessage(exception, e.Output.Split('|'));
            }
        }
Esempio n. 24
0
        public void Message_ShouldIncludeElementGraphAccrossAppDomain()
        {
            PermissionSet ps = new PermissionSet(PermissionState.None);

            ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
            ps.AddPermission(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess));

            //Create a new sandboxed domain
            AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation;

            setup.ApplicationBase = Path.GetDirectoryName(typeof(CompositionExceptionTests).Assembly.Location);
            AppDomain newDomain = AppDomain.CreateDomain("test domain", null, setup, ps);

            Worker remoteWorker = (Worker)newDomain.CreateInstanceAndUnwrap(
                Assembly.GetExecutingAssembly().FullName,
                typeof(Worker).FullName);

            var expectationIndex = new int[] { 1, 2, 3, 10 };

            var expectations       = new ExpectationCollection <CompositionError, string>();
            CompositionError error = null;

            error = CreateCompositionErrorWithElementChain(1);
            expectations.Add(error, GetElementGraphString(error));

            error = CreateCompositionErrorWithElementChain(2);
            expectations.Add(error, GetElementGraphString(error));

            error = CreateCompositionErrorWithElementChain(3);
            expectations.Add(error, GetElementGraphString(error));

            error = CreateCompositionErrorWithElementChain(10);
            expectations.Add(error, GetElementGraphString(error));

            int index = 0;

            foreach (var e in expectations)
            {
                try
                {
                    remoteWorker.Action = (int x) =>
                    {
                        var lclExpectations = new ExpectationCollection <CompositionError, string>();

                        var lclError = CreateCompositionErrorWithElementChain(x);
                        lclExpectations.Add(lclError, GetElementGraphString(lclError));

                        var ce = CreateCompositionException(new CompositionError[] { lclExpectations[0].Input });
                        throw ce;
                    };
                    remoteWorker.DoWork(expectationIndex[index]);
                }
                catch (CompositionException compositionException)
                {
                    string result   = compositionException.ToString();
                    string expected = FixMessage(e.Output);
                    StringAssert.Contains(result, expected);
                }
                catch (Exception exception)
                {
                    Assert.Fail(exception.ToString());
                }
                ++index;
            }
        }
        public void Message_ShouldIncludeErrors()
        {
            var expectations = new ExpectationCollection <IEnumerable <CompositionError>, string>();

            expectations.Add(ErrorFactory.CreateFromDsl("Error"), "1<Separator> Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error|Error"), "1<Separator> Error|2<Separator> Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error|Error|Error"), "1<Separator> Error|2<Separator> Error|3<Separator> Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error)"), "1<Separator> Error|<Prefix>Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error|Error)"), "1<Separator> Error|<Prefix>Error|2<Separator> Error|<Prefix>Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error|Error|Error)"), "1<Separator> Error|<Prefix>Error|2<Separator> Error|<Prefix>Error|3<Separator> Error|<Prefix>Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error(Exception))"), "1<Separator> Exception|<Prefix>Error|<Prefix>Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error|Exception)"), "1<Separator> Error|<Prefix>Error|2<Separator> Exception|<Prefix>Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Exception)"), "1<Separator> Exception|<Prefix>Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Exception(Exception))"), "1<Separator> Exception|<Prefix>Exception|<Prefix>Error");
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error(Exception)|Error)"), "1<Separator> Exception|<Prefix>Error|<Prefix>Error|2<Separator> Error|<Prefix>Error");

            foreach (var e in expectations)
            {
                var exception = CreateCompositionException(e.Input);

                AssertMessage(exception, e.Output.Split('|'));
            }
        }
Esempio n. 26
0
        public void Path_ValidPath_ShouldBeFine()
        {
            using (var directory = CreateTemporaryDirectory())
            {
                var expectations = new ExpectationCollection<string, string>();

                expectations.Add(".", ".");
                expectations.Add(FileIO.RootTemporaryDirectoryName, FileIO.RootTemporaryDirectoryName);
                expectations.Add(FileIO.GetRootTemporaryDirectory(), FileIO.GetRootTemporaryDirectory());
                expectations.Add(directory.DirectoryPath, directory.DirectoryPath);

                foreach (var e in expectations)
                {
                    var cat = CreateDirectoryCatalog(e.Input, NonExistentSearchPattern);

                    Assert.AreEqual(e.Output, cat.Path);
                }
            }
        }
Esempio n. 27
0
        public void ToString_DerivedImportDefinition_ShouldReturnOverriddenConstraintProperty()
        {
            var expectations = new ExpectationCollection<Expression<Func<ExportDefinition, bool>>, string>();
            expectations.Add(d => d.ContractName == "ContractName", @"d.ContractName ==? ""ContractName""");
            expectations.Add(d => d.ContractName.Equals("ContractName"), @"d.ContractName.Equals\(""ContractName""\)");
            expectations.Add(d => (string)d.Metadata["Name"] == "Value", @"Convert\(d.Metadata.get_Item\(""Name""\)\) ==? ""Value""");
            expectations.Add(d => true, "True");

            foreach (var e in expectations)
            {
                var item = new DerivedImportDefinition(e.Input);

                Assert.IsTrue(Regex.IsMatch(item.ToString(), e.Output));
            }
        }
Esempio n. 28
0
        public void FullPath_ValidPath_ShouldBeFine()
        {
            using (var directory = CreateTemporaryDirectory())
            {
                var expectations = new ExpectationCollection<string, string>();

                // Ensure the path is always normalized properly.
                string rootTempPath = Path.GetFullPath(FileIO.GetRootTemporaryDirectory()).ToUpperInvariant();

                // Note: These relative paths work properly because the unit test temporary directories are always
                // created as a subfolder off the AppDomain.CurrentDomain.BaseDirectory.
                expectations.Add(".", Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ".")).ToUpperInvariant());
                expectations.Add(FileIO.RootTemporaryDirectoryName, rootTempPath);
                expectations.Add(FileIO.GetRootTemporaryDirectory(), rootTempPath);
                expectations.Add(directory.DirectoryPath, Path.GetFullPath(directory.DirectoryPath).ToUpperInvariant());

                foreach (var e in expectations)
                {
                    var cat = CreateDirectoryCatalog(e.Input, NonExistentSearchPattern);

                    Assert.AreEqual(e.Output, cat.FullPath);
                }
            }
        }
Esempio n. 29
0
        public void Message_ShouldIncludeElementGraph()
        {
            var expectations = new ExpectationCollection<CompositionError, string>();
            CompositionError error = null;

            error = CreateCompositionErrorWithElementChain(1);
            expectations.Add(error, GetElementGraphString(error));

            error = CreateCompositionErrorWithElementChain(2);
            expectations.Add(error, GetElementGraphString(error));

            error = CreateCompositionErrorWithElementChain(3);
            expectations.Add(error, GetElementGraphString(error));

            error = CreateCompositionErrorWithElementChain(10);
            expectations.Add(error, GetElementGraphString(error));


            foreach (var e in expectations)
            {
                var exception = CreateCompositionException(new CompositionError[] { e.Input });

                string result = exception.ToString();
                string expected = FixMessage(e.Output);
                StringAssert.Contains(result, expected);
            }
        }
Esempio n. 30
0
        public void Message_ShouldIncludeElementGraphAccrossAppDomain()
        {
            PermissionSet ps = new PermissionSet(PermissionState.None);
            ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
            ps.AddPermission(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess));

            //Create a new sandboxed domain 
            AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation;
            AppDomain newDomain = AppDomain.CreateDomain("test domain", null, setup, ps);

            Worker remoteWorker = (Worker)newDomain.CreateInstanceAndUnwrap(
                Assembly.GetExecutingAssembly().FullName,
                typeof(Worker).FullName);

            var expectationIndex = new int[] { 1, 2, 3, 10};

            var expectations = new ExpectationCollection<CompositionError, string>();
            CompositionError error = null;

            error = CreateCompositionErrorWithElementChain(1);
            expectations.Add(error, GetElementGraphString(error));

            error = CreateCompositionErrorWithElementChain(2);
            expectations.Add(error, GetElementGraphString(error));

            error = CreateCompositionErrorWithElementChain(3);
            expectations.Add(error, GetElementGraphString(error));

            error = CreateCompositionErrorWithElementChain(10);
            expectations.Add(error, GetElementGraphString(error));

            int index = 0;
            foreach (var e in expectations)
            {
                try
                {
                    remoteWorker.Action = (int x) => 
                    {
                        var lclExpectations = new ExpectationCollection<CompositionError, string>();

                        var lclError = CreateCompositionErrorWithElementChain(x);
                        lclExpectations.Add(lclError, GetElementGraphString(lclError));

                        var ce =  CreateCompositionException(new CompositionError[] { lclExpectations[0].Input });
                        throw ce;
                    };
                    remoteWorker.DoWork(expectationIndex[index]);
                }
                catch (CompositionException compositionException)
                {
                    string result = compositionException.ToString();
                    string expected = FixMessage(e.Output);
                    StringAssert.Contains(result, expected);
                }
                catch (Exception exception)
                {
                    Assert.Fail(exception.ToString());
                }
                ++index;
            }
        }
Esempio n. 31
0
 static Worker()
 {
     expectations.Add(ErrorFactory.CreateFromDsl("Error"), "1<Separator> Error");
     expectations.Add(ErrorFactory.CreateFromDsl("Error|Error"), "1<Separator> Error|2<Separator> Error");
     expectations.Add(ErrorFactory.CreateFromDsl("Error|Error|Error"), "1<Separator> Error|2<Separator> Error|3<Separator> Error");
     expectations.Add(ErrorFactory.CreateFromDsl("Error(Error)"), "1<Separator> Error|<Prefix>Error");
     expectations.Add(ErrorFactory.CreateFromDsl("Error(Error|Error)"), "1<Separator> Error|<Prefix>Error|2<Separator> Error|<Prefix>Error");
     expectations.Add(ErrorFactory.CreateFromDsl("Error(Error|Error|Error)"), "1<Separator> Error|<Prefix>Error|2<Separator> Error|<Prefix>Error|3<Separator> Error|<Prefix>Error");
     expectations.Add(ErrorFactory.CreateFromDsl("Error(Error(Exception))"), "1<Separator> Exception|<Prefix>Error|<Prefix>Error");
     expectations.Add(ErrorFactory.CreateFromDsl("Error(Error|Exception)"), "1<Separator> Error|<Prefix>Error|2<Separator> Exception|<Prefix>Error");
     expectations.Add(ErrorFactory.CreateFromDsl("Error(Exception)"), "1<Separator> Exception|<Prefix>Error");
     expectations.Add(ErrorFactory.CreateFromDsl("Error(Exception(Exception))"), "1<Separator> Exception|<Prefix>Exception|<Prefix>Error");
     expectations.Add(ErrorFactory.CreateFromDsl("Error(Error(Exception)|Error)"), "1<Separator> Exception|<Prefix>Error|<Prefix>Error|2<Separator> Error|<Prefix>Error");
 }
Esempio n. 32
0
        public void Messsage_ShouldIncludeCountOfRootCauses()
        {
            var expectations = new ExpectationCollection<IEnumerable<CompositionError>, int>();
            expectations.Add(ErrorFactory.CreateFromDsl("Error"),                            1);
            expectations.Add(ErrorFactory.CreateFromDsl("Error|Error"),                      2);
            expectations.Add(ErrorFactory.CreateFromDsl("Error|Error|Error"),                3);
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error)"),                     1);
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error)|Error(Error)"),        2);
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error|Error)"),               2);
            expectations.Add(ErrorFactory.CreateFromDsl("Error(Error|Error|Exception)"),     3);
            
            foreach (var e in expectations)
            {
                var exception = CreateCompositionException(e.Input);

                AssertMessage(exception, e.Output, CultureInfo.CurrentCulture);
            }
        }
        public void GetDefaultContractNameTest()
        {
            ExpectationCollection <Type, string> expectations = new ExpectationCollection <Type, string>();

            expectations.Add(typeof(string), "System.String");
            expectations.Add(typeof(int?), "System.Nullable(System.Int32)");
            expectations.Add(typeof(NestedParent.NestedChild), "System.ComponentModel.Composition.NestedParent+NestedChild");
            expectations.Add(typeof(int[, ]), "System.Int32[,]");
            expectations.Add(typeof(int[, ][][]), "System.Int32[,][][]");
            expectations.Add(typeof(Array[, ][][]).MakePointerType(), "System.Array[,][][]*");
            expectations.Add(typeof(int).MakePointerType(), "System.Int32*");
            expectations.Add(typeof(int).MakePointerType().MakeArrayType(3).MakeArrayType().MakePointerType(), "System.Int32*[][,,]*");
            expectations.Add(typeof(int).MakeByRefType(), "System.Int32&");
            expectations.Add(typeof(int).MakePointerType().MakeArrayType(4).MakeArrayType().MakeByRefType(), "System.Int32*[][,,,]&");
            expectations.Add(typeof(List <>), "System.Collections.Generic.List()");
            expectations.Add(typeof(Dictionary <int, double>), "System.Collections.Generic.Dictionary(System.Int32,System.Double)");
            expectations.Add(typeof(Dictionary <Dictionary <int, double>, double>), "System.Collections.Generic.Dictionary(System.Collections.Generic.Dictionary(System.Int32,System.Double),System.Double)");
            expectations.Add(typeof(GenericContract1 <int> .GenericContract2.GenericContract3 <double>), "System.ComponentModel.Composition.GenericContract1(System.Int32)+GenericContract2+GenericContract3(System.Double)");
            expectations.Add(typeof(GenericContract4 <int, double> .GenericContract5 <double, int> .GenericContract6 <int, double>), "System.ComponentModel.Composition.GenericContract4(System.Int32,System.Double)+GenericContract5(System.Double,System.Int32)+GenericContract6(System.Int32,System.Double)");
            expectations.Add(typeof(GenericContract4 <,> .GenericContract5 <,> .GenericContract6 <,>), "System.ComponentModel.Composition.GenericContract4(,)+GenericContract5(,)+GenericContract6(,)");
            expectations.Add(typeof(GenericContract7), "System.ComponentModel.Composition.GenericContract7");
            expectations.Add(typeof(GenericContract8 <int>), "System.ComponentModel.Composition.GenericContract8(System.Int32)");
            expectations.Add(typeof(GenericContract4 <int, double> .GenericContract5 <double, int>[][, , , , ]), "System.ComponentModel.Composition.GenericContract4(System.Int32,System.Double)+GenericContract5(System.Double,System.Int32)[][,,,,]");
            expectations.Add(typeof(GenericContract4 <int, double> .GenericContract5 <double, int>).MakePointerType(), "System.ComponentModel.Composition.GenericContract4(System.Int32,System.Double)+GenericContract5(System.Double,System.Int32)*");
            expectations.Add(typeof(GenericContract4 <int, double> .GenericContract5 <double, int>[][, ]).MakePointerType().MakeArrayType(4), "System.ComponentModel.Composition.GenericContract4(System.Int32,System.Double)+GenericContract5(System.Double,System.Int32)[][,]*[,,,]");            expectations.Add(typeof(OuterClassWithGenericNested.GenericNested <int>), "System.ComponentModel.Composition.OuterClassWithGenericNested+GenericNested(System.Int32)");
            expectations.Add(typeof(Delegate), "System.Delegate");
            expectations.Add(typeof(MulticastDelegate), "System.MulticastDelegate");
            expectations.Add(typeof(Action), "System.Void()");
            expectations.Add(typeof(Func <Func <string> >), "System.Func(System.String)()");
            expectations.Add(typeof(DelegateCompositionTests.DoWorkDelegate), "System.Object(System.Int32,System.Object&,System.String&)");
            expectations.Add(typeof(DelegateCompositionTests.DelegateOneArg), "System.Int32(System.Int32)");
            expectations.Add(typeof(DelegateCompositionTests.DelegateTwoArgs), "System.Int32(System.Int32,System.Int32)");
            expectations.Add(typeof(DelegateCompositionTests.SimpleDelegate), "System.Int32()");
            expectations.Add(EmitGenericType("MyGeneratedType", typeof(int)), "MyGeneratedType(System.Int32)");
            expectations.Add(EmitGenericType("MyGeneratedType`1", typeof(string)), "MyGeneratedType(System.String)");
            expectations.Add(EmitGenericType("_name_", typeof(List <>)), "_name_(System.Collections.Generic.List())");

            // This particular case can clash with the name generation for methods because we use () for both generics and methods
            // we may want to fix this clash by changing the generic markers but it is likely to be very rare.
            expectations.Add(EmitGenericType("System.Void", typeof(int)), "System.Void(System.Int32)");

            foreach (var e in expectations)
            {
                string typeIdentity = AttributedModelServices.GetTypeIdentity(e.Input);
                Assert.AreEqual(e.Output, typeIdentity);
            }

            // Do it again to excerise the cache.
            foreach (var e in expectations)
            {
                string typeIdentity = AttributedModelServices.GetTypeIdentity(e.Input);
                Assert.AreEqual(e.Output, typeIdentity);
            }
        }
Esempio n. 34
0
        public void ICompositionElementDisplayName_ValueAsTypesArgument_ShouldIncludeCatalogTypeNameAndTypeFullNames()
        {
            var expectations = new ExpectationCollection<Type[], string>();
            expectations.Add(new Type[] { typeof(Type) },
                             GetDisplayName(false, typeof(TypeCatalog)));

            expectations.Add(new Type[] { typeof(ExportValueTypeSingleton) },
                             GetDisplayName(false, typeof(TypeCatalog), typeof(ExportValueTypeSingleton)));

            expectations.Add(new Type[] { typeof(ExportValueTypeSingleton), typeof(ExportValueTypeSingleton) },
                             GetDisplayName(false, typeof(TypeCatalog), typeof(ExportValueTypeSingleton), typeof(ExportValueTypeSingleton)));

            expectations.Add(new Type[] { typeof(ExportValueTypeSingleton), typeof(string), typeof(ExportValueTypeSingleton) },
                             GetDisplayName(false, typeof(TypeCatalog), typeof(ExportValueTypeSingleton), typeof(ExportValueTypeSingleton)));

            expectations.Add(new Type[] { typeof(ExportValueTypeSingleton), typeof(ExportValueTypeFactory) },
                             GetDisplayName(false, typeof(TypeCatalog), typeof(ExportValueTypeSingleton), typeof(ExportValueTypeFactory)));

            expectations.Add(new Type[] { typeof(ExportValueTypeSingleton), typeof(ExportValueTypeFactory), typeof(CallbackExecuteCodeDuringCompose) },
                             GetDisplayName(true, typeof(TypeCatalog), typeof(ExportValueTypeSingleton), typeof(ExportValueTypeFactory)));

            foreach (var e in expectations)
            {
                var catalog = (ICompositionElement)CreateTypeCatalog(e.Input);

                Assert.AreEqual(e.Output, catalog.DisplayName);
            }
        }
Esempio n. 35
0
        public void Constructor2_ContractName_ShouldSetAppropriately()
        {
            var expectations = new ExpectationCollection<string, string>();

            expectations.Add(null, string.Empty);
            expectations.Add(string.Empty, string.Empty);
            expectations.Add("Contract", "Contract");

            string cn = AttributedModelServices.GetContractName(typeof(ImportDefinitionTests));
            expectations.Add(cn, cn);

            foreach (var e in expectations)
            {
                var definition = new ImportDefinition(d => true, e.Input, ImportCardinality.ExactlyOne, false, false);

                Assert.AreEqual(e.Output, definition.ContractName);
            }
        }