private static IRequestClient AugmentClient(SimpleContainer container) { var progress = container.Get <IProgressService>(); var handler = container.Get <IRequestClient>(); return(new ErrorHandlingRestClient(new ProgressAwareRestClient(handler, progress))); }
private static IRequestClient AugmentClient(SimpleContainer container) { var progress = container.Get<IProgressService>(); var handler = container.Get<IRequestClient>(); return new ErrorHandlingRestClient(new ProgressAwareRestClient(handler, progress)); }
public void SupportCtors() { var c = new SimpleContainer(); c.Register(new BasicComponentDefinition { ServiceType = typeof(IA), ImplementationType = typeof(A) }); var a1 = c.Get <IA>(); var a2 = c.Get <IA>(null, 23); Assert.AreEqual(1, a1.Val); Assert.AreEqual(23, a2.Val); }
public void TestNoAction() { MockHttpContextHandler.MockAppRelativeCurrentExecutionFilePath = "~/my/nothing/first/1/1/2"; var p = SimpleContainer.Get <MvcProcessor>(); p.Process(); }
public void Test4() { var item = SimpleContainer.Get <IocConstractor>(); Assert.IsNotNull(item); Assert.AreEqual("2nd impl", item.Run()); }
public void Test1() { var t = SimpleContainer.Get <ITest>(); Assert.IsNotNull(t); Assert.IsTrue(t is NewTestImpl); var t1 = SimpleContainer.Get <ITest>(1); Assert.IsNotNull(t1); Assert.IsTrue(t1 is TestImpl); var t2 = SimpleContainer.Get <ITest>(2); Assert.IsNotNull(t2); Assert.IsTrue(t2 is NewTestImpl); var t3 = SimpleContainer.Get <IocSame>(1); Assert.IsNotNull(t3); Assert.AreEqual("same", t3.Run()); var t4 = SimpleContainer.Get <IocSame>(3); Assert.IsNotNull(t4); Assert.IsTrue(t4 is IocSameSub); Assert.AreEqual("sub class", t4.Run()); }
public void does_not_request_instance_more_than_once() { // configure DI provider var services = new SimpleContainer(); services.Singleton <StarWarsData>(); // mock it so we can verify behavior var mock = new Mock <IServiceProvider>(MockBehavior.Loose); mock.Setup(x => x.GetService(It.IsAny <Type>())).Returns <Type>(type => services.Get(type)); // run test var schema = new StarWarsSchema(mock.Object); schema.Initialize(); // verify that GetService was only called once for each schema type mock.Verify(x => x.GetService(typeof(StarWarsQuery)), Times.Once); mock.Verify(x => x.GetService(typeof(StarWarsMutation)), Times.Once); mock.Verify(x => x.GetService(typeof(CharacterInterface)), Times.Once); mock.Verify(x => x.GetService(typeof(DroidType)), Times.Once); mock.Verify(x => x.GetService(typeof(HumanInputType)), Times.Once); mock.Verify(x => x.GetService(typeof(HumanType)), Times.Once); mock.Verify(x => x.GetService(typeof(EpisodeEnum)), Times.Once); mock.Verify(x => x.GetService(typeof(IEnumerable <IConfigureSchema>)), Times.Once); mock.VerifyNoOtherCalls(); }
public void TestAdd() { MockHttpContextHandler.MockAppRelativeCurrentExecutionFilePath = "~/my/add/13/25"; var p = SimpleContainer.Get <MvcProcessor>(); p.Process(); Assert.AreEqual(38, MyView.Controller["Result"]); }
public void TestGetAll() { MockHttpContextHandler.MockAppRelativeCurrentExecutionFilePath = "~/test/getall/test/ok/3rd/18/30"; var p = SimpleContainer.Get <MvcProcessor>(); p.Process(); Assert.AreEqual("test|ok|3rd|18|30", MockHttpContextHandler.LastWriteMessage); }
public void TestAdd() { MockHttpContextHandler.MockAppRelativeCurrentExecutionFilePath = "~/test/add/13/25"; var p = SimpleContainer.Get <MvcProcessor>(); p.Process(); Assert.AreEqual("38", MockHttpContextHandler.LastWriteMessage); }
public void TestTry() { MockHttpContextHandler.MockAppRelativeCurrentExecutionFilePath = "~/my/try/first"; var p = SimpleContainer.Get <MvcProcessor>(); p.Process(); Assert.AreEqual("first", MyView.Controller["s1"]); Assert.AreEqual(null, MyView.Controller["s2"]); }
public void Test2() { SimpleContainer.Register(typeof(IocSame), typeof(IocSameReg), 4, null); var t = SimpleContainer.Get <IocSame>(4); Assert.IsNotNull(t); Assert.AreEqual("reg class", t.Run()); Assert.IsNotNull(t.TestProperty); Assert.AreEqual("2nd impl", t.TestProperty.Run()); }
public void TestGetAll() { MockHttpContextHandler.MockAppRelativeCurrentExecutionFilePath = "~/my/getall/3rd/18/30"; var p = SimpleContainer.Get <MvcProcessor>(); p.Process(); Assert.AreEqual("3rd", MyView.Controller["s1"]); Assert.AreEqual("18", MyView.Controller["s2"]); Assert.AreEqual("30", MyView.Controller["s3"]); }
public void TestGet() { MockHttpContextHandler.MockAppRelativeCurrentExecutionFilePath = "~/my/get/ok/18/30"; var p = SimpleContainer.Get <MvcProcessor>(); p.Process(); Assert.AreEqual("ok", MyView.Controller["s1"]); Assert.AreEqual(18, MyView.Controller["i2"]); Assert.AreEqual(30, MyView.Controller["l3"]); }
static NameMapper() { if (CoreSettings.NameMapper.StartsWith("@")) { Instance = SimpleContainer.Get <NameMapper>(CoreSettings.NameMapper.Substring(1)); } else { Instance = (NameMapper)ClassHelper.CreateInstance(CoreSettings.NameMapper); } }
static NameMapper() { var nameMapper = ConfigReader.Config.Database.NameMapper; if (nameMapper.StartsWith("@")) { Instance = SimpleContainer.Get <NameMapper>(nameMapper.Substring(1)); } else { Instance = (NameMapper)ClassHelper.CreateInstance(nameMapper); } }
public void TestName() { var item = SimpleContainer.Get <ITest>("test"); Assert.IsNotNull(item); Assert.AreEqual("1st impl", item.Run()); item = SimpleContainer.Get <ITest>("test2"); Assert.IsNotNull(item); Assert.AreEqual("2nd impl", item.Run()); item = SimpleContainer.Get <ITest>("test3"); Assert.IsNotNull(item); Assert.AreEqual("3rd impl", item.Run()); }
private ISimpleContainer BuildContainer() { var container = new SimpleContainer(); container.Singleton<IDocumentExecuter>(new DocumentExecuter()); container.Singleton<IDocumentWriter>(new DocumentWriter(true)); container.Singleton(new StarWarsData()); container.Register<StarWarsQuery>(); container.Register<HumanType>(); container.Register<DroidType>(); container.Register<CharacterInterface>(); container.Singleton(new StarWarsSchema(type => (GraphType) container.Get(type))); return container; }
private ISimpleContainer BuildContainer() { var container = new SimpleContainer(); container.Singleton <IDocumentExecuter>(new DocumentExecuter()); container.Singleton <IDocumentWriter>(new DocumentWriter(true)); container.Singleton(new DbzData()); container.Register <DbzQuery>(); container.Register <SaiyajinType>(); container.Register <EarthmanType>(); container.Register <CharacterInterface>(); container.Singleton(new DbzSchema(type => (GraphType)container.Get(type))); return(container); }
public void ProcessRequest(HttpContext context) { try { var p = SimpleContainer.Get <MvcProcessor>(); p.Process(); } catch (ThreadAbortException) { throw; } catch (Exception ex) { ControllerHelper.OnException(ex); } }
public void Schemas_Align() { var schemaGenerator = new SchemaGenerator(new MockServiceProvider()); var schema = schemaGenerator.CreateSchema(typeof(StarWarsAttributeSchema)); var container = new SimpleContainer(); container.Singleton(new StarWarsData()); container.Register <StarWarsQuery>(); container.Register <HumanType>(); container.Register <DroidType>(); container.Register <CharacterInterface>(); var manualSchema = new StarWarsSchema(type => (GraphType)container.Get(type)); Assert.Equal(manualSchema.Query.Fields.Count(), schema.Query.Fields.Count()); Assert.Equal(manualSchema.AllTypes.Count(), schema.AllTypes.Count() + 1); //todo work on enum }
public static ILogRecorder GetLogRecorder(string name) { lock (Jar) { if (Jar.ContainsKey(name)) { return(Jar[name]); } var ilc = name.StartsWith("@") ? SimpleContainer.Get <ILogRecorder>(name.Substring(1)) : (ILogRecorder)ClassHelper.CreateInstance(name); if (ilc == null) { throw new SettingException(); } Jar[name] = ilc; return(ilc); } }
private ISimpleContainer BuildContainer() { var container = new SimpleContainer(); container.Singleton <IDocumentExecuter>(new DocumentExecuter()); container.Singleton <IDocumentWriter>(new DocumentWriter(true)); container.Singleton(new StarWarsData()); container.Register <StarWarsQuery>(); container.Register <StarWarsMutation>(); container.Register <HumanType>(); container.Register <HumanInputType>(); container.Register <DroidType>(); container.Register <CharacterInterface>(); container.Singleton <ISchema>(new StarWarsSchema(new FuncServiceProvider(type => container.Get(type)))); return(container); }
public void when_one_transient_configuration_without_dependencies_registered_then_resolves_type_correctly() { _sut.Register <Interfaze, Clazz>(); Assert.That(_sut.Get <Interfaze>(), Is.InstanceOf(typeof(Clazz))); }