示例#1
0
        public void NotEqualToNonCallInfo()
        {
            var info = new CallInfo(0);

            Assert.False(info.Equals(null));
            Assert.False(info.Equals("CallInfo"));
            Assert.False(info.Equals(23));
        }
示例#2
0
        private static void RunHashCodeBenchmark()
        {
            var callInfo = new CallInfo(TargetType, null, Flags.InstanceAnyVisibility, MemberTypes.Field, "name",
                                        new[] { typeof(int), typeof(string) }, null, true);
            var callInfoOther = new CallInfo(typeof(CallInfo), null, Flags.InstanceAnyVisibility, MemberTypes.Field, "other",
                                             new[] { typeof(string) }, null, true);
            var sourceInfo      = SourceInfo.CreateFromType(new { ID = 42, Name = "Test" }.GetType());
            var sourceInfoOther = SourceInfo.CreateFromType(new { id = 42, Name = "Test" }.GetType());

            var initMap   = new Dictionary <string, Action> {
            };
            var actionMap = new Dictionary <string, Action>
            {
                { "CallInfo GetHashCode", () => callInfo.GetHashCode() },
                { "CallInfo Equals Other", () => callInfo.Equals(callInfoOther) },
                { "SourceInfo GetHashCode", () => sourceInfo.GetHashCode() },
                { "SourceInfo Equals Other", () => sourceInfo.Equals(sourceInfoOther) },
                { "string GetHashCode", () => "foo".GetHashCode() },
                { "string Equals", () => "foo".Equals("bar") },
                { "new CallInfo", () => new CallInfo(TargetType, null, Flags.InstanceAnyVisibility, MemberTypes.Field, "name",
                                                     new[] { typeof(int), typeof(string) }, null, true) },
                { "new SourceInfo", () => new SourceInfo(TargetType, new[] { "ID", "Name" }, new[] { typeof(int), typeof(string) }) },
                { "new SourceInfo anon", () => SourceInfo.CreateFromType(new { ID = 42, Name = "Test" }.GetType()) },
            };

            Execute("HashCode Benchmark", initMap, actionMap);
        }
示例#3
0
        public static void Equals_GetHashCode_ReturnsExpected(CallInfo info, object obj, bool expected)
        {
            Assert.Equal(expected, info.Equals(obj));

            if (obj is CallInfo)
            {
                // Failure at this point is not definitely a bug,
                // but should be considered a concern unless it can be
                // convincingly ruled a fluke.
                Assert.Equal(expected, info.GetHashCode().Equals(obj.GetHashCode()));
            }
        }
示例#4
0
 public void EqualityBasedOnNamesAndCount()
 {
     string[] names = new[] {"foo", "bar", "baz", "quux", "quuux"};
     for (int i = 0; i <= names.Length; ++i)
     {
         for (int j = 0; j != 3; ++j)
         {
             for (int x = 0; x <= names.Length; ++x)
             {
                 for (int y = 0; y != 3; ++y)
                 {
                     var info0 = new CallInfo(i + j, names.Take(i));
                     var info1 = new CallInfo(x + y, names.Take(x));
                     Assert.Equal(i == x & j == y, info0.Equals(info1));
                 }
             }
         }
     }
 }
示例#5
0
 public void HashCodeBasedOnEquality()
 {
     string[] names = new[] {"foo", "bar", "baz", "quux", "quuux"};
     for (int i = 0; i <= names.Length; ++i)
     {
         for (int j = 0; j != 3; ++j)
         {
             for (int x = 0; x <= names.Length; ++x)
             {
                 for (int y = 0; y != 3; ++y)
                 {
                     var info0 = new CallInfo(i + j, names.Take(i));
                     var info1 = new CallInfo(x + y, names.Take(x));
                     if (info0.Equals(info1))
                     {
                         Assert.Equal(info0.GetHashCode(), info1.GetHashCode());
                     }
                     else
                     {
                         // Failure at this point is not definitely a bug,
                         // but should be considered a concern unless it can be
                         // convincingly ruled a fluke.
                         Assert.NotEqual(info0.GetHashCode(), info1.GetHashCode());
                     }
                 }
             }
         }
     }
 }
示例#6
0
 public void NotEqualToNonCallInfo()
 {
     var info = new CallInfo(0);
     Assert.False(info.Equals(null));
     Assert.False(info.Equals("CallInfo"));
     Assert.False(info.Equals(23));
 }