Exemplo n.º 1
0
        public void TestCaseCasingSelectionRejection()
        {
            var anon1 = new
            {
                A = "1",
                a = "2"
            };

            var disemboweler1 = new SimpleTypeDisemboweler(
                anon1.GetType(),
                StringComparer.OrdinalIgnoreCase, ObjectFormatter);

            disemboweler1.ValidateMember += (sender, e) =>
            {
                Assert.AreSame(disemboweler1, sender);
                Assert.IsTrue(e.Accepted);
                Assert.NotNull(e.Member);
                Assert.AreSame(e.Member.DeclaringType, anon1.GetType());

                if (e.Member.Name == "A")
                {
                    e.Accepted = false;
                }
            };

            Assert.AreEqual("2", disemboweler1.Invoke(anon1, "A"));
            Assert.AreEqual("2", disemboweler1.Invoke(anon1, "a"));
        }
Exemplo n.º 2
0
        public void TestCaseStringFormat()
        {
            var disemboweler = new SimpleTypeDisemboweler(typeof(string), StringComparer.Ordinal, ObjectFormatter);
            var result       = disemboweler.Invoke(string.Empty, "Format", new object[] { "{0} {1} {2}!", "Hello", "weird", "world" });

            Assert.AreEqual("Hello weird world!", result);
        }
Exemplo n.º 3
0
        public void TestCaseParamErrors()
        {
            var disemboweler = new SimpleTypeDisemboweler(
                typeof(string),
                StringComparer.Ordinal,
                ObjectFormatter);

            ExpectArgumentNullException("member", () => disemboweler.Invoke(string.Empty, null));
            ExpectArgumentEmptyException("member", () => disemboweler.Invoke(string.Empty, string.Empty));
            ExpectArgumentNotIdentifierException("member", () => disemboweler.Invoke(string.Empty, "+Value"));
        }
Exemplo n.º 4
0
        private SimpleTypeDisemboweler GetDisembowelerForType([NotNull] Type type)
        {
            Debug.Assert(type != null, "type cannot be null.");

            if (!_disembowelers.TryGetValue(type, out var disemboweler))
            {
                disemboweler = new SimpleTypeDisemboweler(type, _identifierComparer, _objectFormatter);

                _disembowelers.Add(type, disemboweler);
            }

            return(disemboweler);
        }
Exemplo n.º 5
0
        public void TestCaseSensitive()
        {
            var disemboweler = new SimpleTypeDisemboweler(
                typeof(string),
                StringComparer.Ordinal,
                ObjectFormatter);

            const string Value = "Hello World";

            Assert.AreEqual(Value.Length, disemboweler.Invoke(Value, "Length"));
            Assert.AreEqual("HELLO WORLD", disemboweler.Invoke(Value, "ToUpper"));
            Assert.IsNull(disemboweler.Invoke(Value, "length"));
            Assert.IsNull(disemboweler.Invoke(Value, "LENGTH"));
            Assert.IsNull(disemboweler.Invoke(Value, "Toupper"));
        }
Exemplo n.º 6
0
        public void TestCaseConstruction()
        {
            ExpectArgumentNullException("type", () => new SimpleTypeDisemboweler(null, StringComparer.Ordinal, ObjectFormatter));
            ExpectArgumentNullException("memberComparer", () => new SimpleTypeDisemboweler(typeof(string), null, ObjectFormatter));
            ExpectArgumentNullException("objectFormatter", () => new SimpleTypeDisemboweler(typeof(string), StringComparer.Ordinal, null));

            var disemboweler = new SimpleTypeDisemboweler(
                typeof(string),
                StringComparer.CurrentCultureIgnoreCase,
                ObjectFormatter);

            Assert.AreEqual(typeof(string), disemboweler.Type);
            Assert.AreEqual(StringComparer.CurrentCultureIgnoreCase, disemboweler.Comparer);
            Assert.AreEqual(ObjectFormatter, disemboweler.ObjectFormatter);
        }
Exemplo n.º 7
0
        public void TestCaseOverloadedMethodSelection5()
        {
            var selectiveObject = new SelectiveObject();

            var disemboweler = new SimpleTypeDisemboweler(
                typeof(SelectiveObject),
                StringComparer.Ordinal,
                ObjectFormatter);

            disemboweler.Invoke(selectiveObject, "Function5");
            disemboweler.Invoke(selectiveObject, "Function5", new object[] { 1, 2 });
            disemboweler.Invoke(selectiveObject, "Function5", new object[] { (byte)1, (ushort)2, (uint)3, (long)4, 5.33, 6.23M });

            Assert.AreEqual("[...Int32()], [...Int32(1,2)], [...Int32(1,2,3,4,5,6)]", selectiveObject.ToString());
        }
Exemplo n.º 8
0
        public void TestCaseOverloadedMethodSelection4()
        {
            var selectiveObject = new SelectiveObject();

            var disemboweler = new SimpleTypeDisemboweler(
                typeof(SelectiveObject),
                StringComparer.Ordinal,
                ObjectFormatter);

            disemboweler.Invoke(selectiveObject, "Function4");
            disemboweler.Invoke(selectiveObject, "Function4", new object[] { null, null });
            disemboweler.Invoke(selectiveObject, "Function4", new object[] { true, 1.99, 2 });

            Assert.AreEqual("[...String()], [...String(!undefined!,!undefined!)], [...String(True,1.99,2)]", selectiveObject.ToString());
        }
Exemplo n.º 9
0
        public void TestCaseCasingSelectionTactics1()
        {
            var anon1 = new
            {
                VALUE = "1",
                Value = "2"
            };

            var disemboweler1 = new SimpleTypeDisemboweler(
                anon1.GetType(),
                StringComparer.OrdinalIgnoreCase, ObjectFormatter);

            Assert.AreEqual("1", disemboweler1.Invoke(anon1, "Value"));
            Assert.AreEqual("1", disemboweler1.Invoke(anon1, "value"));
            Assert.AreEqual("1", disemboweler1.Invoke(anon1, "VALUE"));
        }
Exemplo n.º 10
0
        public void TestCaseInsensitive()
        {
            var disemboweler = new SimpleTypeDisemboweler(
                typeof(string),
                StringComparer.OrdinalIgnoreCase,
                ObjectFormatter);

            const string Value = "Hello World";

            Assert.AreEqual(Value.Length, disemboweler.Invoke(Value, "Length"));
            Assert.AreEqual(Value.Length, disemboweler.Invoke(Value, "length"));
            Assert.AreEqual(Value.Length, disemboweler.Invoke(Value, "LENGTH"));
            Assert.AreEqual(Value.ToUpper(), disemboweler.Invoke(Value, "ToUpper"));
            Assert.AreEqual(Value.ToUpper(), disemboweler.Invoke(Value, "toupper"));
            Assert.AreEqual(Value.ToUpper(), disemboweler.Invoke(Value, "TOUPPER"));
        }
Exemplo n.º 11
0
        public void TestCaseOverloadedMethodSelection6()
        {
            var selectiveObject = new SelectiveObject();

            var disemboweler = new SimpleTypeDisemboweler(
                typeof(SelectiveObject),
                StringComparer.Ordinal,
                ObjectFormatter);

            disemboweler.Invoke(selectiveObject, "Function6");
            disemboweler.Invoke(selectiveObject, "Function6", new object[] { null });
            disemboweler.Invoke(selectiveObject, "Function6", new object[] { null, null });
            disemboweler.Invoke(selectiveObject, "Function6", new object[] { null, null, null });
            disemboweler.Invoke(selectiveObject, "Function6", new object[] { 1 });
            disemboweler.Invoke(selectiveObject, "Function6", new object[] { 1, "a" });
            disemboweler.Invoke(selectiveObject, "Function6", new object[] { 1, "a", false });

            Assert.AreEqual("[Object() ...Object()], [Object() ...Object()], [Object() Object()], [Object() ...Object()], [Object(1) ...Object()], [Object(1) Object(a)], [Object(1) ...Object(a,False)]", selectiveObject.ToString());
        }
Exemplo n.º 12
0
        public void TestCaseOverloadedMethodSelection2()
        {
            var selectiveObject = new SelectiveObject();

            var disemboweler = new SimpleTypeDisemboweler(
                typeof(SelectiveObject),
                StringComparer.Ordinal,
                ObjectFormatter);

            disemboweler.Invoke(selectiveObject, "Function2");
            disemboweler.Invoke(selectiveObject, "Function2", new object[] { "text", 34, 78 });
            disemboweler.Invoke(selectiveObject, "Function2", new object[] { StringComparer.InvariantCulture, 18 });
            disemboweler.Invoke(selectiveObject, "Function2", new object[] { 100, this });
            disemboweler.Invoke(selectiveObject, "Function2", new object[] { (short)99, string.Empty });
            disemboweler.Invoke(selectiveObject, "Function2", new object[] { 100.0, true });
            disemboweler.Invoke(selectiveObject, "Function2", new object[] { true, 1, 2 });

            Assert.AreEqual("Object(), Object(text), Object(System.CultureAwareComparer), Object(100), Object(99), Object(100), Object(True)", selectiveObject.ToString());
        }
Exemplo n.º 13
0
        public void TestCaseOverloadedMethodSelection1()
        {
            var selectiveObject = new SelectiveObject();

            var disemboweler = new SimpleTypeDisemboweler(
                typeof(SelectiveObject),
                StringComparer.Ordinal,
                ObjectFormatter);

            disemboweler.Invoke(selectiveObject, "Function1");
            disemboweler.Invoke(selectiveObject, "Function1", new object[] { "text" });
            disemboweler.Invoke(selectiveObject, "Function1", new object[] { StringComparer.InvariantCulture });
            disemboweler.Invoke(selectiveObject, "Function1", new object[] { 100 });
            disemboweler.Invoke(selectiveObject, "Function1", new object[] { (short)99 });
            disemboweler.Invoke(selectiveObject, "Function1", new object[] { 100.0 });
            disemboweler.Invoke(selectiveObject, "Function1", new object[] { true });

            Assert.AreEqual("Object(), String(text), Object(System.CultureAwareComparer), Int32(100), Int16(99), Double(100), Boolean(True)", selectiveObject.ToString());
        }
Exemplo n.º 14
0
        public void TestCaseOverloadedMethodSelection3()
        {
            var selectiveObject = new SelectiveObject();

            var disemboweler = new SimpleTypeDisemboweler(
                typeof(SelectiveObject),
                StringComparer.Ordinal,
                ObjectFormatter);

            disemboweler.Invoke(selectiveObject, "Function3");
            disemboweler.Invoke(selectiveObject, "Function3", new object[] { null, null });
            disemboweler.Invoke(selectiveObject, "Function3", new object[] { "text", 34, 78 });
            disemboweler.Invoke(selectiveObject, "Function3", new object[] { StringComparer.InvariantCulture, (byte)18 });
            disemboweler.Invoke(selectiveObject, "Function3", new object[] { 100, null });
            disemboweler.Invoke(selectiveObject, "Function3", new object[] { (short)99, string.Empty });
            disemboweler.Invoke(selectiveObject, "Function3", new object[] { 100.0, true });
            disemboweler.Invoke(selectiveObject, "Function3", new object[] { true, 1.99, 2 });

            Assert.AreEqual("[Object() Object()], [Object() Object()], [Object(text) Int32(34)], [Object(System.CultureAwareComparer) Int32(18)], [Object(100) Object()], [Object(99) Object()], [Object(100) Object(True)], [Object(True) Int32(2)]", selectiveObject.ToString());
        }