示例#1
0
        public void ContentHandlerLoadBinaryObjectFromTest()
        {
            var file = Path.GetTempFileName();

            using (var writer = new BinaryWriter(File.Open(file, FileMode.Create)))
            {
                writer.Write(0);
            }

            var h = new ContentHandler();

            _ = h.LoadObjectFrom(file);
        }
示例#2
0
        public void ContentHandlerLoadObjectFromSaveObjectToTest()
        {
            const string jsonTest = "{ \"Id\": 0, \"Name\": \"Joe\", \"IsShared\": true }";
            var          file     = Path.GetTempFileName();

            File.WriteAllText(file, jsonTest);
            var h       = new ContentHandler();
            var baseObj = h.LoadObjectFrom(file);

            Assert.AreEqual("0", ContentHandler.PropertyValueOf("Id", baseObj), "Id matches");
            Assert.AreEqual("Joe", ContentHandler.PropertyValueOf("Name", baseObj), "Name matches");
            Assert.AreEqual("True", ContentHandler.PropertyValueOf("IsShared", baseObj), "IsShared matches");
            Assert.IsTrue(ContentHandler.SetPropertyValueOfTo("Name", baseObj, "Jane"), "Change name");
            var fileOut = ContentHandler.SaveObjectTo(baseObj, "");
            var h2      = new ContentHandler();

            _ = h2.LoadObjectFrom(fileOut);
            Assert.AreEqual("0", ContentHandler.PropertyValueOf("Id", baseObj), "Unchanged Id matches");
            Assert.AreEqual("Jane", ContentHandler.PropertyValueOf("Name", baseObj), "Changed name matches");
            Assert.AreEqual("True", ContentHandler.PropertyValueOf("IsShared", baseObj), "Unchanged IsShared matches");
        }