コード例 #1
0
        public void Create_WithClassTypeAsParameter_ReturnsCorrectClass()
        {
            var classFactory = new ActivatorClassFactory();

            var instance = classFactory.Create(typeof(ActivatorTestClass));

            Assert.IsType <ActivatorTestClass>(instance);
        }
コード例 #2
0
        public void Create_GenericWithClassTypeAsGenericParameter_ReturnsCorrectClass()
        {
            var classFactory = new ActivatorClassFactory <ActivatorTestClass>();

            var instance = classFactory.Create();

            Assert.IsType <ActivatorTestClass>(instance);
        }
コード例 #3
0
        public void Create_GenericWithSetupWithClassTypeAsGenericParameter_ReturnsCorrectClass()
        {
            var classFactory = new ActivatorClassFactory <ActivatorTestClass>();

            var instance = classFactory.Create(x => x.Text = "abcd");

            Assert.IsType <ActivatorTestClass>(instance);
            Assert.Equal("abcd", instance.Text);
        }
コード例 #4
0
        public void Create_WithSetupWithClassTypeAsParameter_ReturnsCorrectClass()
        {
            var classFactory = new ActivatorClassFactory();

            var instance = classFactory.Create(typeof(ActivatorTestClass), x => ((ActivatorTestClass)x).Text = "1234");

            Assert.IsType <ActivatorTestClass>(instance);
            Assert.Equal("1234", ((ActivatorTestClass)instance).Text);
        }
コード例 #5
0
        public void Create_GenericWithSetupWithClassTypeAsGenericParameterForWrongType_ThrowsException()
        {
            var classFactory = new ActivatorClassFactory <ActivatorTestClassWithCtorParameters>();

            Assert.Throws <MissingMethodException>(() => classFactory.Create(x => x.Text = "abcd"));
        }
コード例 #6
0
        public void Create_WithClassTypeAsParameterWithCtorParameters_ThrowsException()
        {
            var classFactory = new ActivatorClassFactory();

            Assert.Throws <MissingMethodException>(() => classFactory.Create(typeof(ActivatorTestClassWithCtorParameters)));
        }