Beispiel #1
0
        public void Then_the_dictionary_key_and_value_must_be_injected_with_inline_objects()
        {
            const string dictionaryId = "dicid";

            FluentApplicationContext.Register <TestObject>(dictionaryId)
            .Bind(x => x.TestObjectKeyValueDictionary).ToDefinition(
                Inline.Dictionary <TestObject, TestObject>()
                .AddEntry()
                .WithKeyDefinition(
                    Inline.Object <TestObject>()
                    .Bind(x => x.PropertyX).To("somekeyvalue")
                    )
                .AndValueDefinition(
                    Inline.Object <TestObject>()
                    .Bind(x => x.PropertyX).To("somevalue"))
                );

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var initialisedObject = applicationContext.GetObject <TestObject>(dictionaryId);

            Assert.IsTrue(initialisedObject.TestObjectKeyValueDictionary.Keys.Where(l => l.PropertyX.Equals("somekeyvalue")).Count() > 0);
            Assert.IsTrue(initialisedObject.TestObjectKeyValueDictionary.Values.Where(l => l.PropertyX.Equals("somevalue")).Count() > 0);
            Assert.AreEqual("somevalue", initialisedObject.TestObjectKeyValueDictionary.Where(k => k.Value.PropertyX.Equals("somevalue")).Single().Value.PropertyX);
        }
Beispiel #2
0
        public void Then_the_object_must_be_initialised_with_the_right_values_when_passed_by_index_and_inline_definition()
        {
            FluentApplicationContext.Register<ObjectWithConstructor>("object")
                .BindConstructorArgumentAtIndex<TestObject>(0).ToDefinition(
                    Inline.Object<TestObject>().Bind(t => t.PropertyX).To("somevalue"));

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var initialisedObject = (ObjectWithConstructor) applicationContext.GetObject("object");

            Assert.AreEqual("somevalue", initialisedObject.TestObject.PropertyX);
        }
        public void Then_the_list_can_contain_inline_definition()
        {
            FluentApplicationContext.Register <TestObject>()
            .Bind(x => x.ListOfTestObjects).ToDefinition(
                Inline.List <TestObject>()
                .AddDefinition(Inline.Object <TestObject>().Bind(x => x.PropertyX).To("blah"))
                );

            IApplicationContext context = _applicationContextContainer.InitialiseContext();

            var testObject = context.GetObject <TestObject>();

            Assert.IsNotNull(testObject.ListOfTestObjects);
            Assert.AreEqual("blah", testObject.ListOfTestObjects[0].PropertyX);
        }
        public void Then_the_object_property_must_be_initialised()
        {
            const string identifier  = "myobjectname";
            const string myTestValue = "mytestvalue";

            FluentApplicationContext.Register <TestObject>().Bind(t => t.PropertyX).To("somevalue");

            FluentApplicationContext.Register <ObjectWithProperties>(identifier)
            .Bind(x => x.TestObject)
            .ToDefinition(Inline.Object <TestObject>()
                          .Bind(t => t.PropertyX).To(myTestValue));

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var initialisedObject = (ObjectWithProperties)applicationContext.GetObject(identifier);

            Assert.AreEqual(myTestValue, initialisedObject.TestObject.PropertyX);
        }
        public void Then_the_inline_definition_must_not_clash_with_other_defined_definitions_of_same_type()
        {
            const string identifier     = "myobjectname";
            const string myTestValue    = "mytestvalue";
            const string myOrignalValue = "original";

            FluentApplicationContext.Register <TestObject>().Bind(t => t.PropertyX).To(myOrignalValue);

            FluentApplicationContext.Register <ObjectWithProperties>(identifier)
            .Bind(x => x.TestObject)
            .ToDefinition(Inline.Object <TestObject>()
                          .Bind(t => t.PropertyX).To(myTestValue));

            IApplicationContext applicationContext = _applicationContextContainer.InitialiseContext();

            var initialisedObject = (TestObject)applicationContext.GetObject(typeof(TestObject).FullName);

            Assert.AreEqual(myOrignalValue, initialisedObject.PropertyX);
        }
Beispiel #6
0
        public void Demo()
        {
            FluentApplicationContext.Register <TestObject>()
            .AsNonSingleton()
            .Bind(x => x.PropertyX).To("a value");


            FluentApplicationContext.Register <TestObject>().Bind(x => x.PropertyX).To <String>();

            FluentApplicationContext.Register <TestObject>().Bind(x => x.PropertyX).To <String>("something");

            FluentApplicationContext.Register <TestObject>().Bind(x => x.PropertyX).To("something");

            FluentApplicationContext.Register <TestObject>().Bind(x => x.SomeDictionary).ToDefinition(
                Inline.Dictionary <string, String>()
                .AddEntry().WithKey <String>().AndValue("adsf")
                .AddEntry().WithKey("asdfasdf").AndValue <String>()
                .AddEntry().WithKey("asdfasdf").AndValueDefinition(
                    Inline.Object <String>()
                    .Bind(x => x.ToString()).To("1"))
                .AddEntry()
                .WithKeyDefinition(
                    Inline.Object <string>())
                .AndValueDefinition(
                    Inline.Object <String>()
                    .Bind(x => x.ToString()).To("1"))
                );

            Inline.Dictionary <string, string>()
            .AddEntry().WithKey <String>().AndValue("adsf")
            .AddEntry().WithKey("asdfasdf").AndValue <String>();

            FluentApplicationContext.Register <TestObject>()
            .BindConstructorArgument <String>()
            .ToDefinition(Inline.Object <String>());

            FluentApplicationContext.Bind <IDictionary <string, string> >()
            .To <Dictionary <string, string> >().When(Is.RunningEnvironment("PROD"));
        }