public void OneObjectDirectProperty() { var container = new SimpleServiceContainer(); { StObjCollector collector = new StObjCollector(TestHelper.Monitor, container); collector.RegisterType(typeof(SimpleObjectDirect)); var map = collector.GetResult().EngineMap; Debug.Assert(map != null, "No initialization error."); map.StObjs.Obtain <SimpleObjectDirect>() !.OneIntValue.Should().Be(3712, "Direct properties can be set by Attribute."); } { StObjCollector collector = new StObjCollector(TestHelper.Monitor, container, configurator: new ConfiguratorOneIntValueSetTo42()); collector.RegisterType(typeof(SimpleObjectDirect)); var map = collector.GetResult().EngineMap; Debug.Assert(map != null, "No initialization error."); map.StObjs.Obtain <SimpleObjectDirect>() !.OneIntValue.Should().Be(42, "Direct properties can be set by any IStObjStructuralConfigurator participant (here the global one)."); } }
public void OneObjectAmbientProperty() { var container = new SimpleServiceContainer(); { StObjCollector collector = new StObjCollector(TestHelper.Monitor, container); collector.RegisterType(typeof(SimpleObjectAmbient)); var map = collector.GetResult().EngineMap; Debug.Assert(map != null, "No initialization error."); map.StObjs.OrderedStObjs.Should().NotBeEmpty("We registered SimpleObjectAmbient."); map.StObjs.Obtain <SimpleObjectAmbient>() !.OneIntValue.Should().Be(3712, "Same as Direct properties (above) regarding direct setting. The difference between Ambient and non-ambient lies in value propagation."); } { StObjCollector collector = new StObjCollector(TestHelper.Monitor, container, configurator: new ConfiguratorOneIntValueSetTo42()); collector.RegisterType(typeof(SimpleObjectAmbient)); var map = collector.GetResult().EngineMap; Debug.Assert(map != null, "No initialization error."); map.StObjs.Obtain <SimpleObjectAmbient>() !.OneIntValue.Should().Be(42, "Same as Direct properties (above) regarding direct setting. The difference between Ambient and non-ambient lies in value propagation."); } }
public void AmbientOrDirectPropertyDeclaredInBaseClassCanBeSet() { var container = new SimpleServiceContainer(); { StObjCollector collector = new StObjCollector(TestHelper.Monitor, container); collector.RegisterType(typeof(SpecializedObjectDirect)); var map = collector.GetResult().EngineMap; Debug.Assert(map != null, "No initialization error."); map.StObjs.OrderedStObjs.Select(o => o.ClassType).Should().Contain(new[] { typeof(SpecializedObjectDirect), typeof(SimpleObjectDirect) }); map.StObjs.Obtain <SpecializedObjectDirect>() !.OneIntValue.Should().Be(999, "Direct properties can be set by Attribute (or any IStObjStructuralConfigurator)."); } { StObjCollector collector = new StObjCollector(TestHelper.Monitor, container); collector.RegisterType(typeof(SpecializedObjectAmbient)); var map = collector.GetResult().EngineMap; Debug.Assert(map != null, "No initialization error."); map.StObjs.OrderedStObjs.Select(o => o.ClassType).Should().Contain(new[] { typeof(SpecializedObjectAmbient), typeof(SimpleObjectAmbient) }); map.StObjs.Obtain <SpecializedObjectAmbient>() !.OneIntValue.Should().Be(999, "Ambient properties can be set by Attribute (or any IStObjStructuralConfigurator)."); } }