diff --git a/GazeInputTest/GazeInputTest.csproj b/GazeInputTest/GazeInputTest.csproj
index 9364b18cddc..3454b492f5c 100644
--- a/GazeInputTest/GazeInputTest.csproj
+++ b/GazeInputTest/GazeInputTest.csproj
@@ -12,7 +12,7 @@
en-USUAP10.0.19041.0
- 10.0.17134.0
+ 10.0.17763.014512{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Controls/SampleAppMarkdownRenderer.cs b/Microsoft.Toolkit.Uwp.SampleApp/Controls/SampleAppMarkdownRenderer.cs
index dc671f7c5a6..ecc9cb6cc2a 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/Controls/SampleAppMarkdownRenderer.cs
+++ b/Microsoft.Toolkit.Uwp.SampleApp/Controls/SampleAppMarkdownRenderer.cs
@@ -416,7 +416,7 @@ public string DesiredLang
///
/// The Local Storage Helper.
///
- private LocalObjectStorageHelper storage = new LocalObjectStorageHelper();
+ private LocalObjectStorageHelper storage = new LocalObjectStorageHelper(new SystemSerializer());
///
/// DocFX note types and styling info, keyed by identifier.
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs b/Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs
index 1db3fbd9e7e..157caa2114b 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs
+++ b/Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs
@@ -39,7 +39,7 @@ public class Sample
public static async void EnsureCacheLatest()
{
- var settingsStorage = new LocalObjectStorageHelper();
+ var settingsStorage = new LocalObjectStorageHelper(new SystemSerializer());
var onlineDocsSHA = await GetDocsSHA();
var cacheSHA = settingsStorage.Read(_cacheSHAKey);
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Models/Samples.cs b/Microsoft.Toolkit.Uwp.SampleApp/Models/Samples.cs
index 901bea050e8..0aa18896ad4 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/Models/Samples.cs
+++ b/Microsoft.Toolkit.Uwp.SampleApp/Models/Samples.cs
@@ -21,7 +21,7 @@ public static class Samples
private static SemaphoreSlim _semaphore = new SemaphoreSlim(1);
private static LinkedList _recentSamples;
- private static RoamingObjectStorageHelper _roamingObjectStorageHelper = new RoamingObjectStorageHelper();
+ private static LocalObjectStorageHelper _localObjectStorageHelper = new LocalObjectStorageHelper(new SystemSerializer());
public static async Task GetCategoryBySample(Sample sample)
{
@@ -98,7 +98,7 @@ public static async Task> GetRecentSamples()
if (_recentSamples == null)
{
_recentSamples = new LinkedList();
- var savedSamples = _roamingObjectStorageHelper.Read(_recentSamplesStorageKey);
+ var savedSamples = _localObjectStorageHelper.Read(_recentSamplesStorageKey);
if (savedSamples != null)
{
@@ -144,7 +144,7 @@ private static void SaveRecentSamples()
}
var str = string.Join(";", _recentSamples.Take(10).Select(s => s.Name).ToArray());
- _roamingObjectStorageHelper.Save(_recentSamplesStorageKey, str);
+ _localObjectStorageHelper.Save(_recentSamplesStorageKey, str);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Object Storage/ObjectStoragePage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Object Storage/ObjectStoragePage.xaml
index e782345850d..3fc3f747d91 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Object Storage/ObjectStoragePage.xaml
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Object Storage/ObjectStoragePage.xaml
@@ -1,26 +1,33 @@
-
+
-
+
-
+
-
-
-
-
-
+
+
+
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Object Storage/ObjectStoragePage.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Object Storage/ObjectStoragePage.xaml.cs
index 7bde074a771..8f18c5865ee 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Object Storage/ObjectStoragePage.xaml.cs
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Object Storage/ObjectStoragePage.xaml.cs
@@ -9,8 +9,7 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
public sealed partial class ObjectStoragePage
{
- private readonly IObjectStorageHelper localStorageHelper = new LocalObjectStorageHelper();
- private readonly IObjectStorageHelper roamingStorageHelper = new RoamingObjectStorageHelper();
+ private readonly IObjectStorageHelper localStorageHelper = new LocalObjectStorageHelper(new SystemSerializer());
public ObjectStoragePage()
{
@@ -24,21 +23,10 @@ private void ReadButton_Click(object sender, RoutedEventArgs e)
return;
}
- if (StorageModeToggle.IsOn)
+ // Read from local storage
+ if (localStorageHelper.KeyExists(KeyTextBox.Text))
{
- // Read from roaming storage
- if (roamingStorageHelper.KeyExists(KeyTextBox.Text))
- {
- ContentTextBox.Text = roamingStorageHelper.Read(KeyTextBox.Text);
- }
- }
- else
- {
- // Read from local storage
- if (localStorageHelper.KeyExists(KeyTextBox.Text))
- {
- ContentTextBox.Text = localStorageHelper.Read(KeyTextBox.Text);
- }
+ ContentTextBox.Text = localStorageHelper.Read(KeyTextBox.Text);
}
}
@@ -54,16 +42,8 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
return;
}
- if (StorageModeToggle.IsOn)
- {
- // Save into roaming storage
- roamingStorageHelper.Save(KeyTextBox.Text, ContentTextBox.Text);
- }
- else
- {
- // Save into local storage
- localStorageHelper.Save(KeyTextBox.Text, ContentTextBox.Text);
- }
+ // Save into local storage
+ localStorageHelper.Save(KeyTextBox.Text, ContentTextBox.Text);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/BaseObjectStorageHelper.cs b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/BaseObjectStorageHelper.cs
index bf724ac796e..df446a3b85d 100644
--- a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/BaseObjectStorageHelper.cs
+++ b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/BaseObjectStorageHelper.cs
@@ -21,14 +21,13 @@ public abstract class BaseObjectStorageHelper : IObjectStorageHelper
///
/// Initializes a new instance of the class,
/// which can read and write data using the provided ;
- /// if none is provided, a default Json serializer will be used (based on ).
- /// In 6.1 and older the default Serializer was based on Newtonsoft.Json and the new default Serializer may behave differently.
+ /// In 6.1 and older the default Serializer was based on Newtonsoft.Json.
/// To implement a based on Newtonsoft.Json or System.Text.Json see https://aka.ms/wct/storagehelper-migration
///
/// The serializer to use.
- public BaseObjectStorageHelper(IObjectSerializer objectSerializer = null)
+ public BaseObjectStorageHelper(IObjectSerializer objectSerializer)
{
- serializer = objectSerializer ?? new JsonObjectSerializer();
+ serializer = objectSerializer ?? throw new ArgumentNullException(nameof(objectSerializer));
}
///
@@ -85,15 +84,7 @@ public bool KeyExists(string compositeKey, string key)
return @default;
}
- var type = typeof(T);
- var typeInfo = type.GetTypeInfo();
-
- if (typeInfo.IsPrimitive || type == typeof(string))
- {
- return (T)Convert.ChangeType(value, type);
- }
-
- return serializer.Deserialize((string)value);
+ return serializer.Deserialize(value);
}
///
@@ -132,14 +123,7 @@ public void Save(string key, T value)
var type = typeof(T);
var typeInfo = type.GetTypeInfo();
- if (typeInfo.IsPrimitive || type == typeof(string))
- {
- Settings.Values[key] = value;
- }
- else
- {
- Settings.Values[key] = serializer.Serialize(value);
- }
+ Settings.Values[key] = serializer.Serialize(value);
}
///
@@ -214,7 +198,7 @@ public Task FileExistsAsync(string filePath)
/// The where the object was saved
public Task SaveFileAsync(string filePath, T value)
{
- return StorageFileHelper.WriteTextToFileAsync(Folder, serializer.Serialize(value), filePath, CreationCollisionOption.ReplaceExisting);
+ return StorageFileHelper.WriteTextToFileAsync(Folder, serializer.Serialize(value)?.ToString(), filePath, CreationCollisionOption.ReplaceExisting);
}
}
}
diff --git a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/IObjectSerializer.cs b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/IObjectSerializer.cs
index 3dbad93431e..44bc8b1adac 100644
--- a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/IObjectSerializer.cs
+++ b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/IObjectSerializer.cs
@@ -10,19 +10,19 @@ namespace Microsoft.Toolkit.Uwp.Helpers
public interface IObjectSerializer
{
///
- /// Serialize an object into a string.
+ /// Serialize an object into a string. It is recommended to use strings as the final format for objects if you plan to use the method.
///
/// The type of the object to serialize.
/// The object to serialize.
/// The serialized object.
- string Serialize(T value);
+ object Serialize(T value);
///
- /// Deserialize a string into an object.
+ /// Deserialize a primitive or string into an object of the given type.
///
/// The type of the deserialized object.
/// The string to deserialize.
/// The deserialized object.
- T Deserialize(string value);
+ T Deserialize(object value);
}
}
diff --git a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/JsonObjectSerializer.cs b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/JsonObjectSerializer.cs
deleted file mode 100644
index cb962714b2d..00000000000
--- a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/JsonObjectSerializer.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.IO;
-using System.Runtime.Serialization.Json;
-using System.Text;
-
-namespace Microsoft.Toolkit.Uwp.Helpers
-{
- internal class JsonObjectSerializer : IObjectSerializer
- {
- public string Serialize(T value)
- {
- using var sr = new MemoryStream();
-
- new DataContractJsonSerializer(typeof(T)).WriteObject(sr, value);
- var json = sr.ToArray();
- return Encoding.UTF8.GetString(json, 0, json.Length);
- }
-
- public T Deserialize(string value)
- {
- using var ms = new MemoryStream(Encoding.UTF8.GetBytes(value));
-
- return (T)new DataContractJsonSerializer(typeof(T)).ReadObject(ms);
- }
- }
-}
diff --git a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/LocalObjectStorageHelper.cs b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/LocalObjectStorageHelper.cs
index 0b717fb2d83..ff56f155ec4 100644
--- a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/LocalObjectStorageHelper.cs
+++ b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/LocalObjectStorageHelper.cs
@@ -15,12 +15,11 @@ public class LocalObjectStorageHelper : BaseObjectStorageHelper
///
/// Initializes a new instance of the class,
/// which can read and write data using the provided ;
- /// if none is provided, a default Json serializer will be used (based on ).
- /// In 6.1 and older the default Serializer was based on Newtonsoft.Json and the new default Serializer may behave differently.
- /// To implement a based on Newtonsoft.Json or System.Text.Json see https://aka.ms/wct/storagehelper-migration
+ /// In 6.1 and older the default Serializer was based on Newtonsoft.Json.
+ /// To implement an based on System.Text.Json, Newtonsoft.Json, or DataContractJsonSerializer see https://aka.ms/wct/storagehelper-migration
///
/// The serializer to use.
- public LocalObjectStorageHelper(IObjectSerializer objectSerializer = null)
+ public LocalObjectStorageHelper(IObjectSerializer objectSerializer)
: base(objectSerializer)
{
Settings = ApplicationData.Current.LocalSettings;
diff --git a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/RoamingObjectStorageHelper.cs b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/RoamingObjectStorageHelper.cs
index e2d9ae9b2b6..bfd8e7884ed 100644
--- a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/RoamingObjectStorageHelper.cs
+++ b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/RoamingObjectStorageHelper.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System;
using System.Runtime.Serialization;
using Windows.Storage;
@@ -10,17 +11,17 @@ namespace Microsoft.Toolkit.Uwp.Helpers
///
/// Store data in the Roaming environment (shared across all user devices).
///
+ [Obsolete("Package State Roaming will be removed in a futures Windows Update, see https://docs.microsoft.com/windows/deployment/planning/windows-10-deprecated-features for more information.")]
public class RoamingObjectStorageHelper : BaseObjectStorageHelper
{
///
/// Initializes a new instance of the class,
/// which can read and write data using the provided ;
- /// if none is provided, a default Json serializer will be used (based on ).
- /// In 6.1 and older the default Serializer was based on Newtonsoft.Json and the new default Serializer may behave differently.
- /// To implement a based on Newtonsoft.Json or System.Text.Json see https://aka.ms/wct/storagehelper-migration
+ /// In 6.1 and older the default Serializer was based on Newtonsoft.Json.
+ /// To implement an based on System.Text.Json, Newtonsoft.Json, or DataContractJsonSerializer see https://aka.ms/wct/storagehelper-migration
///
/// The serializer to use.
- public RoamingObjectStorageHelper(IObjectSerializer objectSerializer = null)
+ public RoamingObjectStorageHelper(IObjectSerializer objectSerializer)
: base(objectSerializer)
{
Settings = ApplicationData.Current.RoamingSettings;
diff --git a/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/SystemSerializer.cs b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/SystemSerializer.cs
new file mode 100644
index 00000000000..61f247d3eed
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp/Helpers/ObjectStorage/SystemSerializer.cs
@@ -0,0 +1,48 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Reflection;
+using Microsoft.Toolkit.Diagnostics;
+using Windows.Storage;
+
+namespace Microsoft.Toolkit.Uwp.Helpers
+{
+ ///
+ /// A bare-bones serializer which knows how to deal with primitive types and strings only. It will store them directly based on the API.
+ /// It is recommended for more complex scenarios to implement your own based on System.Text.Json, Newtonsoft.Json, or DataContractJsonSerializer see https://aka.ms/wct/storagehelper-migration
+ ///
+ public class SystemSerializer : IObjectSerializer
+ {
+ ///
+ /// Take a primitive value from storage and return it as the requested type using the API.
+ ///
+ /// Type to convert value to.
+ /// Value from storage to convert.
+ /// Deserialized value or default value.
+ public T Deserialize(object value)
+ {
+ var type = typeof(T);
+ var typeInfo = type.GetTypeInfo();
+
+ if (typeInfo.IsPrimitive || type == typeof(string))
+ {
+ return (T)Convert.ChangeType(value, type);
+ }
+
+ return ThrowHelper.ThrowNotSupportedException("This serializer can only handle primitive types and strings. Please implement your own IObjectSerializer for more complex scenarios.");
+ }
+
+ ///
+ /// Returns the value so that it can be serialized by the API directly.
+ ///
+ /// Type to serialize from.
+ /// Value to serialize.
+ /// String representation of value.
+ public object Serialize(T value)
+ {
+ return value;
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp/Helpers/SystemInformation.cs b/Microsoft.Toolkit.Uwp/Helpers/SystemInformation.cs
index 72357b3f790..42c06cdb545 100644
--- a/Microsoft.Toolkit.Uwp/Helpers/SystemInformation.cs
+++ b/Microsoft.Toolkit.Uwp/Helpers/SystemInformation.cs
@@ -21,7 +21,7 @@ namespace Microsoft.Toolkit.Uwp.Helpers
///
public sealed class SystemInformation
{
- private readonly LocalObjectStorageHelper _localObjectStorageHelper = new LocalObjectStorageHelper();
+ private readonly LocalObjectStorageHelper _localObjectStorageHelper = new LocalObjectStorageHelper(new SystemSerializer());
private DateTime _sessionStart;
///
diff --git a/UnitTests/UnitTests.UWP/Helpers/JsonObjectSerializer.cs b/UnitTests/UnitTests.UWP/Helpers/JsonObjectSerializer.cs
new file mode 100644
index 00000000000..7df00beec25
--- /dev/null
+++ b/UnitTests/UnitTests.UWP/Helpers/JsonObjectSerializer.cs
@@ -0,0 +1,47 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Reflection;
+using Microsoft.Toolkit.Uwp.Helpers;
+using Newtonsoft.Json;
+
+namespace UnitTests.UWP.Helpers
+{
+ ///
+ /// This is a Serializer which should mimic the previous functionality of 6.1.1 release of the Toolkit with Newtonsoft.Json.
+ ///
+ internal class JsonObjectSerializer : IObjectSerializer
+ {
+ public T Deserialize(object value)
+ {
+ var type = typeof(T);
+ var typeInfo = type.GetTypeInfo();
+
+ // Note: If you're creating a new app, you could just use the serializer directly.
+ // This if/return combo is to maintain compatibility with 6.1.1
+ if (typeInfo.IsPrimitive || type == typeof(string))
+ {
+ return (T)Convert.ChangeType(value, type);
+ }
+
+ return JsonConvert.DeserializeObject((string)value);
+ }
+
+ public object Serialize(T value)
+ {
+ var type = typeof(T);
+ var typeInfo = type.GetTypeInfo();
+
+ // Note: If you're creating a new app, you could just use the serializer directly.
+ // This if/return combo is to maintain compatibility with 6.1.1
+ if (typeInfo.IsPrimitive || type == typeof(string))
+ {
+ return value;
+ }
+
+ return JsonConvert.SerializeObject(value);
+ }
+ }
+}
diff --git a/UnitTests/UnitTests.UWP/Helpers/SystemTextJsonSerializer.cs b/UnitTests/UnitTests.UWP/Helpers/SystemTextJsonSerializer.cs
new file mode 100644
index 00000000000..4b6a2c576c9
--- /dev/null
+++ b/UnitTests/UnitTests.UWP/Helpers/SystemTextJsonSerializer.cs
@@ -0,0 +1,20 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Text.Json;
+using Microsoft.Toolkit.Uwp.Helpers;
+
+namespace UnitTests.UWP.Helpers
+{
+ ///
+ /// Example class of writing a new that uses System.Text.Json.
+ ///
+ internal class SystemTextJsonSerializer : IObjectSerializer
+ {
+ public T Deserialize(object value) => JsonSerializer.Deserialize(value as string);
+
+ public object Serialize(T value) => JsonSerializer.Serialize(value);
+ }
+}
diff --git a/UnitTests/UnitTests.UWP/Helpers/Test_StorageHelper.cs b/UnitTests/UnitTests.UWP/Helpers/Test_StorageHelper.cs
index 53698707f70..c5162f2f389 100644
--- a/UnitTests/UnitTests.UWP/Helpers/Test_StorageHelper.cs
+++ b/UnitTests/UnitTests.UWP/Helpers/Test_StorageHelper.cs
@@ -2,18 +2,35 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System;
using Microsoft.Toolkit.Uwp.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-using System.Text.Json;
-using UnitTests.UI;
+using Newtonsoft.Json;
+using UnitTests.UWP.Helpers;
+using Windows.Storage;
namespace UnitTests.Helpers
{
[TestClass]
public class Test_StorageHelper
{
- private LocalObjectStorageHelper storageHelper = new LocalObjectStorageHelper();
+ private LocalObjectStorageHelper _localStorageHelperSystem = new LocalObjectStorageHelper(new SystemSerializer());
+ private LocalObjectStorageHelper _localStorageHelperJsonCompat = new LocalObjectStorageHelper(new JsonObjectSerializer());
+
+ private LocalObjectStorageHelper _localStorageHelperJsonNew = new LocalObjectStorageHelper(new SystemTextJsonSerializer());
+
+ ///
+ /// Checks that we're running 10.0.3 version of Newtonsoft.Json package which we used in 6.1.1.
+ ///
+ [TestCategory("Helpers")]
+ [TestMethod]
+ public void Test_StorageHelper_CheckNewtonsoftVersion()
+ {
+ var version = typeof(JsonSerializer).Assembly.GetName().Version;
+ Assert.AreEqual(10, version.Major);
+ Assert.AreEqual(0, version.Minor);
+ Assert.AreEqual(0, version.Revision); // Apparently the file revision was not updated for the updated package
+ }
[TestCategory("Helpers")]
[TestMethod]
@@ -23,38 +40,57 @@ public void Test_StorageHelper_LegacyIntTest()
int input = 42;
- // simulate previous version by generating json and manually inserting it as string
- string jsonInput = JsonSerializer.Serialize(input);
-
- storageHelper.Save(key, jsonInput);
+ // Use our previous Json layer to store value
+ _localStorageHelperJsonCompat.Save(key, input);
- // now read it as int to valid that the change works
- int output = storageHelper.Read(key, 0);
+ // But try and read from our new system to see if it works
+ int output = _localStorageHelperSystem.Read(key, 0);
Assert.AreEqual(input, output);
}
- [Ignore]
+ ///
+ /// If we try and deserialize a complex type with the , we do a check ourselves and will throw our own exception.
+ ///
[TestCategory("Helpers")]
[TestMethod]
- public void Test_StorageHelper_LegacyDateTest()
+ [ExpectedException(typeof(NotSupportedException))]
+ public void Test_StorageHelper_LegacyDateTestFailure()
{
string key = "ChristmasDay";
DateTime input = new DateTime(2017, 12, 25);
- // simulate previous version by generating json and manually inserting it as string
- string jsonInput = JsonSerializer.Serialize(input);
-
- storageHelper.Save(key, jsonInput);
+ _localStorageHelperJsonCompat.Save(key, input);
// now read it as int to valid that the change works
- DateTime output = storageHelper.Read(key, DateTime.Today);
+ DateTime output = _localStorageHelperSystem.Read(key, DateTime.Today);
+ }
- Assert.AreEqual(input, output);
+ ///
+ /// The doesn't support complex types, since it just passes through directly.
+ /// We'll get the argument exception from the API.
+ ///
+ [TestCategory("Helpers")]
+ [TestMethod]
+ public void Test_StorageHelper_DateTestFailure()
+ {
+ Exception expectedException = null;
+
+ // We can't use standard exception checking here like Assert.Throws or ExpectedException
+ // as local and online platforms seem to throw different exception types :(
+ try
+ {
+ _localStorageHelperSystem.Save("Today", DateTime.Today);
+ }
+ catch (Exception exception)
+ {
+ expectedException = exception;
+ }
+
+ Assert.IsNotNull(expectedException, "Was expecting an Exception.");
}
- [Ignore]
[TestCategory("Helpers")]
[TestMethod]
public void Test_StorageHelper_LegacyInternalClassTest()
@@ -64,12 +100,10 @@ public void Test_StorageHelper_LegacyInternalClassTest()
UI.Person input = new UI.Person() { Name = "Joe Bloggs", Age = 42 };
// simulate previous version by generating json and manually inserting it as string
- string jsonInput = JsonSerializer.Serialize(input);
-
- storageHelper.Save(key, jsonInput);
+ _localStorageHelperJsonCompat.Save(key, input);
// now read it as int to valid that the change works
- UI.Person output = storageHelper.Read(key, null);
+ UI.Person output = _localStorageHelperJsonCompat.Read(key, null);
Assert.IsNotNull(output);
Assert.AreEqual(input.Name, output.Name);
@@ -82,15 +116,14 @@ public void Test_StorageHelper_LegacyPublicClassTest()
{
string key = "Contact";
+ // Here's we're serializing a different class which has the same properties as our other class below.
UI.Person input = new UI.Person() { Name = "Joe Bloggs", Age = 42 };
// simulate previous version by generating json and manually inserting it as string
- string jsonInput = JsonSerializer.Serialize(input);
-
- storageHelper.Save(key, jsonInput);
+ _localStorageHelperJsonCompat.Save(key, input);
// now read it as int to valid that the change works
- Person output = storageHelper.Read(key, null);
+ Person output = _localStorageHelperJsonCompat.Read(key, null);
Assert.IsNotNull(output);
Assert.AreEqual(input.Name, output.Name);
@@ -105,10 +138,10 @@ public void Test_StorageHelper_IntTest()
int input = 42;
- storageHelper.Save(key, input);
+ _localStorageHelperSystem.Save(key, input);
// now read it as int to valid that the change works
- int output = storageHelper.Read(key, 0);
+ int output = _localStorageHelperSystem.Read(key, 0);
Assert.AreEqual(input, output);
}
@@ -121,10 +154,10 @@ public void Test_StorageHelper_NewDateTest()
DateTime input = new DateTime(2017, 12, 25);
- storageHelper.Save(key, input);
+ _localStorageHelperJsonNew.Save(key, input);
// now read it as int to valid that the change works
- DateTime output = storageHelper.Read(key, DateTime.Today);
+ DateTime output = _localStorageHelperJsonNew.Read(key, DateTime.Today);
Assert.AreEqual(input, output);
}
@@ -137,10 +170,10 @@ public void Test_StorageHelper_NewPersonTest()
Person input = new Person() { Name = "Joe Bloggs", Age = 42 };
- storageHelper.Save(key, input);
+ _localStorageHelperJsonNew.Save(key, input);
// now read it as int to valid that the change works
- Person output = storageHelper.Read(key, null);
+ Person output = _localStorageHelperJsonNew.Read(key, null);
Assert.IsNotNull(output);
Assert.AreEqual(input.Name, output.Name);
diff --git a/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj b/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj
index b9430d3a797..c2bc7e1cc2a 100644
--- a/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj
+++ b/UnitTests/UnitTests.UWP/UnitTests.UWP.csproj
@@ -119,6 +119,13 @@
2.1.0
+
+ 10.0.3
+
+
+
+ 4.7.2
+ 4.3.0
@@ -141,6 +148,8 @@
+
+