Repository: incubator-reef Updated Branches: refs/heads/master fa77cc63c -> c1b5200f6
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Tests/TangTests/Injection/TestNamedParameter.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Tests/TangTests/Injection/TestNamedParameter.cs b/lang/cs/Tests/TangTests/Injection/TestNamedParameter.cs deleted file mode 100644 index 9bcfd40..0000000 --- a/lang/cs/Tests/TangTests/Injection/TestNamedParameter.cs +++ /dev/null @@ -1,357 +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.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 TestNamedParameter - { - [TestMethod] - public void TestOptionalParameter() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<StringTest.NamedString, string>(GenericType<StringTest.NamedString>.Class, "foo"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<StringTest>(); - o.Verify("foo"); - } - - [TestMethod] - public void TestOptionalParameterWithDefault() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<StringTest>(); - o.Verify(" "); - } - - [TestMethod] - public void TestBoolParameter() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<BooleanTest.NamedBool, bool>(GenericType<BooleanTest.NamedBool>.Class, "true"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<BooleanTest>(); - o.Verify(true); - } - - [TestMethod] - public void TestBoolUpperCaseParameter() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<BooleanTest.NamedBool, bool>(GenericType<BooleanTest.NamedBool>.Class, "True"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<BooleanTest>(); - o.Verify(true); - } - - [TestMethod] - public void TestBoolParameterWithDefault() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<BooleanTest>(); - o.Verify(false); - } - - [TestMethod] - public void TestByteParameter() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<ByteTest.NamedByte, byte>(GenericType<ByteTest.NamedByte>.Class, "6"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<ByteTest>(); - o.Verify(6); - } - - [TestMethod] - public void TestByteArrayParameter() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - string input = "abcde"; - cb.BindNamedParameter<ByteArrayTest.NamedByteArray, byte[]>(GenericType<ByteArrayTest.NamedByteArray>.Class, input); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<ByteArrayTest>(); - - byte[] bytes = new byte[input.Length * sizeof(char)]; - System.Buffer.BlockCopy(input.ToCharArray(), 0, bytes, 0, bytes.Length); - Assert.IsTrue(o.Verify(bytes)); - } - - [TestMethod] - public void TestCharParameter() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<CharTest.NamedChar, char>(GenericType<CharTest.NamedChar>.Class, "C"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<CharTest>(); - o.Verify('C'); - } - - [TestMethod] - public void TestShortParameter() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<Int16Test.NamedShort, short>(GenericType<Int16Test.NamedShort>.Class, "8"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<Int16Test>(); - o.Verify(8); - } - - [TestMethod] - public void TestIntParameter() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<Int32Test.NamedInt, int>(GenericType<Int32Test.NamedInt>.Class, "8"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<Int32Test>(); - o.Verify(8); - } - - [TestMethod] - public void TestLongParameter() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<Int64Test.NamedLong, long>(GenericType<Int64Test.NamedLong>.Class, "8777"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<Int64Test>(); - o.Verify(8777); - } - - [TestMethod] - public void TestFloatParameter() - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(); - cb.BindNamedParameter<FloatTest.NamedSingle, float>(GenericType<FloatTest.NamedSingle>.Class, "3.5"); - IInjector i = TangFactory.GetTang().NewInjector(cb.Build()); - var o = i.GetInstance<FloatTest>(); - float x = 3.5F; - o.Verify(x); - } - } - - public class StringTest - { - private readonly string str; - - [Inject] - public StringTest([Parameter(typeof(NamedString))] string s) - { - this.str = s; - } - - public void Verify(string s) - { - Assert.AreEqual(s, str); - } - - [NamedParameter(DefaultValue = " ")] - public class NamedString : Name<string> - { - } - } - - public class CharTest - { - private readonly char c; - - [Inject] - public CharTest([Parameter(typeof(NamedChar))] char c) - { - this.c = c; - } - - public void Verify(char s) - { - Assert.AreEqual(s, c); - } - - [NamedParameter(DefaultValue = " ")] - public class NamedChar : Name<char> - { - } - } - - public class ByteTest - { - private readonly byte b; - - [Inject] - public ByteTest([Parameter(typeof(NamedByte))] byte b) - { - this.b = b; - } - - public void Verify(byte v) - { - Assert.AreEqual(v, b); - } - - [NamedParameter(DefaultValue = "7")] - public class NamedByte : Name<byte> - { - } - } - - public class BooleanTest - { - private readonly bool b; - - [Inject] - public BooleanTest([Parameter(typeof(NamedBool))] bool b) - { - this.b = b; - } - - public void Verify(bool v) - { - Assert.AreEqual(v, b); - } - - [NamedParameter(DefaultValue = "false")] - public class NamedBool : Name<bool> - { - } - } - - public class ByteArrayTest - { - private readonly byte[] b; - - [Inject] - public ByteArrayTest([Parameter(typeof(NamedByteArray))] byte[] b) - { - this.b = b; - } - - public bool Verify(byte[] v) - { - if (v.Length != b.Length) - { - return false; - } - - for (int i = 0; i < v.Length; i++) - { - if (v[i] != b[i]) - { - return false; - } - } - - return true; - } - - [NamedParameter] - public class NamedByteArray : Name<byte[]> - { - } - } - - public class Int16Test - { - private readonly short s; - - [Inject] - public Int16Test([Parameter(typeof(NamedShort))] short s) - { - this.s = s; - } - - public void Verify(short v) - { - Assert.AreEqual(v, s); - } - - [NamedParameter(DefaultValue = "3")] - public class NamedShort : Name<short> - { - } - } - - public class Int32Test - { - private readonly int i; - - [Inject] - public Int32Test([Parameter(typeof(NamedInt))] int i) - { - this.i = i; - } - - public void Verify(int v) - { - Assert.AreEqual(v, i); - } - - [NamedParameter(DefaultValue = "3")] - public class NamedInt : Name<int> - { - } - } - - public class Int64Test - { - private readonly long l; - - [Inject] - public Int64Test([Parameter(typeof(NamedLong))] long l) - { - this.l = l; - } - - public void Verify(int v) - { - Assert.AreEqual(v, l); - } - - [NamedParameter(DefaultValue = "34567")] - public class NamedLong : Name<long> - { - } - } - - public class FloatTest - { - private readonly float f; - - [Inject] - public FloatTest([Parameter(typeof(NamedSingle))] float f) - { - this.f = f; - } - - public void Verify(float v) - { - Assert.AreEqual(v, f); - } - - [NamedParameter(DefaultValue = "12.5")] - public class NamedSingle : Name<float> - { - } - } -} \ No newline at end of file
