Ejemplo n.º 1
0
        private static void PerformSmokeTest(MappingBehaviors behaviors)
        {
            Console.WriteLine();
            using (var container = new UnityContainer())
            {
                using (new ColorSwitch(ConsoleColor.Yellow).AsDisposable())
                    using (new DisposableAdapter <InvertedColourSwitch>())
                        Console.WriteLine("Smoke testing using the following behaviors: {0}.", behaviors.ToString());

                try
                {
                    container.AutomapAssemblies(new MappingOptions {
                        Behaviors = behaviors
                    }, Assembly.GetExecutingAssembly().FullName, "ConfigProviderAssembly", "Lydian.Unity.Automapper.Test.TestAssembly", "Lydian.Unity.Automapper.Test.TestAssemblyTwo");
                }
                catch (Exception ex)
                {
                    using (new ColorSwitch(ConsoleColor.Red).AsDisposable())
                        using (new DisposableAdapter <InvertedColourSwitch>())
                        {
                            Console.WriteLine("Failed during automapping phase: {0}.", ex.Message);
                            Console.WriteLine();
                        }
                }

                TestRegistration <ISimpleInterface>(container, "Non generic mapping");
                TestRegistration <IMyGenericClass <Boolean, String> >(container, "Open generic mapping");
                TestRegistration <IMyGenericClass <String, Int32> >(container, "First closed generic mapping");
                TestRegistration <IMyGenericClass <Boolean, Object> >(container, "Second closed generic mapping");
                TestRegistration <IMultimap>(container, "Multiple mappings", false);
                if (behaviors.HasFlag(MappingBehaviors.CollectionRegistration))
                {
                    TestRegistration <IEnumerable <IMultimap> >(container, "Multiple mappings ACR");
                }

                TestRegistration <ISingleMultimap>(container, "Single-instance multimaps", singleMapping: false);
                if (behaviors.HasFlag(MappingBehaviors.CollectionRegistration))
                {
                    TestRegistration <IEnumerable <ISingleMultimap> >(container, "Single-instance mappings ACR");
                }

                TestRegistration <INamedInterface>(container, "Named mapping", mappingName: "Test");

                TestRegistration <SingletonInterface>(container, "Provider-based singleton mapping");
                TestRegistration <MultimappingInterface>(container, "Provider-based multi-mapping", singleMapping: false);

                TestRegistration <IDependencyInversionPrinciple>(container, "Decoupled DIP mapping");

                TestPolicyRegistration(container);
            }
        }