CreateObjects() public method

public CreateObjects ( ) : void
return void
 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_have_DisposeObjects_method()
 {
     ObjectFactory objectFactory = new ObjectFactory();
     objectFactory.AddClass(typeof(Dummy));
     objectFactory.CreateObjects();
     objectFactory.DisposeObjects();
 }
Esempio n. 3
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);
 }
Esempio n. 4
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_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);
 }
Esempio n. 6
0
        public string Process(string request)
        {
            try
            {
                JArray requestObject = JArray.Parse(request);
                var    command       = requestObject[0].Value <string>();
                switch (command)
                {
                case "begin_scenario":
                {
                    _objectFactory.CreateObjects();
                    var scenarioTags = GetScenarioTags(requestObject);
                    _repository.BeforeHooks.ForEach(hook => hook.Invoke(_objectFactory, scenarioTags));
                    return(SuccessResponse());
                }

                case "end_scenario":
                {
                    var scenarioTags = GetScenarioTags(requestObject);
                    _repository.AfterHooks.ForEach(hook => hook.Invoke(_objectFactory, scenarioTags));
                    _objectFactory.DisposeObjects();
                    return(SuccessResponse());
                }

                case "step_matches":
                {
                    var nameToMatch = ((JObject)requestObject[1])["name_to_match"].Value <string>();
                    return(StepMatches(nameToMatch));
                }

                case "snippet_text":
                {
                    var keyword           = ((JObject)requestObject[1])["step_keyword"].Value <string>().Trim();
                    var stepName          = ((JObject)requestObject[1])["step_name"].Value <string>();
                    var multilineArgClass = ((JObject)requestObject[1])["multiline_arg_class"].Value <string>();
                    return(SnippetResponse(keyword, stepName, multilineArgClass));
                }

                case "invoke":
                {
                    var jsonArgs = (JArray)((JObject)requestObject[1])["args"];
                    return(Invoke(requestObject[1]["id"].Value <string>(), ToStringArray(jsonArgs)));
                }

                default:
                {
                    return(FailResponse("Invalid request '" + request + "'"));
                }
                }
            }
            catch (Exception x)
            {
                Debug.LogError("Unable to process request '" + request + "': " + x.Message);
                return(FailResponse(x));
            }
        }
 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);
 }
 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"));
 }
 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_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"}));
 }
 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]);
 }