public void Test_CanWrite_CanConvert_ShouldPass() { var converter = new JsonPathConverter(); Assert.False(converter.CanWrite); Assert.False(converter.CanConvert(typeof(object))); }
public void Test_WriteJson_ThrowsException_ShouldPass() { var converter = new JsonPathConverter(); Assert.Throws <NotImplementedException>(() => { converter.WriteJson(null, null, null); }); }
public void TestJson() { var json = new JsonPathConverter(); Assert.That(Json.Serialize(json), Is.EqualTo("{\"canWrite\":false,\"canRead\":true}")); DateTime testDate = new DateTime(2018, 1, 2); var deserialized = Json.Deserialize <DateTime>("\"2018-01-02T00:00:00\""); Assert.That(deserialized, Is.EqualTo(testDate)); }
private async Task CreateViewModel(Uri jsonFileUri) { if (jsonFileUri != null) { var localPath = jsonFileUri.LocalPath; var jsonFile = await StorageFile.GetFileFromPathAsync(localPath); var json = await FileIO.ReadTextAsync(jsonFile); var conv = new JsonPathConverter(Path.GetDirectoryName(jsonFileUri.AbsolutePath)); var dialMenuDefinition = JsonConvert.DeserializeObject<DialMenuDefinition>(json, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Objects, Converters = new List<JsonConverter>() { conv } }); _viewModel = new DialMenuControlViewModel(dialMenuDefinition); } if (PART_DialMenuControl != null) { PART_DialMenuControl.ViewModel = _viewModel; } }
public async Task LoadAppData(string knownPath = null, bool loadDebugJson = false) { try { if (knownPath == null) { try { var sfolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync("AppRootFolder"); knownPath = sfolder.Path; } catch (Exception) { } } var folderPicker = new FolderPicker { SuggestedStartLocation = PickerLocationId.Desktop }; folderPicker.FileTypeFilter.Add("*"); StorageFolder folder = null; if (knownPath == null) { folder = await folderPicker.PickSingleFolderAsync(); } else { folder = await StorageFolder.GetFolderFromPathAsync(knownPath); } if (folder != null) { var configFile = await folder.GetFileAsync(loadDebugJson? "config_debug.json" : "config.json"); var configText = await FileIO.ReadTextAsync(configFile); var conv = new JsonPathConverter(folder.Path); var rootConfig = JsonConvert.DeserializeObject <RootConfiguration>(configText, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Objects, PreserveReferencesHandling = PreserveReferencesHandling.All, ReferenceLoopHandling = ReferenceLoopHandling.Serialize, Converters = new List <JsonConverter>() { conv } }); _globalSettings = new GlobalSettings() { RootFolder = folder.Path }; await ProcessAppConfig(rootConfig); var config = ServiceLocator.Instance.Resolve <RemoteRelayConfiguration>(); config.ServerURL = rootConfig.RemoteSettings.ServerURL; await RemoteRelayManager.Instance.Initialize(config); ServiceLocator.Instance.Register(rootConfig); ServiceLocator.Instance.Register(_globalSettings); // Application now has read/write access to all contents in the picked folder // (including other sub-folder contents) StorageApplicationPermissions.FutureAccessList.AddOrReplace("AppRootFolder", folder); var localSettings = ApplicationData.Current.LocalSettings; if (localSettings.Values.ContainsKey("AppRootFolder")) { localSettings.Values["AppRootFolder"] = folder.Path; } else { } OnLoadFinished(); } } catch (Exception ex) { OnLoadFailed(ex); } }