コード例 #1
0
        public void GetFieldPlugComponent()
        {
            var c = _context.GetComponent <ComponentWithFieldPlug>();

            Assert.IsNotNull(c);
            Assert.IsNotNull(c.Plug);
        }
コード例 #2
0
        public void RegistrationOrderInsensitivity()
        {
            var contextOne = new ComponentContext();

            contextOne.Register(typeof(EmptyComponentAndContract));
            contextOne.Register(typeof(ComponentWithFieldPlug));
            contextOne.Register(typeof(ComponentWithPropertyPlug));

            var contextTwo = new ComponentContext();

            contextTwo.Register(typeof(ComponentWithFieldPlug));
            contextTwo.Register(typeof(ComponentWithPropertyPlug));
            contextTwo.Register(typeof(EmptyComponentAndContract));

            var cField    = contextOne.GetComponent <ComponentWithFieldPlug>();
            var cProperty = contextOne.GetComponent <ComponentWithPropertyPlug>();

            Assert.IsNotNull(cField);
            Assert.IsNotNull(cProperty);
            Assert.IsNotNull(cField.Plug);
            Assert.IsNotNull(cProperty.Plug);
            Assert.AreSame(cField.Plug, cProperty.Plug);

            cField    = contextTwo.GetComponent <ComponentWithFieldPlug>();
            cProperty = contextTwo.GetComponent <ComponentWithPropertyPlug>();
            Assert.IsNotNull(cField);
            Assert.IsNotNull(cProperty);
            Assert.IsNotNull(cField.Plug);
            Assert.IsNotNull(cProperty.Plug);
            Assert.AreSame(cField.Plug, cProperty.Plug);
        }
コード例 #3
0
        public void InterfaceContractTest()
        {
            var c = _context.GetComponent <IInterfaceContract>();

            Assert.IsNotNull(c);
            Assert.IsInstanceOfType(c, typeof(InterfaceContractComponent));
        }
コード例 #4
0
        public void ComponentPlugAsField()
        {
            _context.Register(typeof(WithFieldComponentPlug));

            var c = _context.GetComponent <WithFieldComponentPlug>();

            Assert.IsNotNull(c.SampleContract);
        }
コード例 #5
0
        public void QueryWithoutName()
        {
            var c1 = _context.GetComponent <ComponentWithDefaultName>();
            var c2 = _context.GetComponent <ComponentWithoutName>();

            Assert.IsNull(c1);
            Assert.IsNull(c2);
        }
コード例 #6
0
        public void RegisterWithAssemblyObject()
        {
            _context.RegisterAssembly(typeof(IContractInAnotherAssembly).Assembly);

            var c = _context.GetComponent <IContractInAnotherAssembly>();

            Assert.IsNotNull(c);
        }
コード例 #7
0
        public void ConfigurationPointAsField()
        {
            _context.Register(typeof(WithFieldConfigurationPoint));

            var c = _context.GetComponent <WithFieldConfigurationPoint>();

            Assert.AreEqual(c.SomeConfigurationPoint, "SomeConfigurationValue");
        }
コード例 #8
0
        public void ResourcePlugAsField()
        {
            _context.Register(typeof(WithFieldResourcePlug));

            var c = _context.GetComponent <WithFieldResourcePlug>();

            Assert.IsNotNull(c.ResourcePlug);
        }
コード例 #9
0
        public void DirectClosedGeneric()
        {
            _context.ForComponent <ClosedGenericComponent>()
            .RegisterWith <IGenericContract <string> >();

            var c = _context.GetComponent <IGenericContract <string> >();

            Assert.IsNotNull(c);
        }
コード例 #10
0
        public void NoAttributesAtAll()
        {
            _context.Configuration.DisableAttributeChecking = true;
            _context.Register(typeof(INonAttributedContractOne), typeof(NonAttributedComponentOne));

            var c = _context.GetComponent <INonAttributedContractOne>();

            Assert.IsNotNull(c);
        }
コード例 #11
0
        public void OptConfigProvided()
        {
            _context.ProcessCompositionXmlFromResource("Appson.Composer.UnitTests.RequiredAndOptionalInitPoint.Xmls.OptConfigProvided.xml");

            var c = _context.GetComponent <ComponentWithOptionalConfig>();

            Assert.IsNotNull(c);
            Assert.IsNotNull(c.SomeConfig);
            Assert.AreEqual(c.SomeConfig, "SomeConfigValue");
        }
コード例 #12
0
        public void ReqConfigProvided()
        {
            _context.ProcessCompositionXmlFromResource(typeof(AssemblyPointer).Assembly,
                                                       "ComposerCore.Tests.RequiredAndOptionalInitPoint.Xmls.ReqConfigProvided.xml");

            var c = _context.GetComponent <ComponentWithRequiredConfig>();

            Assert.IsNotNull(c);
            Assert.IsNotNull(c.SomeConfig);
            Assert.AreEqual(c.SomeConfig, "SomeConfigValue");
        }
コード例 #13
0
        public void DefaultConstructorFromMany()
        {
            _context.Register(typeof(MultiConstructorsWithDefault));
            var c = _context.GetComponent <MultiConstructorsWithDefault>();

            Assert.IsNotNull(c);
            Assert.AreEqual(1, c.InvokedConstructor);

            Assert.IsNull(c.A);
            Assert.IsNull(c.B);
        }
コード例 #14
0
        public void RegisterWithDefaultCache()
        {
            _context.ForComponent <NonAttributedComponent>().RegisterWith <INonAttributedContract>();

            var c1 = _context.GetComponent <INonAttributedContract>();
            var c2 = _context.GetComponent <INonAttributedContract>();

            Assert.IsNotNull(c1);
            Assert.IsNotNull(c2);
            Assert.IsTrue(ReferenceEquals(c1, c2));
        }
コード例 #15
0
        public void SimpleRegister()
        {
            _context.ForComponent <NonAttributedComponent>().RegisterWith <INonAttributedContract>();

            var c = _context.GetComponent <INonAttributedContract>();

            Assert.IsNotNull(c);
        }
コード例 #16
0
        public void ReplaceWhenCreating()
        {
            var listener = new ReplaceUponCreationListener();

            _context.RegisterCompositionListener("replacer", listener);

            var c = _context.GetComponent <ISampleContract>();

            Assert.IsNotNull(c);
            Assert.IsNotInstanceOfType(c, typeof(SampleComponentOne));
            Assert.IsInstanceOfType(c, typeof(SampleComponentTwo));
        }
        public void AddInitializationMethod()
        {
            _context.ForComponent <NonAttributedComponent>()
            .NotifyInitialized((cmpsr, x) => x.Initialize())
            .RegisterWith <INonAttributedContract>();

            var i = _context.GetComponent <INonAttributedContract>();
            var c = i as NonAttributedComponent;

            Assert.IsNotNull(i);
            Assert.IsNotNull(c);
            Assert.IsTrue(c.InitCalled);
        }
コード例 #18
0
        public void SetValue()
        {
            _context.ForComponent <NonAttributedComponent>()
            .SetValue(x => x.SomeValue, "someString")
            .SetValue(x => x.SomeOtherValue, 5)
            .RegisterWith <INonAttributedContract>();

            var i = _context.GetComponent <INonAttributedContract>();
            var c = i as NonAttributedComponent;

            Assert.IsNotNull(i);
            Assert.IsNotNull(c);
            Assert.AreEqual("someString", c.SomeValue);
            Assert.AreEqual(5, c.SomeOtherValue);
        }
コード例 #19
0
        public void QueryComponentPlugs()
        {
            _context.ForComponent <NonAttributedComponent>()
            .SetComponent(x => x.ComponentOne)
            .SetComponent(x => x.ComponentTwo)
            .RegisterWith <INonAttributedContract>();

            var i = _context.GetComponent <INonAttributedContract>();
            var c = i as NonAttributedComponent;

            Assert.IsNotNull(i);
            Assert.IsNotNull(c);
            Assert.IsNotNull(c.ComponentOne);
            Assert.IsNotNull(c.ComponentTwo);
        }
コード例 #20
0
        static void Main()
        {
            var context = new ComponentContext();

            context.ProcessCompositionXmlFromResource("Compositional.Composer.Samples.Basic.CalculatorComposition.xml");

            var classEmitter = context.GetComponent <IClassEmitter>();
            IEmittedTypeHandler emittedTypeHandler = new TestEmittedTypeHandler();

            context.Register(new PreInitializedComponentFactory(classEmitter.EmitInterfaceInstance(emittedTypeHandler, typeof(IAdder))));
            context.Register(new PreInitializedComponentFactory(classEmitter.EmitInterfaceInstance(emittedTypeHandler, typeof(IMultiplier))));
            context.Register(new PreInitializedComponentFactory(classEmitter.EmitInterfaceInstance(emittedTypeHandler, typeof(IDivider))));

            context.GetComponent <IProgramRunner>().Run();
        }
コード例 #21
0
        public void GetComponentWithoutRegistrationThrows()
        {
            _context = new ComponentContext();
            _context.Register(typeof(ComponentWithFieldPlug));

            _context.GetComponent <ComponentWithFieldPlug>();
        }
コード例 #22
0
        public void ConstructorParameterAreRequired()
        {
            _context.UnregisterFamily(typeof(ISampleContractA));
            _context.Register(typeof(MultiConstructorsWithDefaultAndMarked));

            _context.GetComponent <MultiConstructorsWithDefaultAndMarked>();
        }
コード例 #23
0
        public void GetComponentWithoutRegistrationReturnsNull()
        {
            _context = new ComponentContext();
            var c = _context.GetComponent <EmptyComponentAndContract>();

            Assert.IsNull(c);
        }
コード例 #24
0
        public void StopWorkerService()
        {
            var workerService = ComponentContext.GetComponent <WorkerService>();

            workerService.Stopping = true;
            workerService.StopAsync().GetAwaiter().GetResult();
        }
コード例 #25
0
ファイル: Program.cs プロジェクト: yavari-alireza/composer
        static void Main()
        {
            var context = new ComponentContext();

            context.ProcessCompositionXmlFromResource("Compositional.Composer.Samples.Basic.CalculatorComposition.xml");

            context.GetComponent <IProgramRunner>().Run();
        }
コード例 #26
0
        static void Main()
        {
            var composer = new ComponentContext();

            composer.Register(typeof(DefaultLogger));

            composer.GetComponent <ILogger>().Log("Hello, compositional world!");
        }
コード例 #27
0
        public void ReqPlugProvided()
        {
            _context.Register(typeof(ComponentWithRequiredPlug));
            _context.Register(typeof(PluggedComponent));

            var c = _context.GetComponent <ComponentWithRequiredPlug>();

            Assert.IsNotNull(c);
            Assert.IsNotNull(c.PluggedContract);
        }
コード例 #28
0
        private static void SetResolver(ComponentContext composer)
        {
            var dependencyResolverContract = composer.GetComponent <IDependencyResolverContract>();

            if (dependencyResolverContract != null)
            {
                DependencyResolver.SetResolver(dependencyResolverContract);
            }
        }
コード例 #29
0
        public void TestInitialize()
        {
            _context = new ComponentContext();
            _context.Register(typeof(SampleComponentOne));

            _listener = new ParameterRecorderListener();
            _context.RegisterCompositionListener("recorder", _listener);

            _context.GetComponent <ISampleContract>();
        }
コード例 #30
0
        public void TestInitialize()
        {
            _context      = new ComponentContext();
            _classEmitter = _context.GetComponent <IClassEmitter>();

//			UNCOMMENT FOLLOWING FOR DEBUGGING
//			_classEmitter = new DefaultClassEmitter {SaveEmittedAssembly = true, SaveTargetFolder = "D:\\"};
//			_context.InitializePlugs(_classEmitter, typeof (DefaultClassEmitter));

            _dth = new TestingEmittedTypeHandler();
        }