コード例 #1
0
        public void SimpleObjectToTomlStringWorks()
        {
            var testObject = new SimplePrimitiveTestClass
            {
                MyBool     = true,
                MyFloat    = 420.69f,
                MyString   = "Hello, world!",
                MyDateTime = new DateTime(1970, 1, 1, 7, 0, 0, DateTimeKind.Utc)
            };

            var serializedForm = TomletMain.TomlStringFrom(testObject);

            Assert.Equal("MyString = \"Hello, world!\"\nMyFloat = 420.69000244140625\nMyBool = true\nMyDateTime = 1970-01-01T07:00:00", serializedForm.Trim());
        }
コード例 #2
0
        public void SerializingSimpleObjectAndDeserializingAgainGivesEquivalentObject()
        {
            var testObject = new SimplePrimitiveTestClass
            {
                MyBool     = true,
                MyFloat    = 420.69f,
                MyString   = "Hello, world!",
                MyDateTime = new DateTime(1970, 1, 1, 7, 0, 0, DateTimeKind.Utc)
            };

            var serializedForm = TomletMain.TomlStringFrom(testObject);

            var deserializedAgain = TomletMain.To <SimplePrimitiveTestClass>(serializedForm);

            Assert.Equal(testObject, deserializedAgain);
        }
コード例 #3
0
        public static void SimpleObjectToTomlDocWorks()
        {
            var testObject = new SimplePrimitiveTestClass
            {
                MyBool     = true,
                MyFloat    = 420.69f,
                MyString   = "Hello, world!",
                MyDateTime = new DateTime(1970, 1, 1, 7, 0, 0, DateTimeKind.Utc)
            };

            var tomlDoc = TomletMain.DocumentFrom(testObject);

            Assert.Equal(4, tomlDoc.Entries.Count);
            Assert.True(tomlDoc.GetBoolean("MyBool"));
            Assert.True(Math.Abs(tomlDoc.GetFloat("MyFloat") - 420.69) < 0.01);
            Assert.Equal("Hello, world!", tomlDoc.GetString("MyString"));
            Assert.Equal("1970-01-01T07:00:00", tomlDoc.GetValue("MyDateTime").StringValue);
        }