コード例 #1
0
        public void Should_return_null_from_GetObject_if_CreateObjects_not_called_first()
        {
            ObjectFactory objectFactory = new ObjectFactory();

            objectFactory.AddClass(typeof(Dummy));
            Assert.That(objectFactory.GetObject(typeof(Dummy)), Is.Null);
        }
コード例 #2
0
        public void Should_have_CreateObjects_method()
        {
            ObjectFactory objectFactory = new ObjectFactory();

            objectFactory.AddClass(typeof(Dummy));
            objectFactory.CreateObjects();
        }
コード例 #3
0
        public void Should_successfully_create_an_object_without_a_parameterless_constructor()
        {
            ObjectFactory objectFactory = new ObjectFactory();

            objectFactory.AddClass(typeof(DummyBox));
            objectFactory.CreateObjects();
            /*DummyBox dummyBox = (DummyBox)*/ objectFactory.GetObject(typeof(DummyBox));
        }
コード例 #4
0
        public void Should_have_GetObject_method()
        {
            ObjectFactory objectFactory = new ObjectFactory();

            objectFactory.AddClass(typeof(Dummy));
            objectFactory.CreateObjects();
            /*Dummy dummy = (Dummy)*/ objectFactory.GetObject(typeof(Dummy));
        }
コード例 #5
0
        public void Should_return_null_from_GetObject_after_DisposeObjects_is_called()
        {
            ObjectFactory objectFactory = new ObjectFactory();

            objectFactory.AddClass(typeof(Dummy));
            objectFactory.CreateObjects();
            Assert.That(objectFactory.GetObject(typeof(Dummy)), Is.Not.Null);
            objectFactory.DisposeObjects();
            Assert.That(objectFactory.GetObject(typeof(Dummy)), Is.Null);
        }
コード例 #6
0
        public void Successful_invocation_of_instance_should_not_throw()
        {
            var objectFactory = new ObjectFactory();

            objectFactory.AddClass(typeof(ValidStepDefinitions));
            objectFactory.CreateObjects();
            var stepDefinition = new StepDefinition(GetValidMethod("Instance"));

            stepDefinition.Invoke(objectFactory);
        }
コード例 #7
0
        public void Should_not_invoke_tagged_hook_when_scenario_has_no_tags()
        {
            ObjectFactory objectFactory = new ObjectFactory();

            objectFactory.AddClass(typeof(ValidHooks));
            objectFactory.CreateObjects();
            var method = Reflection.GetMethod(typeof(ValidHooks), "BeforeWithTagThrowsException");
            var hook   = new Hook(method);

            hook.Invoke(objectFactory, new string[0]);
        }
コード例 #8
0
        public void Should_invoke_tagged_hook_when_scenario_has_matching_tag()
        {
            ObjectFactory objectFactory = new ObjectFactory();

            objectFactory.AddClass(typeof(ValidHooks));
            objectFactory.CreateObjects();
            var method = Reflection.GetMethod(typeof(ValidHooks), "BeforeWithTagThrowsException");
            var hook   = new Hook(method);

            Assert.Throws <Exception>(() => hook.Invoke(objectFactory, new string[] { "my_tag" }));
        }
コード例 #9
0
        public void Should_invoke_method_successfully()
        {
            ObjectFactory objectFactory = new ObjectFactory();

            objectFactory.AddClass(typeof(ValidHooks));
            objectFactory.CreateObjects();
            var method = Reflection.GetMethod(typeof(ValidHooks), "Before1");
            var hook   = new Hook(method);

            hook.Invoke(objectFactory);
        }
コード例 #10
0
        public void Invoke_should_throw_when_method_throws()
        {
            ObjectFactory objectFactory = new ObjectFactory();

            objectFactory.AddClass(typeof(ValidHooks));
            objectFactory.CreateObjects();
            var method = Reflection.GetMethod(typeof(ValidHooks), "ThrowsException");
            var hook   = new Hook(method);

            hook.Invoke(objectFactory);
        }
コード例 #11
0
        public void Should_return_same_object_from_multiple_GetObject_calls()
        {
            ObjectFactory objectFactory = new ObjectFactory();

            objectFactory.AddClass(typeof(Dummy));
            objectFactory.CreateObjects();
            Dummy dummy1 = (Dummy)objectFactory.GetObject(typeof(Dummy));

            dummy1.Value = "foo";
            Dummy dummy2 = (Dummy)objectFactory.GetObject(typeof(Dummy));

            Assert.That(dummy2.Value, Is.EqualTo("foo"));
        }