http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Tests/TangTests/Injection/TestForkInjection.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Injection/TestForkInjection.cs b/lang/cs/Tests/TangTests/Injection/TestForkInjection.cs deleted file mode 100644 index 2d9dde5..0000000 --- a/lang/cs/Tests/TangTests/Injection/TestForkInjection.cs +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Org.Apache.Reef.Tang.Examples; -using Org.Apache.Reef.Tang.Implementations; -using Org.Apache.Reef.Tang.Interface; -using Org.Apache.Reef.Tang.Util; -using System; -using System.Reflection; - -namespace Org.Apache.Reef.Tang.Test.Injection -{ - [TestClass] - public class TestForkInjection - { - static Assembly asm = null; - - [ClassInitialize] - public static void ClassSetup(TestContext context) - { - asm = Assembly.Load(FileNames.Examples); - } - - [ClassCleanup] - public static void ClassCleanup() - { - } - - [TestInitialize()] - public void TestSetup() - { - } - - [TestCleanup()] - public void TestCleanup() - { - } - - [TestMethod] - public void TestForksInjectorInConstructor() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(new string[] { FileNames.Examples }); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance(typeof(ForksInjectorInConstructor)); - } - - [TestMethod] - public void TestForkWorks() - { - Type checkChildIfaceType = typeof(CheckChildIface); - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(new string[] { FileNames.Examples }); - cb.BindImplementation(GenericType<CheckChildIface>.Class, GenericType<CheckChildImpl>.Class); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - IInjector i1 = i.ForkInjector(); - CheckChildIface c1 = (CheckChildIface)i1.GetInstance(checkChildIfaceType); - IInjector i2 = i.ForkInjector(); - CheckChildIface c2 = (CheckChildIface)i2.GetInstance(checkChildIfaceType); - Assert.AreNotEqual(c1, c2); - } - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Tests/TangTests/Injection/TestInjection.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Injection/TestInjection.cs b/lang/cs/Tests/TangTests/Injection/TestInjection.cs deleted file mode 100644 index 4e765bc..0000000 --- a/lang/cs/Tests/TangTests/Injection/TestInjection.cs +++ /dev/null @@ -1,386 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Org.Apache.Reef.Tang.Annotations; -using Org.Apache.Reef.Tang.Examples; -using Org.Apache.Reef.Tang.Implementations; -using Org.Apache.Reef.Tang.Interface; -using Org.Apache.Reef.Tang.Util; -using Org.Apache.Reef.Tasks; -using System; -using System.Reflection; - -namespace Org.Apache.Reef.Tang.Test.Injection -{ - [DefaultImplementation(typeof(AReferenceClass))] - internal interface IAInterface - { - } - - [TestClass] - public class TestInjection - { - static Assembly asm = null; - - [ClassInitialize] - public static void ClassSetup(TestContext context) - { - asm = Assembly.Load(FileNames.Examples); - } - - [ClassCleanup] - public static void ClassCleanup() - { - } - - [TestInitialize()] - public void TestSetup() - { - } - - [TestCleanup()] - public void TestCleanup() - { - } - - [TestMethod] - public void TestTimer() - { - Type timerType = typeof(Timer); - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Examples }); - cb.BindNamedParameter<Timer.Seconds, int>(GenericType<Timer.Seconds>.Class, "2"); - IConfiguration conf = cb.Build(); - IInjector injector = tang.NewInjector(conf); - var timer = (Timer)injector.GetInstance(timerType); - - Assert.IsNotNull(timer); - - timer.sleep(); - } - - [TestMethod] - public void TestTimerWithClassHierarchy() - { - Type timerType = typeof(Timer); - - ClassHierarchyImpl classHierarchyImpl = new ClassHierarchyImpl(FileNames.Examples); - - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder((ICsClassHierarchy)classHierarchyImpl); - - cb.BindNamedParameter<Timer.Seconds, int>(GenericType<Timer.Seconds>.Class, "2"); - IConfiguration conf = cb.Build(); - - IInjector injector = tang.NewInjector(conf); - var timer = (Timer)injector.GetInstance(timerType); - - Assert.IsNotNull(timer); - - timer.sleep(); - } - - [TestMethod] - public void TestDocumentLoadNamedParameter() - { - Type documentedLocalNamedParameterType = typeof(DocumentedLocalNamedParameter); - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Examples }); - cb.BindNamedParameter<DocumentedLocalNamedParameter.Foo, string>(GenericType<DocumentedLocalNamedParameter.Foo>.Class, "Hello"); - IConfiguration conf = cb.Build(); - IInjector injector = tang.NewInjector(conf); - var doc = (DocumentedLocalNamedParameter)injector.GetInstance(documentedLocalNamedParameterType); - - Assert.IsNotNull(doc); - } - - [TestMethod] - public void TestDocumentLoadNamedParameterWithDefaultValue() - { - ITang tang = TangFactory.GetTang(); - IConfiguration conf = tang.NewConfigurationBuilder(new string[] { FileNames.Examples }).Build(); - IInjector injector = tang.NewInjector(conf); - var doc = (DocumentedLocalNamedParameter)injector.GetInstance(typeof(DocumentedLocalNamedParameter)); - - Assert.IsNotNull(doc); - } - - [TestMethod] - public void TestSimpleConstructor() - { - Type simpleConstructorType = typeof(SimpleConstructors); - - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Examples }); - IConfiguration conf = cb.Build(); - IInjector injector = tang.NewInjector(conf); - var simpleConstructor = (SimpleConstructors)injector.GetInstance(simpleConstructorType); - Assert.IsNotNull(simpleConstructor); - } - - [TestMethod] - public void TestActivity() - { - Type activityType = typeof(HelloTask); - - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Tasks, FileNames.Common }); - IConfiguration conf = cb.Build(); - IInjector injector = tang.NewInjector(conf); - var activityRef = (ITask)injector.GetInstance(activityType); - Assert.IsNotNull(activityRef); - } - - [TestMethod] - public void TestStreamActivity1() - { - Type activityType = typeof(StreamTask1); - - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Tasks, FileNames.Common }); - IConfiguration conf = cb.Build(); - IInjector injector = tang.NewInjector(conf); - var activityRef = (ITask)injector.GetInstance(activityType); - Assert.IsNotNull(activityRef); - } - - [TestMethod] - public void TestStreamActivity2() - { - Type activityType = typeof(StreamTask2); - - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Tasks, FileNames.Common }); - IConfiguration conf = cb.Build(); - IInjector injector = tang.NewInjector(conf); - var activityRef = (ITask)injector.GetInstance(activityType); - Assert.IsNotNull(activityRef); - } - - [TestMethod] - public void TestMultipleAssemlies() - { - Type activityInterfaceType1 = typeof(ITask); - Type tweeterType = typeof(Tweeter); - - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Examples, FileNames.Tasks, FileNames.Common }); - cb.BindImplementation(GenericType<ITask>.Class, GenericType<HelloTask>.Class); - cb.BindImplementation(GenericType<ITweetFactory>.Class, GenericType<MockTweetFactory>.Class); - cb.BindImplementation(GenericType<ISMS>.Class, GenericType<MockSMS>.Class); - cb.BindNamedParameter<Tweeter.PhoneNumber, long>(GenericType<Tweeter.PhoneNumber>.Class, "8675309"); - - IConfiguration conf = cb.Build(); - IInjector injector = tang.NewInjector(conf); - var activityRef = (ITask)injector.GetInstance(activityInterfaceType1); - var tweeter = (Tweeter)injector.GetInstance(tweeterType); - - Assert.IsNotNull(activityRef); - Assert.IsNotNull(tweeter); - - tweeter.sendMessage(); - } - - [TestMethod] - public void TestActivityWithBinding() - { - Type activityInterfaceType = typeof(ITask); - - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Tasks, FileNames.Common }); - cb.BindImplementation(GenericType<ITask>.Class, GenericType<HelloTask>.Class); - cb.BindNamedParameter<TaskConfigurationOptions.Identifier, string>(GenericType<TaskConfigurationOptions.Identifier>.Class, "Hello Task"); - - IConfiguration conf = cb.Build(); - IInjector injector = tang.NewInjector(conf); - ITask activityRef1 = injector.GetInstance<ITask>(); - var activityRef2 = (ITask)injector.GetInstance(activityInterfaceType); - Assert.IsNotNull(activityRef2); - Assert.IsNotNull(activityRef1); - Assert.AreEqual(activityRef1, activityRef2); - } - - [TestMethod] - public void TestHelloStreamingActivityWithBinding() - { - Type activityInterfaceType = typeof(ITask); - - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Tasks, FileNames.Common }); - - cb.BindImplementation(GenericType<ITask>.Class, GenericType<HelloTask>.Class); - cb.BindNamedParameter<TaskConfigurationOptions.Identifier, string>(GenericType<TaskConfigurationOptions.Identifier>.Class, "Hello Stereamingk"); - cb.BindNamedParameter<StreamTask1.IpAddress, string>(GenericType<StreamTask1.IpAddress>.Class, "127.0.0.0"); - IConfiguration conf = cb.Build(); - IInjector injector = tang.NewInjector(conf); - var activityRef = (ITask)injector.GetInstance(activityInterfaceType); - Assert.IsNotNull(activityRef); - } - - [TestMethod] - public void TestTweetExample() - { - Type tweeterType = typeof(Tweeter); - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(new string[] { FileNames.Examples }); - - IConfiguration conf = cb.BindImplementation(GenericType<ITweetFactory>.Class, GenericType<MockTweetFactory>.Class) - .BindImplementation(GenericType<ISMS>.Class, GenericType<MockSMS>.Class) - .BindNamedParameter<Tweeter.PhoneNumber, long>(GenericType<Tweeter.PhoneNumber>.Class, "8675309") - .Build(); - IInjector injector = tang.NewInjector(conf); - var tweeter = (Tweeter)injector.GetInstance(tweeterType); - tweeter.sendMessage(); - - var sms = (ISMS)injector.GetInstance(typeof(ISMS)); - var factory = (ITweetFactory)injector.GetInstance(typeof(ITweetFactory)); - Assert.IsNotNull(sms); - Assert.IsNotNull(factory); - } - - [TestMethod] - public void TestReferenceType() - { - AReferenceClass o = (AReferenceClass)TangFactory.GetTang().NewInjector().GetInstance(typeof(IAInterface)); - } - - [TestMethod] - public void TestGeneric() - { - var o = (AGenericClass<int>)TangFactory.GetTang().NewInjector().GetInstance(typeof(AGenericClass<int>)); - var o2 = (AClassWithGenericArgument<int>)TangFactory.GetTang().NewInjector().GetInstance(typeof(AClassWithGenericArgument<int>)); - Assert.IsNotNull(o); - Assert.IsNotNull(o2); - } - - [TestMethod] - public void TestNestedClass() - { - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(); - - IConfiguration conf = cb - .BindNamedParameter<ClassParameter.Named1, int>(GenericType<ClassParameter.Named1>.Class, "5") - .BindNamedParameter<ClassParameter.Named2, string>(GenericType<ClassParameter.Named2>.Class, "hello") - .Build(); - - IInjector injector = tang.NewInjector(conf); - ClassHasNestedClass h = injector.GetInstance<ClassHasNestedClass>(); - - Assert.IsNotNull(h); - } - - [TestMethod] - public void TestExternalObject() - { - ITang tang = TangFactory.GetTang(); - ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(); - - IInjector injector = tang.NewInjector(cb.Build()); - - //bind an object to the injetor so that Tang will get this instance from cache directly instead of inject it when injecting ClassWithExternalObject - injector.BindVolatileInstance(GenericType<ExternalClass>.Class, new ExternalClass()); - ClassWithExternalObject o = injector.GetInstance<ClassWithExternalObject>(); - - Assert.IsNotNull(o.ExternalObject is ExternalClass); - } - } - - class AReferenceClass : IAInterface - { - [Inject] - public AReferenceClass(AReferenced refclass) - { - } - } - - class AReferenced - { - [Inject] - public AReferenced() - { - } - } - - class AGenericClass<T> - { - [Inject] - public AGenericClass() - { - } - } - - class AClassWithGenericArgument<T> - { - [Inject] - public AClassWithGenericArgument(AGenericClass<T> g) - { - } - } - - class ClassHasNestedClass - { - [Inject] - public ClassHasNestedClass(ClassParameter h1) - { - } - } - - class ClassParameter - { - private int i; - private string s; - - [Inject] - public ClassParameter([Parameter(typeof(Named1))] int i, [Parameter(typeof(Named2))] string s) - { - this.i = i; - this.s = s; - } - - [NamedParameter] - public class Named1 : Name<int> - { - } - - [NamedParameter] - public class Named2 : Name<string> - { - } - } - - class ClassWithExternalObject - { - [Inject] - public ClassWithExternalObject(ExternalClass ec) - { - ExternalObject = ec; - } - - public ExternalClass ExternalObject { get; set; } - } - - class ExternalClass - { - public ExternalClass() - { - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Tests/TangTests/Injection/TestInjectionFuture.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Injection/TestInjectionFuture.cs b/lang/cs/Tests/TangTests/Injection/TestInjectionFuture.cs deleted file mode 100644 index 17349e2..0000000 --- a/lang/cs/Tests/TangTests/Injection/TestInjectionFuture.cs +++ /dev/null @@ -1,240 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -using Org.Apache.Reef.Tang.Annotations; -using Org.Apache.Reef.Tang.Implementations; -using Org.Apache.Reef.Tang.Interface; -using Org.Apache.Reef.Tang.Util; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Org.Apache.Reef.Tang.Test.Injection -{ - interface IAinj - { - } - - [DefaultImplementation(typeof(C), "C")] - interface IBinj : IAinj - { - } - - [TestClass] - public class TestInjectionFuture - { - [TestMethod] - public void TestProactiveFutures() - { - IInjector i = TangFactory.GetTang().NewInjector(); - IsFuture.Instantiated = false; - i.GetInstance(typeof(NeedsFuture)); - Assert.IsTrue(IsFuture.Instantiated); - } - - [TestMethod] - public void testFutures() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - IInjector i2 = TangFactory.GetTang().NewInjector(cb.Build()); - - Futurist f = (Futurist)i.GetInstance(typeof(Futurist)); - Assert.IsTrue(f == f.getMyCar().getDriver()); - Assert.IsTrue(f.getMyCar() == f.getMyCar().getDriver().getMyCar()); - - Futurist f2 = (Futurist)i2.GetInstance(typeof(Futurist)); - Assert.IsTrue(f2 == f2.getMyCar().getDriver()); - Assert.IsTrue(f2.getMyCar() == f2.getMyCar().getDriver().getMyCar()); - - Assert.IsTrue(f != f2.getMyCar().getDriver()); - Assert.IsTrue(f.getMyCar() != f2.getMyCar().getDriver().getMyCar()); - } - - [TestMethod] - public void testFutures2() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - IInjector i2 = i.ForkInjector(new IConfiguration[] { }); - - FlyingCar c = (FlyingCar)i.GetInstance(typeof(FlyingCar)); - Assert.IsTrue(c == c.getDriver().getMyCar()); - Assert.IsTrue(c.getDriver() == c.getDriver().getMyCar().getDriver()); - - FlyingCar c2 = (FlyingCar)i2.GetInstance(typeof(FlyingCar)); - Assert.IsTrue(c2 == c2.getDriver().getMyCar()); - Assert.IsTrue(c2.getDriver() == c2.getDriver().getMyCar().getDriver()); - - Assert.IsTrue(c2 != c.getDriver().getMyCar()); - Assert.IsTrue(c2.getDriver() != c.getDriver().getMyCar().getDriver()); - } - - [TestMethod] - public void TestNamedParameterInjectionFuture() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindImplementation(GenericType<FlyingCar>.Class, GenericType<FlyingCar>.Class); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - PickyFuturist f = (PickyFuturist)i.GetInstance(typeof(PickyFuturist)); - Assert.IsNotNull(f.getMyCar()); - } - - [TestMethod] - public void TestNamedParameterInjectionFutureDefaultImpl() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - PickyFuturist f = (PickyFuturist)i.GetInstance(typeof(PickyFuturist)); - Assert.IsNotNull(f.getMyCar()); - } - - [TestMethod] - public void TestNamedParameterInjectionFutureBindImpl() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindImplementation(GenericType<Futurist>.Class, GenericType<PickyFuturist>.Class); - cb.BindNamedParameter<MyFlyingCar, BigFlyingCar, FlyingCar>(GenericType<MyFlyingCar>.Class, GenericType<BigFlyingCar>.Class); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - PickyFuturist f = (PickyFuturist)i.GetInstance(typeof(PickyFuturist)); - Assert.IsNotNull((BigFlyingCar)f.getMyCar()); - } - - [TestMethod] - public void TestNamedParameterBoundToDelegatingInterface() - { - IInjector i = TangFactory.GetTang().NewInjector(); - C c = (C)i.GetNamedInstance(typeof(AName)); - Assert.IsNotNull(c); - } - - [TestMethod] - public void TestBoundToDelegatingInterface() - { - IInjector i = TangFactory.GetTang().NewInjector(); - C c = (C)i.GetInstance(typeof(IBinj)); - Assert.IsNotNull(c); - } - - [DefaultImplementation(typeof(Futurist), "Futurist")] - public class Futurist - { - private IInjectionFuture<FlyingCar> fcar; - [Inject] - public Futurist(IInjectionFuture<FlyingCar> car) - { - this.fcar = car; - } - - public virtual FlyingCar getMyCar() - { - FlyingCar c = fcar.Get(); - return c; - } - } - - public class PickyFuturist : Futurist - { - private IInjectionFuture<FlyingCar> fCar; - [Inject] - public PickyFuturist([Parameter(typeof(MyFlyingCar))] IInjectionFuture<FlyingCar> myFlyingCar) : base(myFlyingCar) - { - fCar = myFlyingCar; - } - - public override FlyingCar getMyCar() - { - FlyingCar c = fCar.Get(); - return c; - } - } - - [DefaultImplementation(typeof(FlyingCar), "")] - public class FlyingCar - { - private string color; - private Futurist driver; - - [Inject] - public FlyingCar([Parameter(typeof(Color))] string color, Futurist driver) - { - this.color = color; - this.driver = driver; - } - - public string getColor() - { - return color; - } - - public Futurist getDriver() - { - return driver; - } - } - - [NamedParameter(DefaultValue = "blue")] - public class Color : Name<string> - { - } - - public class BigFlyingCar : FlyingCar - { - [Inject] - BigFlyingCar([Parameter(typeof(Color))] string color, Futurist driver) : base(color, driver) - { - } - } - - [NamedParameter(DefaultClass = typeof(FlyingCar))] - public class MyFlyingCar : Name<FlyingCar> - { - } - } - - [NamedParameter(DefaultClass = typeof(IBinj))] - class AName : Name<IAinj> - { - } - - class C : IBinj - { - [Inject] - C() - { - } - } - - class IsFuture - { - [Inject] - IsFuture(NeedsFuture nf) - { - Instantiated = true; - } - - public static bool Instantiated { get; set; } - } - - class NeedsFuture - { - [Inject] - NeedsFuture(IInjectionFuture<IsFuture> isFut) - { - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Tests/TangTests/Injection/TestListInjection.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Injection/TestListInjection.cs b/lang/cs/Tests/TangTests/Injection/TestListInjection.cs deleted file mode 100644 index 1c05516..0000000 --- a/lang/cs/Tests/TangTests/Injection/TestListInjection.cs +++ /dev/null @@ -1,565 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using ClassHierarchyProto; -using Org.Apache.Reef.Tang.Annotations; -using Org.Apache.Reef.Tang.Implementations; -using Org.Apache.Reef.Tang.Interface; -using Org.Apache.Reef.Tang.Types; -using Org.Apache.Reef.Tang.Util; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Org.Apache.Reef.Tang.Test.Injection -{ - /// <summary> - /// Test injection with a List - /// </summary> - [TestClass] - public class TestListInjection - { - /// <summary> - /// Tests the string inject default. - /// </summary> - [TestMethod] - public void TestStringInjectDefault() - { - StringClass b = TangFactory.GetTang().NewInjector().GetInstance<StringClass>(); - - IList<string> actual = b.StringList; - - Assert.IsTrue(actual.Contains("one")); - Assert.IsTrue(actual.Contains("two")); - Assert.IsTrue(actual.Contains("three")); - } - - /// <summary> - /// Tests the int inject default. - /// </summary> - [TestMethod] - public void TestIntInjectDefault() - { - IntClass b = TangFactory.GetTang().NewInjector().GetInstance<IntClass>(); - - IList<int> actual = b.IntList; - - Assert.IsTrue(actual.Contains(1)); - Assert.IsTrue(actual.Contains(2)); - Assert.IsTrue(actual.Contains(3)); - } - - /// <summary> - /// Tests the string inject configuration builder. - /// </summary> - [TestMethod] - public void TestStringInjectConfigurationBuilder() - { - ICsClassHierarchy classH = TangFactory.GetTang().GetDefaultClassHierarchy(); - INamedParameterNode np = (INamedParameterNode)classH.GetNode(typeof(StringList)); - IList<string> injected = new List<string>(); - injected.Add("hi"); - injected.Add("hello"); - injected.Add("bye"); - - IConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindList(np, injected); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - IList<string> actual = ((StringClass)i.GetInstance(typeof(StringClass))).StringList; - - Assert.IsTrue(actual.Contains("hi")); - Assert.IsTrue(actual.Contains("hello")); - Assert.IsTrue(actual.Contains("bye")); - Assert.AreEqual(actual.Count, 3); - } - - /// <summary> - /// Tests the bool list with named parameter. - /// </summary> - [TestMethod] - public void TestBoolListWithNamedParameter() - { - ICsClassHierarchy classH = TangFactory.GetTang().GetDefaultClassHierarchy(); - INamedParameterNode np = (INamedParameterNode)classH.GetNode(typeof(BoolListClass.NamedBoolList)); - IList<string> injected = new List<string>(); - injected.Add("true"); - injected.Add("false"); - injected.Add("true"); - - IConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindList(np, injected); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - BoolListClass o = i.GetInstance<BoolListClass>(); - - IList<bool> expected = new List<bool>(); - expected.Add(true); - expected.Add(false); - expected.Add(true); - o.Verify(expected); - } - - /// <summary> - /// Tests the type of the bool list with generic. - /// </summary> - [TestMethod] - public void TestBoolListWithGenericType() - { - IList<string> injected = new List<string>(); - injected.Add("true"); - injected.Add("false"); - injected.Add("true"); - - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindList<BoolListClass.NamedBoolList, bool>(GenericType<BoolListClass.NamedBoolList>.Class, injected); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - BoolListClass o = i.GetInstance<BoolListClass>(); - - IList<bool> expected = new List<bool>(); - expected.Add(true); - expected.Add(false); - expected.Add(true); - o.Verify(expected); - } - - /// <summary> - /// Tests the int list with named parameter. - /// </summary> - [TestMethod] - public void TestIntListWithNamedParameter() - { - ICsClassHierarchy classH = TangFactory.GetTang().GetDefaultClassHierarchy(); - INamedParameterNode np = (INamedParameterNode)classH.GetNode(typeof(IntListClass.NamedIntList)); - IList<string> injected = new List<string>(); - injected.Add("1"); - injected.Add("2"); - injected.Add("3"); - - IConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindList(np, injected); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - IntListClass o = i.GetInstance<IntListClass>(); - - IList<int> expected = new List<int>(); - expected.Add(1); - expected.Add(2); - expected.Add(3); - o.Verify(expected); - } - - /// <summary> - /// Tests the type of the int list with generic. - /// </summary> - [TestMethod] - public void TestIntListWithGenericType() - { - IList<string> injected = new List<string>(); - injected.Add("1"); - injected.Add("2"); - injected.Add("3"); - - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindList<IntListClass.NamedIntList, int>(GenericType<IntListClass.NamedIntList>.Class, injected); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - IntListClass o = i.GetInstance<IntListClass>(); - - IList<int> expected = new List<int>(); - expected.Add(1); - expected.Add(2); - expected.Add(3); - o.Verify(expected); - } - - /// <summary> - /// Tests the string inject. - /// </summary> - [TestMethod] - public void TestStringInject() - { - IList<string> injected = new List<string>(); - injected.Add("hi"); - injected.Add("hello"); - injected.Add("bye"); - - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindList<StringList, string>(GenericType<StringList>.Class, injected); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - IList<string> actual = ((StringClass)i.GetInstance(typeof(StringClass))).StringList; - - Assert.IsTrue(actual.Contains("hi")); - Assert.IsTrue(actual.Contains("hello")); - Assert.IsTrue(actual.Contains("bye")); - Assert.AreEqual(actual.Count, 3); - } - - /// <summary> - /// Tests the node inject and bind volatile instance. - /// </summary> - [TestMethod] - public void TestNodeInjectAndBindVolatileInstance() - { - ICsClassHierarchy classH = TangFactory.GetTang().GetDefaultClassHierarchy(); - INamedParameterNode np = (INamedParameterNode)classH.GetNode(typeof(ListOfClasses)); - IList<INode> injected = new List<INode>(); - injected.Add(classH.GetNode(typeof(TestSetInjection.Integer))); - injected.Add(classH.GetNode(typeof(TestSetInjection.Float))); - - IConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindList(np, injected); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - i.BindVolatileInstance(GenericType<TestSetInjection.Integer>.Class, new TestSetInjection.Integer(42)); - i.BindVolatileInstance(GenericType<TestSetInjection.Float>.Class, new TestSetInjection.Float(42.0001f)); - IList<INumber> actual = ((PoolListClass)i.GetInstance(typeof(PoolListClass))).Numbers; - - Assert.IsTrue(actual.Contains(new TestSetInjection.Integer(42))); - Assert.IsTrue(actual.Contains(new TestSetInjection.Float(42.0001f))); - } - - /// <summary> - /// Tests the class name inject with named parameter node. - /// </summary> - [TestMethod] - public void TestClassNameInjectWithNamedParameterNode() - { - ICsClassHierarchy classH = TangFactory.GetTang().GetDefaultClassHierarchy(); - INamedParameterNode np = (INamedParameterNode)classH.GetNode(typeof(ListOfClasses)); - - IList<string> injected = new List<string>(); - injected.Add(typeof(TestSetInjection.Integer).AssemblyQualifiedName); - injected.Add(typeof(TestSetInjection.Float).AssemblyQualifiedName); - - IConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindList(np, injected); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - i.BindVolatileInstance(GenericType<TestSetInjection.Integer>.Class, new TestSetInjection.Integer(42)); - i.BindVolatileInstance(GenericType<TestSetInjection.Float>.Class, new TestSetInjection.Float(42.0001f)); - IList<INumber> actual = ((PoolListClass)i.GetInstance(typeof(PoolListClass))).Numbers; - - Assert.IsTrue(actual.Contains(new TestSetInjection.Integer(42))); - Assert.IsTrue(actual.Contains(new TestSetInjection.Float(42.0001f))); - } - - /// <summary> - /// Tests the name of the class name inject with named parameter. - /// </summary> - [TestMethod] - public void TestClassNameInjectWithNamedParameterName() - { - IList<string> injected = new List<string>(); - injected.Add(typeof(TestSetInjection.Integer).AssemblyQualifiedName); - injected.Add(typeof(TestSetInjection.Float).AssemblyQualifiedName); - - IConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindList(typeof(ListOfClasses).AssemblyQualifiedName, injected); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - i.BindVolatileInstance(GenericType<TestSetInjection.Integer>.Class, new TestSetInjection.Integer(42)); - i.BindVolatileInstance(GenericType<TestSetInjection.Float>.Class, new TestSetInjection.Float(42.0001f)); - IList<INumber> actual = ((PoolListClass)i.GetInstance(typeof(PoolListClass))).Numbers; - - Assert.IsTrue(actual.Contains(new TestSetInjection.Integer(42))); - Assert.IsTrue(actual.Contains(new TestSetInjection.Float(42.0001f))); - } - - /// <summary> - /// Tests the object inject with injectable subclasses. - /// </summary> - [TestMethod] - public void TestObjectInjectWithInjectableSubclasses() - { - IList<string> injected = new List<string>(); - injected.Add(typeof(TestSetInjection.Integer1).AssemblyQualifiedName); - injected.Add(typeof(TestSetInjection.Integer2).AssemblyQualifiedName); - injected.Add(typeof(TestSetInjection.Integer3).AssemblyQualifiedName); - - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindList(typeof(ListOfClasses).AssemblyQualifiedName, injected); - cb.BindNamedParameter<TestSetInjection.Integer1.NamedInt, int>(GenericType<TestSetInjection.Integer1.NamedInt>.Class, "5"); - cb.BindNamedParameter<TestSetInjection.Integer3.NamedInt, int>(GenericType<TestSetInjection.Integer3.NamedInt>.Class, "10"); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - - IList<INumber> actual = ((PoolListClass)i.GetInstance(typeof(PoolListClass))).Numbers; - - Assert.IsTrue(actual.Count == 3); - Assert.IsTrue(actual.Contains(new TestSetInjection.Integer1(5))); - Assert.IsTrue(actual.Contains(new TestSetInjection.Integer2())); - Assert.IsTrue(actual.Contains(new TestSetInjection.Integer3(10))); - } - - /// <summary> - /// Tests the object inject with injectable subclasses multiple instances. - /// </summary> - [TestMethod] - public void TestObjectInjectWithInjectableSubclassesMultipleInstances() - { - IList<string> injected = new List<string>(); - injected.Add(typeof(TestSetInjection.Integer1).AssemblyQualifiedName); - injected.Add(typeof(TestSetInjection.Integer1).AssemblyQualifiedName); - injected.Add(typeof(TestSetInjection.Float1).AssemblyQualifiedName); - - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<TestSetInjection.Integer1.NamedInt, int>(GenericType<TestSetInjection.Integer1.NamedInt>.Class, "5"); - cb.BindNamedParameter<TestSetInjection.Float1.NamedFloat, float>(GenericType<TestSetInjection.Float1.NamedFloat>.Class, "12.5"); - cb.BindList<ListOfClasses, INumber>(GenericType<ListOfClasses>.Class, injected); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - - IList<INumber> actual = ((PoolListClass)i.GetInstance(typeof(PoolListClass))).Numbers; - - Assert.IsTrue(actual.Count == 3); - Assert.IsTrue(actual.Contains(new TestSetInjection.Integer1(5))); - Assert.IsTrue(actual.Contains(new TestSetInjection.Integer1(5))); - Assert.IsTrue(actual.Contains(new TestSetInjection.Float1(12.5f))); - } - - /// <summary> - /// Tests the object inject with injectable subclasses and typeof named parameter. - /// </summary> - [TestMethod] - public void TestObjectInjectWithInjectableSubclassesAndTypeofNamedParameter() - { - IList<string> injected = new List<string>(); - injected.Add(typeof(TestSetInjection.Integer1).AssemblyQualifiedName); - injected.Add(typeof(TestSetInjection.Integer2).AssemblyQualifiedName); - injected.Add(typeof(TestSetInjection.Integer3).AssemblyQualifiedName); - - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<TestSetInjection.Integer1.NamedInt, int>(GenericType<TestSetInjection.Integer1.NamedInt>.Class, "5"); - cb.BindNamedParameter<TestSetInjection.Integer3.NamedInt, int>(GenericType<TestSetInjection.Integer3.NamedInt>.Class, "10"); - cb.BindList<ListOfClasses, INumber>(GenericType<ListOfClasses>.Class, injected); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - - IList<INumber> actual = ((PoolListClass)i.GetInstance(typeof(PoolListClass))).Numbers; - - Assert.IsTrue(actual.Count == 3); - Assert.IsTrue(actual.Contains(new TestSetInjection.Integer1(5))); - Assert.IsTrue(actual.Contains(new TestSetInjection.Integer2())); - Assert.IsTrue(actual.Contains(new TestSetInjection.Integer3(10))); - } - - /// <summary> - /// Tests the object inject with names configuration builder. - /// </summary> - [TestMethod] - public void TestObjectInjectWithNames() - { - ICsClassHierarchy classH = TangFactory.GetTang().GetDefaultClassHierarchy(); - IList<INode> injected = new List<INode>(); - injected.Add(classH.GetNode(typeof(TestSetInjection.Integer))); - injected.Add(classH.GetNode(typeof(TestSetInjection.Float))); - - IConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindList(typeof(ListOfClasses).AssemblyQualifiedName, injected); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - i.BindVolatileInstance(GenericType<TestSetInjection.Integer>.Class, new TestSetInjection.Integer(42)); - i.BindVolatileInstance(GenericType<TestSetInjection.Float>.Class, new TestSetInjection.Float(42.0001f)); - IList<INumber> actual = ((PoolListClass)i.GetInstance(typeof(PoolListClass))).Numbers; - - Assert.IsTrue(actual.Contains(new TestSetInjection.Integer(42))); - Assert.IsTrue(actual.Contains(new TestSetInjection.Float(42.0001f))); - } - - /// <summary> - /// Tests the object inject with type type cs configuration builder. - /// </summary> - [TestMethod] - public void TestObjectInjectWithTypeType() - { - IList<Type> injected = new List<Type>(); - injected.Add(typeof(TestSetInjection.Integer)); - injected.Add(typeof(TestSetInjection.Float)); - - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindList(typeof(ListOfClasses), injected); - - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - i.BindVolatileInstance(GenericType<TestSetInjection.Integer>.Class, new TestSetInjection.Integer(42)); - i.BindVolatileInstance(GenericType<TestSetInjection.Float>.Class, new TestSetInjection.Float(42.0001f)); - IList<INumber> actual = ((PoolListClass)i.GetInstance(typeof(PoolListClass))).Numbers; - - Assert.IsTrue(actual.Contains(new TestSetInjection.Integer(42))); - Assert.IsTrue(actual.Contains(new TestSetInjection.Float(42.0001f))); - } - - ///// <summary> - ///// Tests the subclass inject with multiple instances. - ///// </summary> - //[TestMethod] - //public void TestSubclassInjectWithMultipleInstances() - //{ - // ICsConfigurationBuilder cb1 = TangFactory.GetTang().NewConfigurationBuilder() - // .BindNamedParameter<TestSetInjection.Integer3.NamedInt, int>(GenericType<TestSetInjection.Integer3.NamedInt>.Class, "10"); - // TestSetInjection.Integer3 integer3 = TangFactory.GetTang().NewInjector(cb1.Build()).GetInstance<TestSetInjection.Integer3>(); - - // ICsClassHierarchy classH = TangFactory.GetTang().GetDefaultClassHierarchy(); - // INamedParameterNode np = (INamedParameterNode)classH.GetNode(typeof(ListOfClasses)); - // IList<object> injected = new List<object>(); - // injected.Add(new TestSetInjection.Integer1(42)); //instance from the same class - // injected.Add(new TestSetInjection.Integer1(30)); //instance from the same class - // injected.Add(new TestSetInjection.Float1(42.0001f)); //instance from another subclass of the same interface - // injected.Add(typeof(TestSetInjection.Float1).AssemblyQualifiedName); //inject from another subclass of the same interface - // injected.Add(typeof(TestSetInjection.Integer1).AssemblyQualifiedName); //inject using configuration - // injected.Add(typeof(TestSetInjection.Integer2).AssemblyQualifiedName); //inject using default - // injected.Add(integer3); //add pre injected instance - - // ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - // cb.BindNamedParameter<TestSetInjection.Integer1.NamedInt, int>(GenericType<TestSetInjection.Integer1.NamedInt>.Class, "5"); - // cb.BindNamedParameter<TestSetInjection.Float1.NamedFloat, float>(GenericType<TestSetInjection.Float1.NamedFloat>.Class, "12.5"); - // cb.BindList(np, injected); - - // IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - // IList<INumber> actual = ((PoolListClass)i.GetInstance(typeof(PoolListClass))).Numbers; - // Assert.IsTrue(actual.Count == 7); - // Assert.IsTrue(actual.Contains(new TestSetInjection.Integer1(42))); - // Assert.IsTrue(actual.Contains(new TestSetInjection.Integer1(30))); - // Assert.IsTrue(actual.Contains(new TestSetInjection.Float1(42.0001f))); - // Assert.IsTrue(actual.Contains(new TestSetInjection.Float1(12.5f))); - // Assert.IsTrue(actual.Contains(new TestSetInjection.Integer1(5))); - // Assert.IsTrue(actual.Contains(new TestSetInjection.Integer2())); - // Assert.IsTrue(actual.Contains(new TestSetInjection.Integer3(10))); - //} - } - - [NamedParameter(DefaultValues = new string[] { "one", "two", "three" })] - internal class StringList : Name<IList<string>> - { - } - - [NamedParameter(DefaultValues = new string[] { "1", "2", "3" })] - internal class IntList : Name<IList<int>> - { - } - - [NamedParameter(DefaultValues = new string[] { "1", "2", "3" })] - internal class IntegerList : Name<IList<TestSetInjection.Integer>> - { - } - - internal class StringClass - { - [Inject] - private StringClass([Parameter(typeof(StringList))] IList<string> stringList) - { - this.StringList = stringList; - } - - public IList<string> StringList { get; set; } - } - - internal class IntClass - { - [Inject] - private IntClass([Parameter(typeof(IntList))] IList<int> integerList) - { - this.IntList = integerList; - } - - public IList<int> IntList { get; set; } - } - - internal class IntegerListClass - { - [Inject] - private IntegerListClass([Parameter(typeof(IntegerList))] IList<TestSetInjection.Integer> integerList) - { - this.IntegerList = integerList; - } - - public IList<TestSetInjection.Integer> IntegerList { get; set; } - } - - [NamedParameter(DefaultClasses = new Type[] { typeof(TestSetInjection.Integer), typeof(TestSetInjection.Float) })] - internal class ListOfClasses : Name<IList<INumber>> - { - } - - internal class PoolListClass - { - [Inject] - private PoolListClass([Parameter(typeof(ListOfClasses))] IList<INumber> numbers) - { - this.Numbers = numbers; - } - - public IList<INumber> Numbers { get; set; } - } - - internal class BoolListClass - { - private readonly IList<bool> b; - - [Inject] - public BoolListClass([Parameter(typeof(NamedBoolList))] IList<bool> b) - { - this.b = b; - } - - public void Verify(IList<bool> v) - { - Assert.AreEqual(v.Count, b.Count); - foreach (bool bv in v) - { - Assert.IsTrue(b.Contains(bv)); - } - } - - [NamedParameter] - public class NamedBoolList : Name<IList<bool>> - { - } - } - - internal class IntListClass - { - private readonly IList<int> l; - - [Inject] - public IntListClass([Parameter(typeof(NamedIntList))] IList<int> b) - { - this.l = b; - } - - public void Verify(IList<int> v) - { - Assert.AreEqual(v.Count, l.Count); - foreach (int iv in v) - { - Assert.IsTrue(l.Contains(iv)); - } - } - - [NamedParameter] - public class NamedIntList : Name<IList<int>> - { - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Tests/TangTests/Injection/TestMissingParameters.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Injection/TestMissingParameters.cs b/lang/cs/Tests/TangTests/Injection/TestMissingParameters.cs deleted file mode 100644 index 09fdd78..0000000 --- a/lang/cs/Tests/TangTests/Injection/TestMissingParameters.cs +++ /dev/null @@ -1,151 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -using System; -using Org.Apache.Reef.Tang.Annotations; -using Org.Apache.Reef.Tang.Exceptions; -using Org.Apache.Reef.Tang.Implementations; -using Org.Apache.Reef.Tang.Interface; -using Org.Apache.Reef.Tang.Util; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Org.Apache.Reef.Tang.Test.Injection -{ - [TestClass] - public class TestMissingParameters - { - [TestMethod] - public void MultipleParameterTest() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<MultiParameterConstructor.NamedString, string>(GenericType<MultiParameterConstructor.NamedString>.Class, "foo"); - cb.BindNamedParameter<MultiParameterConstructor.NamedInt, int>(GenericType<MultiParameterConstructor.NamedInt>.Class, "8"); - cb.BindNamedParameter<MultiParameterConstructor.NamedBool, bool>(GenericType<MultiParameterConstructor.NamedBool>.Class, "true"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<MultiParameterConstructor>(); - o.Verify("foo", 8, true); - } - - [TestMethod] - public void MissingAllParameterTest() - { - //Org.Apache.Reef.Tang.Test.Injection.MultiParameterConstructor, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - //missing arguments: [ - //Org.Apache.Reef.Tang.Test.Injection.MultiParameterConstructor+NamedBool, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - //Org.Apache.Reef.Tang.Test.Injection.MultiParameterConstructor+NamedString, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - //Org.Apache.Reef.Tang.Test.Injection.MultiParameterConstructor+NamedInt, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - //] - MultiParameterConstructor obj = null; - try - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - obj = i.GetInstance<MultiParameterConstructor>(); - } - catch (InjectionException e) - { - System.Diagnostics.Debug.WriteLine(e); - } - Assert.IsNull(obj); - } - - [TestMethod] - public void MissingTwoParameterTest() - { - //Cannot inject Org.Apache.Reef.Tang.Test.Injection.MultiParameterConstructor, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: - //Org.Apache.Reef.Tang.Test.Injection.MultiParameterConstructor, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - //missing arguments: [ - //Org.Apache.Reef.Tang.Test.Injection.MultiParameterConstructor+NamedString, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - //Org.Apache.Reef.Tang.Test.Injection.MultiParameterConstructor+NamedInt, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - //] - MultiParameterConstructor obj = null; - try - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<MultiParameterConstructor.NamedBool, bool>(GenericType<MultiParameterConstructor.NamedBool>.Class, "true"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - obj = i.GetInstance<MultiParameterConstructor>(); - } - catch (InjectionException e) - { - System.Diagnostics.Debug.WriteLine(e); - } - Assert.IsNull(obj); - } - - [TestMethod] - public void MissingOneParameterTest() - { - //Cannot inject Org.Apache.Reef.Tang.Test.Injection.MultiParameterConstructor, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: - //Org.Apache.Reef.Tang.Test.Injection.MultiParameterConstructor, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - //missing argument Org.Apache.Reef.Tang.Test.Injection.MultiParameterConstructor+NamedInt, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - MultiParameterConstructor obj = null; - try - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<MultiParameterConstructor.NamedBool, bool>(GenericType<MultiParameterConstructor.NamedBool>.Class, "true"); - cb.BindNamedParameter<MultiParameterConstructor.NamedString, string>(GenericType<MultiParameterConstructor.NamedString>.Class, "foo"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - obj = i.GetInstance<MultiParameterConstructor>(); - } - catch (InjectionException e) - { - System.Diagnostics.Debug.WriteLine(e); - } - Assert.IsNull(obj); - } - } - - public class MultiParameterConstructor - { - private readonly string str; - private readonly int iVal; - private readonly bool bVal; - - [Inject] - public MultiParameterConstructor([Parameter(typeof(NamedBool))] bool b, [Parameter(typeof(NamedString))] string s, [Parameter(typeof(NamedInt))] int i) - { - this.str = s; - this.iVal = i; - this.bVal = b; - } - - public void Verify(string s, int i, bool b) - { - Assert.AreEqual(str, s); - Assert.AreEqual(iVal, i); - Assert.AreEqual(bVal, b); - } - - [NamedParameter] - public class NamedString : Name<string> - { - } - - [NamedParameter] - public class NamedInt : Name<int> - { - } - - [NamedParameter] - public class NamedBool : Name<bool> - { - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Tests/TangTests/Injection/TestMissingParamtersInNested.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Injection/TestMissingParamtersInNested.cs b/lang/cs/Tests/TangTests/Injection/TestMissingParamtersInNested.cs deleted file mode 100644 index 25ddb0c..0000000 --- a/lang/cs/Tests/TangTests/Injection/TestMissingParamtersInNested.cs +++ /dev/null @@ -1,142 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -using System; -using Org.Apache.Reef.Tang.Annotations; -using Org.Apache.Reef.Tang.Exceptions; -using Org.Apache.Reef.Tang.Implementations; -using Org.Apache.Reef.Tang.Interface; -using Org.Apache.Reef.Tang.Util; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Org.Apache.Reef.Tang.Test.Injection -{ - [TestClass] - public class TestMissingParamtersInNested - { - [TestMethod] - public void InnerParameterTest() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<ReferencedClass.NamedInt, int>(GenericType<ReferencedClass.NamedInt>.Class, "8"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<ReferencedClass>(); - Assert.IsNotNull(o); - } - - [TestMethod] - public void NestedParameterTest() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<OuterClass.NamedString, string>(GenericType<OuterClass.NamedString>.Class, "foo"); - cb.BindNamedParameter<ReferencedClass.NamedInt, int>(GenericType<ReferencedClass.NamedInt>.Class, "8"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<OuterClass>(); - Assert.IsNotNull(o); - } - - [TestMethod] - public void MissingAllParameterTest() - { - //Cannot inject Org.Apache.Reef.Tang.Test.Injection.OuterClass, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: - //Org.Apache.Reef.Tang.Test.Injection.ReferencedClass, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - //missing argument Org.Apache.Reef.Tang.Test.Injection.ReferencedClass+NamedInt, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - OuterClass obj = null; - try - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - obj = i.GetInstance<OuterClass>(); - } - catch (InjectionException e) - { - System.Diagnostics.Debug.WriteLine(e); - } - Assert.IsNull(obj); - } - - [TestMethod] - public void MissingInnerParameterTest() - { - //Cannot inject Org.Apache.Reef.Tang.Test.Injection.OuterClass, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: - //Org.Apache.Reef.Tang.Test.Injection.ReferencedClass, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - //missing argument Org.Apache.Reef.Tang.Test.Injection.ReferencedClass+NamedInt, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - OuterClass obj = null; - try - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<OuterClass.NamedString, string>(GenericType<OuterClass.NamedString>.Class, "foo"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - obj = i.GetInstance<OuterClass>(); - } - catch (InjectionException e) - { - System.Diagnostics.Debug.WriteLine(e); - } - Assert.IsNull(obj); - } - - [TestMethod] - public void MissingOuterParameterTest() - { - //Cannot inject Org.Apache.Reef.Tang.Test.Injection.OuterClass, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: - //Org.Apache.Reef.Tang.Test.Injection.OuterClass, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - //missing argument Org.Apache.Reef.Tang.Test.Injection.OuterClass+NamedString, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - OuterClass obj = null; - try - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<ReferencedClass.NamedInt, int>(GenericType<ReferencedClass.NamedInt>.Class, "8"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - obj = i.GetInstance<OuterClass>(); - } - catch (InjectionException e) - { - System.Diagnostics.Debug.WriteLine(e); - } - Assert.IsNull(obj); - } - } - - class OuterClass - { - [Inject] - public OuterClass([Parameter(typeof(NamedString))] string s, ReferencedClass refCls) - { - } - - [NamedParameter] - public class NamedString : Name<string> - { - } - } - - class ReferencedClass - { - [Inject] - public ReferencedClass([Parameter(typeof(NamedInt))] int i) - { - } - - [NamedParameter] - public class NamedInt : Name<int> - { - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Tests/TangTests/Injection/TestMultipleConstructors.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Injection/TestMultipleConstructors.cs b/lang/cs/Tests/TangTests/Injection/TestMultipleConstructors.cs deleted file mode 100644 index bc3d25a..0000000 --- a/lang/cs/Tests/TangTests/Injection/TestMultipleConstructors.cs +++ /dev/null @@ -1,360 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -using System; -using Org.Apache.Reef.Tang.Annotations; -using Org.Apache.Reef.Tang.Exceptions; -using Org.Apache.Reef.Tang.Implementations; -using Org.Apache.Reef.Tang.Interface; -using Org.Apache.Reef.Tang.Util; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Org.Apache.Reef.Tang.Test.Injection -{ - public interface IH - { - } - - [TestClass] - public class TestMultipleConstructors - { - [TestMethod] - public void TestMissingAllParameters() - { - //Multiple infeasible plans: Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest - //, Org.Apache.Reef.Tang.Test - //, Version=1.0.0.0 - //, Culture=neutral - //, PublicKeyToken=null: - - // [ Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest = new Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest - // ( System.Boolean Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedBool = - // , System.Int32 Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedInt = - // ) - // | new Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest - // ( System.String Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedString = - // , System.Int32 Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedInt = - // ) - // | new Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest - // ( System.Boolean Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedBool = - // , System.String Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedString = - // , System.Int32 Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedInt = - // ) - // ] - MultiConstructorTest obj = null; - try - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - obj = i.GetInstance<MultiConstructorTest>(); - } - catch (InjectionException) - { - } - Assert.IsNull(obj); - } - - [TestMethod] - public void TestMissingIntParameter() - { - //Multiple infeasible plans: Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest - //, Org.Apache.Reef.Tang.Test - //, Version=1.0.0.0 - //, Culture=neutral - //, PublicKeyToken=null: - // [ Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest = new Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest - // ( System.Boolean Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedBool = False - // , System.Int32 Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedInt = - // ) - // | new Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest - // ( System.String Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedString = foo - // , System.Int32 Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedInt = - // ) - // | new Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest - // ( System.Boolean Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedBool = False - // , System.String Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedString = foo - // , System.Int32 Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedInt = - // ) - // ] - MultiConstructorTest obj = null; - try - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<MultiConstructorTest.NamedString, string>(GenericType<MultiConstructorTest.NamedString>.Class, "foo"); - cb.BindNamedParameter<MultiConstructorTest.NamedBool, bool>(GenericType<MultiConstructorTest.NamedBool>.Class, "true"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - obj = i.GetInstance<MultiConstructorTest>(); - } - catch (InjectionException) - { - } - Assert.IsNull(obj); - } - - [TestMethod] - public void TestOnlyBoolParameter() - { - //Multiple infeasible plans: Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest - //, Org.Apache.Reef.Tang.Test - //, Version=1.0.0.0 - //, Culture=neutral - //, PublicKeyToken=null: - // [ Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest = new Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest - // ( System.Boolean Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedBool = False - // , System.Int32 Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedInt = - // ) - // | new Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest - // ( System.String Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedString = - // , System.Int32 Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedInt = - // ) - // | new Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest - // ( System.Boolean Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedBool = False - // , System.String Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedString = - // , System.Int32 Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedInt = - // ) - // ] - MultiConstructorTest obj = null; - try - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<MultiConstructorTest.NamedBool, bool>(GenericType<MultiConstructorTest.NamedBool>.Class, "true"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - obj = i.GetInstance<MultiConstructorTest>(); - } - catch (InjectionException) - { - } - Assert.IsNull(obj); - } - - [TestMethod] - public void TestOnlyIntParameter() - { - //Multiple infeasible plans: Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest - //, Org.Apache.Reef.Tang.Test - //, Version=1.0.0.0 - //, Culture=neutral - //, PublicKeyToken=null: - // [ Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest = new Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest - // ( System.Boolean Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedBool = - // , System.Int32 Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedInt = 8 - // ) - // | new Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest - // ( System.String Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedString = - // , System.Int32 Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedInt = 8 - // ) - // | new Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest - // ( System.Boolean Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedBool = - // , System.String Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedString = - // , System.Int32 Org.Apache.Reef.Tang.Test.Injection.MultiConstructorTest+NamedInt = 8 - // ) - // ] - MultiConstructorTest obj = null; - try - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<MultiConstructorTest.NamedInt, int>(GenericType<MultiConstructorTest.NamedInt>.Class, "8"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - obj = i.GetInstance<MultiConstructorTest>(); - } - catch (InjectionException) - { - } - Assert.IsNull(obj); - } - - [TestMethod] - public void TestMultipleConstructor() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<MultiConstructorTest.NamedString, string>(GenericType<MultiConstructorTest.NamedString>.Class, "foo"); - cb.BindNamedParameter<MultiConstructorTest.NamedInt, int>(GenericType<MultiConstructorTest.NamedInt>.Class, "8"); - cb.BindNamedParameter<MultiConstructorTest.NamedBool, bool>(GenericType<MultiConstructorTest.NamedBool>.Class, "true"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<MultiConstructorTest>(); - o.Verify("foo", 8, true); - } - - [TestMethod] - public void TestMultiLayersWithMiddleLayerFirst() - { - TangImpl.Reset(); - ICsConfigurationBuilder cb2 = TangFactory.GetTang().NewConfigurationBuilder(); - cb2.BindImplementation(typeof(IH), typeof(M)); - IInjector i2 = TangFactory.GetTang().NewInjector(cb2.Build()); - var o2 = i2.GetInstance<IH>(); - Assert.IsTrue(o2 is M); - - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindImplementation(typeof(IH), typeof(L)); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<IH>(); - Assert.IsTrue(o is L); - } - - [TestMethod] - public void TestMultiLayersWithLowerLayerFirst() - { - TangImpl.Reset(); - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindImplementation(typeof(IH), typeof(L)); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<IH>(); - Assert.IsTrue(o is L); - - ICsConfigurationBuilder cb2 = TangFactory.GetTang().NewConfigurationBuilder(); - cb2.BindImplementation(typeof(IH), typeof(M)); - IInjector i2 = TangFactory.GetTang().NewInjector(cb2.Build()); - var o2 = i2.GetInstance<IH>(); - Assert.IsTrue(o2 is M); - } - - [TestMethod] - public void TestMultiLayersWithBindImpl() - { - TangImpl.Reset(); - - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindImplementation(typeof(IH), typeof(L)); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<IH>(); - Assert.IsTrue(o is L); - - ICsConfigurationBuilder cb2 = TangFactory.GetTang().NewConfigurationBuilder(); - cb2.BindImplementation(typeof(IH), typeof(M)); - cb2.BindImplementation(typeof(M), typeof(L)); //construcotr of L is explicitly bound - IInjector i2 = TangFactory.GetTang().NewInjector(cb2.Build()); - var o2 = i2.GetInstance<IH>(); - Assert.IsTrue(o2 is L); - } - - [TestMethod] - public void TestMultiLayersWithNoInjectableDefaultConstructor() - { - TangImpl.Reset(); - - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindImplementation(typeof(IH), typeof(L1)); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<IH>(); - Assert.IsNotNull(o); - - ICsConfigurationBuilder cb2 = TangFactory.GetTang().NewConfigurationBuilder(); - cb2.BindImplementation(typeof(IH), typeof(M1)); //M1 doesn't have injectable default constructor, no implementation L1 is bound to M1 - IInjector i2 = TangFactory.GetTang().NewInjector(cb2.Build()); - string msg = null; - try - { - var o2 = i2.GetInstance<IH>(); - Assert.IsTrue(o2 is L1); - } - catch (Exception e) - { - //Cannot inject Org.Apache.Reef.Tang.Test.Injection.IH, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: - //No known implementations / injectable constructors for Org.Apache.Reef.Tang.Test.Injection.M1, Org.Apache.Reef.Tang.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - msg = e.Message; - } - Assert.IsNotNull(msg); - } - } - - public class MultiConstructorTest - { - private readonly string str; - private readonly int iVal; - private readonly bool bVal; - - [Inject] - public MultiConstructorTest([Parameter(typeof(NamedBool))] bool b, [Parameter(typeof(NamedInt))] int i) - { - this.bVal = b; - this.iVal = i; - this.bVal = false; - } - - [Inject] - public MultiConstructorTest([Parameter(typeof(NamedString))] string s, [Parameter(typeof(NamedInt))] int i) - { - this.str = s; - this.iVal = i; - this.bVal = false; - } - - [Inject] - public MultiConstructorTest([Parameter(typeof(NamedBool))] bool b, [Parameter(typeof(NamedString))] string s, [Parameter(typeof(NamedInt))] int i) - { - this.str = s; - this.iVal = i; - this.bVal = b; - } - - public void Verify(string s, int i, bool b) - { - Assert.AreEqual(str, s); - Assert.AreEqual(iVal, i); - Assert.AreEqual(bVal, b); - } - - [NamedParameter] - public class NamedString : Name<string> - { - } - - [NamedParameter] - public class NamedInt : Name<int> - { - } - - [NamedParameter] - public class NamedBool : Name<bool> - { - } - } - - class M : IH - { - [Inject] - public M() - { - } - } - - class L : M - { - [Inject] - public L() - { - } - } - - class M1 : IH - { - public M1() - { - } - } - - class L1 : M1 - { - [Inject] - public L1() - { - } - } -} \ No newline at end of file
