Пример #1
0
        public void CanFetchMethodWithConstraintTest()
        {
            var returnsInt = AttributeScanner
                             .GetMethodAttributes <TestConstraintAttribute>()
                             .WithSignature(MethodSignature.Func <int>())
                             .ToList();

            Assert.IsTrue(returnsInt.Count == 1);
            Assert.AreEqual(returnsInt[0].Method.Name, nameof(TypeWithMethodConstraintsAttribute.ReturnsInt));

            var floatToInt = AttributeScanner
                             .GetMethodAttributes <TestConstraintAttribute>()
                             .WithSignature(MethodSignature.Func <float, int>())
                             .ToList();

            Assert.IsTrue(floatToInt.Count == 1);
            Assert.AreEqual(floatToInt[0].Method.Name, nameof(TypeWithMethodConstraintsAttribute.FloatToInt));

            var voidToVoid = AttributeScanner
                             .GetMethodAttributes <TestConstraintAttribute>()
                             .WithSignature(MethodSignature.Action())
                             .ToList();

            Assert.IsTrue(voidToVoid.Count == 1);
            Assert.AreEqual(voidToVoid[0].Method.Name, nameof(TypeWithMethodConstraintsAttribute.VoidToVoid));

            var floatToVoid = AttributeScanner
                              .GetMethodAttributes <TestConstraintAttribute>()
                              .WithSignature(MethodSignature.Action <float>())
                              .ToList();

            Assert.IsTrue(floatToVoid.Count == 3);
            Assert.AreEqual(floatToVoid[0].Method.Name, nameof(TypeWithMethodConstraintsAttribute.FloatToVoid));
            Assert.AreEqual(floatToVoid[1].Method.Name, nameof(TypeWithMethodConstraintsAttribute.FloatToVoid2));
            Assert.AreEqual(floatToVoid[2].Method.Name, nameof(FloatClass.TToVoid));

            var multipleConstraints = AttributeScanner
                                      .GetMethodAttributes <TestConstraintAttribute>()
                                      .Static()
                                      .WithSignature(MethodSignature.Action <float>())
                                      .ToList();

            Assert.IsTrue(multipleConstraints.Count == 1);
            Assert.AreEqual(multipleConstraints[0].Method.Name,
                            nameof(TypeWithMethodConstraintsAttribute.FloatToVoid2));

            Assert.IsFalse(AttributeScanner
                           .GetMethodAttributes <TestConstraintAttribute>()
                           .Static()
                           .Instance()
                           .Any());
        }
Пример #2
0
 public void SignatureNameMatchesTest()
 {
     Assert.AreEqual("()=>void", MethodSignature.Action().GetSignatureName());
     Assert.AreEqual("(string)=>void", MethodSignature.Action <string>().GetSignatureName());
     Assert.AreEqual("(float, string)=>void", MethodSignature.Action <float, string>().GetSignatureName());
     Assert.AreEqual("(TestGeneric<string>)=>void", MethodSignature.Action <TestGeneric <string> >().GetSignatureName());
     Assert.AreEqual("(TestGeneric<TestGeneric<int>>)=>void", MethodSignature.Action <TestGeneric <TestGeneric <int> > >().GetSignatureName());
     Assert.AreEqual("()=>float", MethodSignature.Func <float>().GetSignatureName());
     Assert.AreEqual("(string)=>int", MethodSignature.Func <string, int>().GetSignatureName());
     Assert.AreEqual("(float, string)=>TestGeneric<double>", MethodSignature.Func <float, string, TestGeneric <double> >().GetSignatureName());
     Assert.AreEqual("(IntGeneric)=>sbyte", MethodSignature.Func <IntGeneric, sbyte>().GetSignatureName());
     Assert.AreEqual("(ITestName)=>ITestGenericName<ulong>", MethodSignature.Func <ITestName, ITestGenericName <ulong> >().GetSignatureName());
 }