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);
        }
        public void Should_have_CreateObjects_method()
        {
            ObjectFactory objectFactory = new ObjectFactory();

            objectFactory.AddClass(typeof(Dummy));
            objectFactory.CreateObjects();
        }
        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));
        }
        public void Should_have_GetObject_method()
        {
            ObjectFactory objectFactory = new ObjectFactory();

            objectFactory.AddClass(typeof(Dummy));
            objectFactory.CreateObjects();
            /*Dummy dummy = (Dummy)*/ objectFactory.GetObject(typeof(Dummy));
        }
        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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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]);
        }
Exemplo n.º 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" }));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
        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"));
        }