Ejemplo n.º 1
0
        public void TestDeserialization(SerializationTestCase testCase)
        {
            var(preferences, persister) = Setup();

            using (persister) {
                var optionKey = testCase.Wrap(preferences);
                var property  = optionKey.GetPropertyName();

                // Set the value and deserialize it
                PropertyService.Set(property, testCase.SerializedValue);
                var success = persister.TryFetch(optionKey, out var deserialized);
                Assert.AreEqual(testCase.Success, success);
                Assert.AreEqual(testCase.Value, deserialized, $"Could not convert {testCase.SerializedValue} to {testCase.Value}");
            }
        }
        public void TestDeserialization(SerializationTestCase testCase)
        {
            var(preferences, persister) = Setup();

            using (persister) {
                var optionKey = testCase.Wrap(preferences);
                var property  = optionKey.GetPropertyName();

                // Set the value and deserialize it
                PropertyService.Set(property, testCase.SerializedValue);
                Assert.AreEqual(testCase.Success, persister.TryFetch(optionKey, out var deserialized));
                if (!testCase.Success)
                {
                    Assert.IsNull(deserialized);
                    return;
                }

                Assert.AreEqual(testCase.Value, deserialized);
            }
        }
Ejemplo n.º 3
0
        public void TestSerialization(SerializationTestCase testCase)
        {
            var(preferences, persister) = Setup();

            using (persister) {
                var optionKey = testCase.Wrap(preferences);

                var property = optionKey.GetPropertyName();
                PropertyService.Set(property, null);

                // Try persisting it.
                Assert.AreEqual(testCase.Success, persister.TryPersist(optionKey, testCase.Value));
                if (!testCase.Success)
                {
                    Assert.IsFalse(PropertyService.HasValue(property));
                    return;
                }

                // See if we can deserialize it back as-is
                Assert.AreEqual(testCase.SerializedValue, PropertyService.Get <object> (property));
                Assert.AreEqual(testCase.Success, persister.TryFetch(optionKey, out var deserializedValue));
                Assert.AreEqual(testCase.Value, deserializedValue);
            }
        }