public void GetFieldPlugComponent() { var c = _context.GetComponent <ComponentWithFieldPlug>(); Assert.IsNotNull(c); Assert.IsNotNull(c.Plug); }
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); }
public void InterfaceContractTest() { var c = _context.GetComponent <IInterfaceContract>(); Assert.IsNotNull(c); Assert.IsInstanceOfType(c, typeof(InterfaceContractComponent)); }
public void ComponentPlugAsField() { _context.Register(typeof(WithFieldComponentPlug)); var c = _context.GetComponent <WithFieldComponentPlug>(); Assert.IsNotNull(c.SampleContract); }
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); }
public void ConfigurationPointAsField() { _context.Register(typeof(WithFieldConfigurationPoint)); var c = _context.GetComponent <WithFieldConfigurationPoint>(); Assert.AreEqual(c.SomeConfigurationPoint, "SomeConfigurationValue"); }
public void ResourcePlugAsField() { _context.Register(typeof(WithFieldResourcePlug)); var c = _context.GetComponent <WithFieldResourcePlug>(); Assert.IsNotNull(c.ResourcePlug); }
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); }
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"); }
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); }
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)); }
public void SimpleRegister() { _context.ForComponent <NonAttributedComponent>().RegisterWith <INonAttributedContract>(); var c = _context.GetComponent <INonAttributedContract>(); Assert.IsNotNull(c); }
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); }
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); }
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(); }
public void GetComponentWithoutRegistrationThrows() { _context = new ComponentContext(); _context.Register(typeof(ComponentWithFieldPlug)); _context.GetComponent <ComponentWithFieldPlug>(); }
public void ConstructorParameterAreRequired() { _context.UnregisterFamily(typeof(ISampleContractA)); _context.Register(typeof(MultiConstructorsWithDefaultAndMarked)); _context.GetComponent <MultiConstructorsWithDefaultAndMarked>(); }
public void GetComponentWithoutRegistrationReturnsNull() { _context = new ComponentContext(); var c = _context.GetComponent <EmptyComponentAndContract>(); Assert.IsNull(c); }
public void StopWorkerService() { var workerService = ComponentContext.GetComponent <WorkerService>(); workerService.Stopping = true; workerService.StopAsync().GetAwaiter().GetResult(); }
static void Main() { var context = new ComponentContext(); context.ProcessCompositionXmlFromResource("Compositional.Composer.Samples.Basic.CalculatorComposition.xml"); context.GetComponent <IProgramRunner>().Run(); }
static void Main() { var composer = new ComponentContext(); composer.Register(typeof(DefaultLogger)); composer.GetComponent <ILogger>().Log("Hello, compositional world!"); }
public void ReqPlugProvided() { _context.Register(typeof(ComponentWithRequiredPlug)); _context.Register(typeof(PluggedComponent)); var c = _context.GetComponent <ComponentWithRequiredPlug>(); Assert.IsNotNull(c); Assert.IsNotNull(c.PluggedContract); }
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>(); }
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(); }