示例#1
0
        public void TestDictionaryToModel()
        {
            var     now   = DateTime.Now;
            var     id    = Guid.NewGuid().ToString();
            var     name  = "My Roving";
            decimal price = 12.00m;
            var     qty   = 1;

            var compareDict = new Dictionary <string, object> {
                { "ID", id },
                { "Name", name },
                { "Price", price },
                { "Qty", qty },
                { "DateCreated", now },
                { "DateModified", now },
                { "InventoryType", InventoryType.ROVING },
                { "Materials", null },
                { "Weight", null },
                { "Length", null }
            };
            var model      = compareDict.FromDictionary <Roving>();
            var testRoving = new Roving
            {
                Name         = name,
                Price        = price,
                ID           = id,
                Qty          = qty,
                DateCreated  = now,
                DateModified = now
            };

            Assert.AreEqual(JsonConvert.SerializeObject(model), JsonConvert.SerializeObject(testRoving), "Does not contain same props");
        }
示例#2
0
        public void TestToDictionary()
        {
            var     now   = DateTime.Now;
            var     id    = Guid.NewGuid().ToString();
            var     name  = "My Roving";
            decimal price = 12.00m;
            var     qty   = 1;

            var testRoving = new Roving
            {
                Name         = name,
                Price        = price,
                ID           = id,
                Qty          = qty,
                DateCreated  = now,
                DateModified = now
            };
            var modelDict = testRoving.ToDictionary();

            var compareDict = new Dictionary <string, object> {
                { "ID", id },
                { "Name", name },
                { "Price", price },
                { "Qty", qty },
                { "DateCreated", now },
                { "DateModified", now },
                { "InventoryType", InventoryType.ROVING },
                { "Materials", null },
                { "Weight", null },
                { "Length", null }
            };

            CollectionAssert.AreEquivalent(modelDict, compareDict, "not equivalent");
        }