Пример #1
0
        public void DesignTimeSortTest()
        {
            ExportStrategyCollection collection =
                new ExportStrategyCollection(new FauxInjectionScope(),
                    ExportEnvironment.DesignTime,
                    DependencyInjectionContainer.CompareExportStrategies);

            collection.AddExport(new FauxExportStrategy(() => ExportEnvironment.RunTime)
                                 {
                                     Environment = ExportEnvironment.RunTime
                                 }, null);

            collection.AddExport(new FauxExportStrategy(() => ExportEnvironment.DesignTime)
                                 {
                                     Environment = ExportEnvironment.DesignTime
                                 }, null);

            collection.AddExport(new FauxExportStrategy(() => ExportEnvironment.UnitTest)
                                 {
                                     Environment = ExportEnvironment.UnitTest
                                 }, null);

            Assert.Equal(ExportEnvironment.DesignTime, collection.Activate(null, null, new FauxInjectionContext(), null, null));

            Assert.Equal(3, collection.ActivateAll<ExportEnvironment>(new FauxInjectionContext(), null, null).Count());
        }
Пример #2
0
        public void ActivateTest()
        {
            ExportStrategyCollection collection =
                new ExportStrategyCollection(new FauxInjectionScope(),
                    ExportEnvironment.RunTime,
                    DependencyInjectionContainer.CompareExportStrategies);

            collection.AddExport(new FauxExportStrategy(() => 5), null);

            Assert.Equal(5, collection.Activate(null, null, new FauxInjectionContext(), null, null));
        }
Пример #3
0
        public void DisposeTwiceTest()
        {
            ExportStrategyCollection collection =
                new ExportStrategyCollection(new FauxInjectionScope(),
                    ExportEnvironment.RunTime,
                    DependencyInjectionContainer.CompareExportStrategies);

            collection.AddExport(new FauxExportStrategy(() => 5), null);

            collection.Dispose();

            collection.Dispose();
        }
Пример #4
0
        public void ActivateAll()
        {
            ExportStrategyCollection collection =
                new ExportStrategyCollection(new FauxInjectionScope(),
                    ExportEnvironment.RunTime,
                    DependencyInjectionContainer.CompareExportStrategies);

            collection.AddExport(new FauxExportStrategy(() => 5) { Priority = 5 }, null);
            collection.AddExport(new FauxExportStrategy(() => 10) { Priority = 10 }, null);
            collection.AddExport(new FauxExportStrategy(() => 1) { Priority = 1 }, null);

            List<int> exports = new List<int>(collection.ActivateAll<int>(new FauxInjectionContext(), null, null));

            Assert.Equal(3, exports.Count);
            Assert.Equal(10, exports[0]);
            Assert.Equal(5, exports[1]);
            Assert.Equal(1, exports[2]);
        }
Пример #5
0
        public void EmptyActivate()
        {
            ExportStrategyCollection collection =
                new ExportStrategyCollection(new FauxInjectionScope(),
                    ExportEnvironment.RunTime,
                    DependencyInjectionContainer.CompareExportStrategies);

            object activated = collection.Activate(null, null, new FauxInjectionContext(), null, null);

            Assert.Null(activated);
        }
Пример #6
0
        public void RemoveTest()
        {
            ExportStrategyCollection collection =
                new ExportStrategyCollection(new FauxInjectionScope(),
                    ExportEnvironment.RunTime,
                    DependencyInjectionContainer.CompareExportStrategies);

            FauxExportStrategy tenExport = new FauxExportStrategy(() => 10) { Priority = 10 };

            collection.AddExport(new FauxExportStrategy(() => 5) { Priority = 5 }, null);
            collection.AddExport(tenExport, null);
            collection.AddExport(new FauxExportStrategy(() => 1) { Priority = 1 }, null);

            Assert.Equal(10, collection.Activate(null, null, new FauxInjectionContext(), null, null));

            collection.RemoveExport(tenExport, null);

            Assert.Equal(5, collection.Activate(null, null, new FauxInjectionContext(), null, null));
            Assert.Equal(2, collection.ActivateAll<int>(new FauxInjectionContext(), null, null).Count());
        }