Example #1
0
    public void TestSample()
    {
        var mockSum = new Mock <ISum>();

        mockSum.Setup();     // fill this what you want
        var sampleObj = new SampleObj(mockSum.Object);
        //Do Some Asserts
    }
Example #2
0
        public void TestObject()
        {
            var jd = new JsonDeserializer();

            var w = new SampleObj();
            const string str = "{ \"F\": 123.4 }";
            jd.FromString(w, str);
            Assert.AreEqual(123.4, w.F);
            var wg = new SampleObj();
            SampleObj_JsonDeserializer.Instance.FromString(wg, str);
            Assert.AreEqual(123.4, wg.F);

            jd.FromString(w, "{ \"F\": [1,2,3] }");
            CollectionAssert.AreEqual(new object[] { 1.0, 2.0, 3.0 }, (List<object>)w.F);
            jd.FromString(w, "{ \"F\": {\"a\":\"1\", \"b\": \"2\"} }");
            CollectionAssert.AreEqual(
                new Dictionary<string, object>() { { "a", "1" }, { "b", "2" } },
                (Dictionary<string, object>)w.F);
            Assert.AreEqual(typeof(Dictionary<string, object>), jd.FromString("{}").GetType());
            Assert.AreEqual(typeof(Dictionary<string, object>), jd.FromString<object>("{}").GetType());

            var d = jd.FromString("{ \"F\": [1,2,3] }");
            Assert.AreEqual(typeof(Dictionary<string, object>), d.GetType());
            CollectionAssert.AreEqual(
                new object[] { 1.0, 2.0, 3.0 },
                (List<object>)((Dictionary<string,object>)d)["F"]);

            d = jd.FromString("{ \"F\": {\"class\": \"YuzuTest.SampleObj, YuzuTest\", \"F\": null } }");
            Assert.AreEqual(typeof(Dictionary<string, object>), d.GetType());
            var f = ((Dictionary<string, object>)d)["F"];
            Assert.IsInstanceOfType(f, typeof(SampleObj));
            Assert.AreEqual(null, ((SampleObj)f).F);

            var js = new JsonSerializer();
            js.JsonOptions.Indent = "";
            js.JsonOptions.FieldSeparator = "";
            Assert.AreEqual("[\"q\",[1]]", js.ToString(new List<object> { "q", new List<int> { 1 } }));
        }
Example #3
0
        public void TestObject()
        {
            var bd = new BinaryDeserializer();
            var w = new SampleObj();
            var buf =  SX(
                "20 01 00 " + XS(typeof(SampleObj)) + " 01 00 " + XS("F", RoughType.Any) +
                " 01 00 " + XS(RoughType.Float) + " CD CC F6 42 00 00");
            bd.FromBytes(w, buf);
            Assert.AreEqual(123.4f, w.F);
            var wg = new SampleObj();
            (new BinaryDeserializerGen()).FromBytes(wg, buf);
            Assert.AreEqual(123.4f, wg.F);

            bd.FromBytes(w, SX("20 01 00 01 00 21 02 03 00 00 00 01 02 03 00 00"));
            CollectionAssert.AreEqual(new byte[] { 1, 2, 3 }, (List<byte>)w.F);
            bd.FromBytes(w, SX(
                "20 01 00 01 00 22 10 03 02 00 00 00 " +
                XS("a") + " 01 00 " + XS("b") + " 02 00 00 00"));
            CollectionAssert.AreEqual(
                new Dictionary<string, short>() { { "a", 1 }, { "b", 2 } },
                (Dictionary<string, short>)w.F);

            Assert.AreEqual(
                typeof(Dictionary<string, object>),
                bd.FromBytes(new byte[] { 0x22, 0x10, (byte)RoughType.Any, 00, 00, 00, 00 }).GetType());
            CollectionAssert.AreEqual(
                (List<object>)bd.FromBytes(SX("21 11 02 00 00 00 01 05 10 " + XS("abc"))),
                new object[] { (sbyte)5, "abc" });

            Assert.AreEqual((short)266, bd.FromBytes<object>(SX("03 0A 01")));

            var bs = new BinarySerializer();
            Assert.AreEqual(
                "21 11 02 00 00 00 10 " + XS("q") + " 21 05 01 00 00 00 01 00 00 00",
                XS(bs.ToBytes(new List<object> { "q", new List<int> { 1 } })));
        }