Exemplo n.º 1
0
        public void testMatch()
        {
            /*
             * Now back to the bug I found: The problem stems from the fact
             * that java doesn't do deep equality for arrays. Little known to
             * me (I forget easily ;-), java arrays are equal only if they
             * are identical. Unfortunately the 2 sort methods returns a map
             * that is directly keyed on the value of the column without
             * considering this little fact. Conclusion there is a missing
             * and a surplus row where there should be one right row.
             * -- Jacques Morel
             */

            RowFixture  fixture      = new TestRowFixture();
            TypeAdapter arrayAdapter = TypeAdapter.on(fixture, typeof(BusinessObject).GetMethod("getStrings"));

            fixture.columnBindings = new TypeAdapter[] { arrayAdapter };

            ArrayList computed = new ArrayList();

            computed.Add(new BusinessObject(new String[] { "1" }));
            ArrayList expected = new ArrayList();

            expected.Add(new Parse("tr", "", new Parse("td", "1", null, null), null));
            fixture.match(expected, computed, 0);
            Assert.AreEqual(1, fixture.counts.right, "right");
            Assert.AreEqual(0, fixture.counts.exceptions, "exceptions");
            Assert.AreEqual(0, fixture.missing.Count, "missing");
            Assert.AreEqual(0, fixture.surplus.Count, "surplus");
        }
Exemplo n.º 2
0
        public virtual void enter()
        {
            MethodInfo method = findMethod(1);
            Type       type   = method.GetParameters()[0].ParameterType;
            String     text   = cells.more.more.text();

            Object[] args = { TypeAdapter.on(actor, type).parse(text) };
            method.Invoke(actor, args);
        }
Exemplo n.º 3
0
        protected virtual TypeAdapter bindField(string name)
        {
            String    camelName = camel(name);
            FieldInfo field     = getTargetClass().GetField(camelName);

            if (field == null)
            {
                throw new MissingFieldException(getTargetClass().FullName, camelName);
            }
            return(TypeAdapter.on(this, field));
        }
Exemplo n.º 4
0
        protected virtual TypeAdapter bindMethod(string name)
        {
            String     camelName = camel(name);
            MethodInfo method    = getTargetClass().GetMethod(camelName, new Type[] {});

            if (method == null)
            {
                throw new MissingMethodException(getTargetClass().FullName, camelName);
            }
            return(TypeAdapter.on(this, method));
        }
Exemplo n.º 5
0
        public void TestTypeAdapter()
        {
            TypeAdapterTarget target    = new TypeAdapterTarget();
            TypeAdapter       adapter   = TypeAdapter.on(target, typeof(int));
            object            parsedInt = adapter.parse("123");

            Assert.AreEqual(123, (int)parsedInt, "int");
            Assert.IsTrue(adapter.equals(parsedInt, 123), "int should be equal");

            adapter = TypeAdapter.on(target, typeof(float));
            Assert.AreEqual(12.3, (float)adapter.parse("12.3"), .00001, "float");

            adapter = TypeAdapter.on(target, typeof(long));
            Assert.AreEqual(123L, (long)adapter.parse("123"), "long");

            adapter = TypeAdapter.on(target, typeof(string));
            Assert.AreEqual("123", (string)adapter.parse("123"), "string");

            adapter = TypeAdapter.on(target, typeof(string[]));
            AssertArraysEqual(new object[] { "1", "2", "3" }, (object[])adapter.parse("1,2,3"), "string[]");
            Assert.AreEqual("1,2,3", adapter.ToString(new string[] { "1", "2", "3" }));

            adapter = TypeAdapter.on(target, typeof(int[]));
            AssertArraysEqual(new object[] { 1, 2, 3 }, (object[])adapter.parse("1,2,3"), "int[]");
            Assert.AreEqual("1,2,3", adapter.ToString(new int[] { 1, 2, 3 }));

            MethodInfo twoPi = typeof(TypeAdapterTarget).GetMethod("twoPi");

            adapter = TypeAdapter.on(target, twoPi);
            Assert.AreEqual(2 * Math.PI, adapter.get(), "twoPi");

            FieldInfo pi = target.GetType().GetField("pi");

            adapter = TypeAdapter.on(target, pi);
            adapter.set(3);
            Assert.AreEqual(3, target.pi, .00001, "pi");
            Assert.AreEqual(3, (double)adapter.get(), .00001, "adapted pi");
        }
Exemplo n.º 6
0
        public void testTypeAdapter()
        {
            TestFixture f = new TestFixture();
            TypeAdapter a = TypeAdapter.on(f, f.GetType().GetField("sampleInt"));

            a.set(a.parse("123456"));
            Assert.AreEqual(123456, f.sampleInt);
            Assert.AreEqual("-234567", a.parse("-234567").ToString());
            a = TypeAdapter.on(f, f.GetType().GetMethod("pi", new Type[] {}));
            Assert.AreEqual(3.14159, (double)a.get(), 0.00001);
            a = TypeAdapter.on(f, f.GetType().GetField("ch"));
            a.set(a.parse("a"));
            Assert.AreEqual('a', f.ch);
            a = TypeAdapter.on(f, f.GetType().GetField("name"));
            a.set(a.parse("xyzzy"));
            Assert.AreEqual("xyzzy", f.name);
            a = TypeAdapter.on(f, f.GetType().GetField("sampleFloat"));
            a.set(a.parse("6.02e23"));
            Assert.AreEqual(6.02e23, f.sampleFloat, 1e17);
            //      a = TypeAdapter.on(f, f.GetType().GetField("sampleArray"));
            //      a.set(a.parse("1,2,3"));
            //      Assert.AreEqual(1, f.sampleArray[0]);
            //      Assert.AreEqual(2, f.sampleArray[1]);
            //      Assert.AreEqual(3, f.sampleArray[2]);
            //      Assert.AreEqual("1,2,3", f.sampleArray.ToString());
            //      Assert.AreEqual(new int[] {1, 2, 3}, f.sampleArray);
            //      a = TypeAdapter.on(f, f.GetType().GetField("sampleDate"));
            //      DateTime date = new DateTime(1949,4,26);
            //      a.set(a.parse(DateFormat.getDateInstance().format(date)));
            //      Assert.AreEqual(date, f.sampleDate);
            a = TypeAdapter.on(f, f.GetType().GetField("sampleByte"));
            a.set(a.parse("123"));
            Assert.AreEqual((byte)123, f.sampleByte);
            a = TypeAdapter.on(f, f.GetType().GetField("sampleShort"));
            a.set(a.parse("12345"));
            Assert.AreEqual((short)12345, f.sampleShort);
        }
Exemplo n.º 7
0
        public virtual void check()
        {
            TypeAdapter adapter = TypeAdapter.on(actor, findMethod(0));

            check(cells.more.more, adapter);
        }