예제 #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);
        }
        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);
        }
        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");
        }
        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);
        }
        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
        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);
            }
        }
        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();
        }