コード例 #1
0
        public void NonMathcingFieldTest()
        {
            var context = new RIContext();

            try
            {
                var classInstanceProvider = new ComplexInstanceProvider(
                    typeof(Address),
                    new IInstanceProvider[]
                {
                },
                    new Dictionary <string, IInstanceProvider>()
                {
                    { "AddressLine1", new SimpleInstanceProvider("Vesterbygdvej 10") },
                    { "ZipCode", new SimpleInstanceProvider("3650") }
                }
                    );
                Assert.Fail("A NoMatchingPropertyException was expected.");
            }
            catch (NoMatchingPropertyException)
            {
            }
            catch (Exception)
            {
                Assert.Fail("Another exception than NoMatchingPropertyException was not expected.");
            }
        }
コード例 #2
0
        public void NonMathcingContructorClassTypeTest()
        {
            var context = new RIContext();

            var genderInstanceProvider = new EnumInstanceProvider(Gender.Male, typeof(Gender));
            var nameInstanceProvider   = new SimpleInstanceProvider("Jørgen");

            try
            {
                var classInstanceProvider = new ComplexInstanceProvider(
                    typeof(Person),
                    new IInstanceProvider[] {
                    genderInstanceProvider,
                    nameInstanceProvider,
                },
                    new Dictionary <string, IInstanceProvider>()
                {
                    { "Birthday", new SimpleInstanceProvider(new DateTime(1966, 7, 14)) },
                }
                    );
                Assert.Fail("A NoMatchingConstructorException was expected.");
            }
            catch (NoMatchingConstructorException)
            {
            }
            catch (Exception)
            {
                Assert.Fail("Another exception than NoMatchingConstructorException was not expected.");
            }
        }
コード例 #3
0
        public void NonMathcingPropertyTest()
        {
            var context = new RIContext();

            var nameInstanceProvider   = new SimpleInstanceProvider("Jørgen");
            var ageInstanceProvider    = new SimpleInstanceProvider(49);
            var genderInstanceProvider = new EnumInstanceProvider(Gender.Male, typeof(Gender));

            try
            {
                var classInstanceProvider = new ComplexInstanceProvider(
                    typeof(Person),
                    new IInstanceProvider[] {
                    nameInstanceProvider,
                    ageInstanceProvider,
                    genderInstanceProvider
                },
                    new Dictionary <string, IInstanceProvider>()
                {
                    { "Shoe Size", new SimpleInstanceProvider(44) },
                }
                    );
                Assert.Fail("A NoMatchingPropertyException was expected.");
            }
            catch (NoMatchingPropertyException)
            {
            }
            catch (Exception)
            {
                Assert.Fail("Another exception than NoMatchingPropertyException was not expected.");
            }
        }
コード例 #4
0
        public void ClassTypeTest()
        {
            var context = new RIContext();

            var nameInstanceProvider   = new SimpleInstanceProvider("Jørgen");
            var ageInstanceProvider    = new SimpleInstanceProvider(49);
            var genderInstanceProvider = new EnumInstanceProvider(Gender.Male, typeof(Gender));

            var dateOfBirth = new DateTime(1966, 7, 14);

            var classInstanceProvider = new ComplexInstanceProvider(
                typeof(Person),
                new IInstanceProvider[] {
                nameInstanceProvider,
                ageInstanceProvider,
                genderInstanceProvider
            },
                new Dictionary <string, IInstanceProvider>()
            {
                { "Birthday", new SimpleInstanceProvider(dateOfBirth) },
            }
                );

            context.AddNamedInstanceProvider("A", classInstanceProvider);

            var person = context.GetInstance <Person>("A");

            Assert.AreEqual("Jørgen", person.Name);

            var now = DateTime.Today;
            var age = now.Year - dateOfBirth.Year + (now.DayOfYear >= dateOfBirth.DayOfYear ? 0 : -1);

            Assert.AreEqual(age, person.Age);
            Assert.AreEqual(Gender.Male, person.Gender);
        }
コード例 #5
0
        public void MathcingFieldTest()
        {
            var context = new RIContext();

            var classInstanceProvider = new ComplexInstanceProvider(
                typeof(Address),
                new IInstanceProvider[]
            {
            },
                new Dictionary <string, IInstanceProvider>()
            {
                { "AddressLine1", new SimpleInstanceProvider("Vesterbygdvej 10") },
                { "City", new SimpleInstanceProvider("Ølstykke") }
            }
                );
        }