public void EntityConverter_ConvertLinkedObjectToJson_Succeeds() { // Create Object var newInvoice = new ComplexEntity { Currency = "EUR", OrderDate = new DateTime(2012, 10, 26), InvoiceTo = new Guid("3734121e-1544-4b77-9ae2-7203e9bd6046"), Journal = "50", OrderedBy = new Guid("3734121e-1544-4b77-9ae2-7203e9bd6046"), Description = "NewInvoiceForEntityWithCollection" }; var newInvoiceLine = new ComplexEntityLine { Description = "NewInvoiceForEntityWithCollection", Item = new Guid("4f68481a-7a2c-4fbc-a3a0-0c494df3fa0d") }; var invoicelines = new List <ComplexEntityLine> { newInvoiceLine }; newInvoice.Lines = invoicelines; var entityConverter = new EntityConverter(); string json = entityConverter.ConvertObjectToJson(newInvoice, null); string expected = JsonFileReader.GetJsonFromFileWithoutWhiteSpace("Expected_Json_Object_ComplexEntity_WithLinkedEntity.txt"); Assert.AreEqual(expected, json); }
public async Task ReadJSon3Async() { var setting = new CsvFile(UnitTestInitializeCsv.GetTestPath("Jason3.json")) { JsonFormat = true }; using (var dpd = new CustomProcessDisplay(UnitTestInitializeCsv.Token)) using (var jfr = new JsonFileReader(setting, dpd)) { await jfr.OpenAsync(dpd.CancellationToken); Assert.AreEqual(2, jfr.FieldCount); await jfr.ReadAsync(dpd.CancellationToken); Assert.AreEqual(28L, jfr.GetValue(0)); await jfr.ReadAsync(dpd.CancellationToken); Assert.AreEqual(56L, jfr.GetValue(0)); while (await jfr.ReadAsync(dpd.CancellationToken)) { } Assert.AreEqual(5, jfr.RecordNumber); } }
public void A_User_Should_be_Able_to_Read_A_JsonFile(string fileName) { var jsonFileReader = new JsonFileReader(filePath, fileName); string contentFile = jsonFileReader.Read(); Assert.Equal("{\"title\": \"Person\",\"type\": \"object\",\"lastName\": {\"type\": \"string\"}}", contentFile); }
public void StoreCounters() { MetaJsonCounters newMeta = new MetaJsonCounters(); allCounters.Values.ToList().ForEach(x => newMeta.myCounters.Add(x)); JsonFileReader.WriteJsonToExternalResource("Counters.json", JsonUtility.ToJson(newMeta)); }
private void Awake() { CreateSingleton(); if (PlayerPrefs.GetInt("level") == 4) { return; } FireList = new List <GameObject>(); string levelData = JsonFileReader.LoadJsonAsResource("levels.json"); LevelDataObj = JsonUtility.FromJson <LevelData>(levelData); List <Fire> FireData = LevelDataObj.levels[PlayerPrefs.GetInt("level") - 1].fires; spawnTimers = new List <float>(); foreach (Fire data in FireData) { Vector3 position = new Vector3(data.x, data.y); GameObject newFire = Instantiate(fireGameObj, position, Quaternion.identity); newFire.GetComponent <FireController>().Life = data.life; newFire.GetComponent <FireController>().despawnTime = data.despawnTime; newFire.transform.localScale = new Vector3(data.scale, data.scale, 1); spawnTimers.Add(data.spawnTime); newFire.SetActive(false); FireList.Add(newFire); } }
public void FileThatHasBeenReadShouldReturnSameValue() { var reader = new JsonFileReader(_pathValidations, _fileSystem); var content = reader.ReadContent(_expFullNamePath); Assert.True(content.RootElement.GetProperty("foo").ValueEquals("bar")); }
public void A_User_Should_be_Able_to_Read_An_Encrypted_TextFile_InjectingService() { string fileName = "EncryptedContentJson.json"; //Mock DecryptService Service var mockDecryptService = new Mock <IDecryptDataService>(); mockDecryptService .Setup(mock => mock.DecryptData(It.IsAny <string>())) .Returns((string param) => { string content = Encoding.UTF8.GetString(Convert.FromBase64String(param)); string[] splittedContent = content.Split("\r\n"); content = string.Empty; foreach (var item in splittedContent) { content += item.Trim(); } return(content); }); var jsonFileReader = new JsonFileReader(filePath, fileName, mockDecryptService.Object); string contentFile = jsonFileReader.Read(); Assert.Equal("{\"title\": \"Person\",\"type\": \"object\",\"lastName\": {\"type\": \"string\"}}", contentFile); }
public void ResetMyContent() { allMobs = new Dictionary <string, CharacterContent>(); allItems = new Dictionary <string, ItemContent>(); allCounters = new Dictionary <string, CounterContent>(); allEvents = new Dictionary <string, TriggerContent>(); // Load all mobs string loadedItem = JsonFileReader.LoadJsonAsResource("Jsons/Mobs"); MetaJsonMobs loadedMobs = JsonUtility.FromJson <MetaJsonMobs>(loadedItem); foreach (CharacterContent elt in loadedMobs.myMobs) { allMobs.Add(elt.myName, elt); } // Load all items loadedItem = JsonFileReader.LoadJsonAsResource("Jsons/Items"); MetaJsonItems loadedItems = JsonUtility.FromJson <MetaJsonItems>(loadedItem); foreach (ItemContent elt in loadedItems.myItems) { allItems.Add(elt.myName, elt); } // Load all events ReadEventsFile(); // Load all counters, create file if not exists if (!System.IO.File.Exists(Application.persistentDataPath + "/Counters.json")) { ResetCountersFile(); } ReadCountersFile(); }
public async Task OpenLogAsync() { var setting = new CsvFile(UnitTestInitializeCsv.GetTestPath("LogFile.json")) { JsonFormat = true }; using (var dpd = new CustomProcessDisplay(UnitTestInitializeCsv.Token)) using (var jfr = new JsonFileReader(setting, dpd)) { await jfr.OpenAsync(dpd.CancellationToken); await jfr.ReadAsync(dpd.CancellationToken); Assert.AreEqual("level", jfr.GetColumn(1).Name); Assert.AreEqual("Error", jfr.GetValue(1)); await jfr.ReadAsync(dpd.CancellationToken); Assert.AreEqual("Reading EdgeAPI vw_rpt_transcript", jfr.GetValue(2)); await jfr.ReadAsync(dpd.CancellationToken); Assert.AreEqual("System.Data.DataException", jfr.GetValue(4)); } }
public void LoadFlight(string path) { string myLoadedItem = JsonFileReader.LoadJsonAsResource(path); Flight myFlights = JsonUtility.FromJson <Flight>(myLoadedItem); flights.Add(myFlights); }
public async Task ReadJSon2Async() { var setting = new CsvFile(UnitTestInitializeCsv.GetTestPath("Jason2.json")) { JsonFormat = true }; using (var dpd = new CustomProcessDisplay(UnitTestInitializeCsv.Token)) using (var jfr = new JsonFileReader(setting, dpd)) { await jfr.OpenAsync(dpd.CancellationToken); Assert.AreEqual(7, jfr.FieldCount); await jfr.ReadAsync(dpd.CancellationToken); await jfr.ReadAsync(dpd.CancellationToken); Assert.AreEqual("Loading defaults C:\\Users\\rnoldner\\AppData\\Roaming\\CSVFileValidator\\Setting.xml", jfr.GetValue(6)); while (await jfr.ReadAsync(dpd.CancellationToken)) { } Assert.AreEqual(29, jfr.RecordNumber); } }
public Executor(string configFile, string movesFile) { _gameConfig = JsonFileReader.IRead <Configurations>(configFile); _movements = JsonFileReader.IRead <Moves[]>(movesFile); _turtle = new TurtlePointer(_gameConfig.EntryDirection, _gameConfig.EntryPoint.XVal, _gameConfig.EntryPoint.YVal); InitializeBoard(); }
public async Task ReadJSon1TypedAsync() { var setting = new CsvFile(UnitTestInitializeCsv.GetTestPath("Larger.json")) { JsonFormat = true }; using (var processDisplay = new CustomProcessDisplay(UnitTestInitializeCsv.Token)) { using (var jfr = new JsonFileReader(setting, processDisplay)) { await jfr.OpenAsync(processDisplay.CancellationToken); await jfr.ReadAsync(processDisplay.CancellationToken); Assert.AreEqual(new Guid("ef21069c-3d93-4e07-878d-00e820727f65"), jfr.GetGuid(0)); Assert.IsTrue((new DateTime(2020, 04, 03, 18, 45, 29, 573, DateTimeKind.Utc) - jfr.GetDateTime(1).ToUniversalTime()).TotalSeconds < 2); Assert.AreEqual((short)0, jfr.GetInt16(5)); Assert.AreEqual((int)0, jfr.GetInt32(5)); Assert.AreEqual((long)0, jfr.GetInt64(5)); var val = new object[jfr.FieldCount]; jfr.GetValues(val); Assert.IsNull(val[2]); } } }
static void Main(string[] args) { fileReader = new JsonFileReader <StudentJson>(); StringBuilder menu = new StringBuilder(); menu.AppendLine("1. MapCollection"); menu.AppendLine("2. JsonFileReading"); menu.AppendLine("3. Exit"); string cont = "Y"; do { Console.WriteLine(menu.ToString()); var o = Console.ReadLine(); switch (o) { case "1": CollectionMapper(); break; case "2": JsonFileReading(fileReader); break; case "3": cont = "N"; break; } } while (cont != "N"); }
public void ApiResponseCleanerFetchJsonArrayWithEmptyLinkedEntitiesSucceeds() { const string expected = @"[{""BankAccounts"":[]}]"; string clean = ApiResponseCleaner.GetJsonArray(JsonFileReader.GetJsonFromFile("ApiResponse_Json_Array_WithEmptyLinkedEntities.txt")); Assert.AreEqual(expected, clean); }
/// <summary> /// Loads supported city list from file. /// </summary> private void LoadCountryList() { var jsonFileReader = new JsonFileReader <IList <Country> >("Weather.Data.", "country.list.json"); jsonFileReader.Read(); _provider = new CountryProvider(jsonFileReader.Result.AsQueryable()); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); this.JsonFileReader = new JsonFileReader(); this.SpeechRecognizer = SpeechRecognizer.CreateSpeechRecognizer(this); this.SpeechRecognizer.Results += SpeechRecognizerOnResults; }
public void EntityConverter_ConvertJsonToDynamicObject_WithIncorrectJson_Fails() { string json = JsonFileReader.GetJsonFromFile("Response_Json_Object_GLAccount_WithCorruptJson.txt"); dynamic glaccountObject = _entityConverter.ConvertJsonToDynamicObject(json); Assert.AreEqual("D", (string)glaccountObject.BalanceSide); Assert.AreEqual("W", (string)glaccountObject.BalanceType); }
public void LoadItem(string path) { string loadPlayerItem = JsonFileReader.LoadJsonAsResource(path); //Debug.Log(loadPlayerItem); Item item = JsonUtility.FromJson <Item>(loadPlayerItem); playerItems.Add(item); }
private void Awake() { string loadedQuestion = JsonFileReader.LoadJsonAsResource("Kvízy/Kvíz_1/1.json"); Debug.Log(loadedQuestion); question = JsonUtility.FromJson <Question>(loadedQuestion); }
public void JsonFileReader_Can_Read_Valid_Json_File() { using (var reader = new JsonFileReader(@"FixtureFiles\test.json")) { var json = reader.Read(); Assert.AreEqual("world", json["hello"].ToObject <string>()); } }
public async Task Read_UnexistingFile_ShouldThrowException() { // Arrange var path = @"C:\Nowhere"; var sut = new JsonFileReader(path, new FileValidator()); // Act/Assert await Assert.ThrowsAsync <Exception>(() => sut.ReadAsync()); }
public async Task CreateTopologyFromPartialFileAsync() { var options = await JsonFileReader.ReadFileAsync <RabbitOptions>("TestConfig.json"); var top = new Topologer(options); await top .CreateTopologyFromFileAsync("TestPartialTopologyConfig.json") .ConfigureAwait(false); }
public void A_User_Should_be_Able_to_Read_An_Encrypted_TextFile_ExtensionMethod() { string fileName = "EncryptedContentJson.json"; var jsonFileReader = new JsonFileReader(filePath, fileName); string contentFile = jsonFileReader.ReadAndDecrypt(); Assert.Equal("{\"title\": \"Person\",\"type\": \"object\",\"lastName\": {\"type\": \"string\"}}", contentFile); }
public static void OneTimeApiSetup(TestContext testContext) { testContext.TestParameters = JsonFileReader <Dictionary <string, string> > .LoadJson("testParameters.json"); testContext.CarsRepository = JsonFileReader <List <CarInfo> > .LoadJson("TestData\\CarsRepository.json"); testContext.ApiUrlHostName = testContext.TestParameters["apiHostName"]; testContext.ApiClient = new RestClient(testContext.ApiUrlHostName); }
/// <summary> /// Loads supported country list from file. /// </summary> /// <returns>Task with supported country list.</returns> private Task <CountryProvider> LoadCountryList() { return(Task.Run(() => { var jsonFileReader = new JsonFileReader <IList <Country> >("Weather.Data.", "country.list.json"); jsonFileReader.Read(); return new CountryProvider(jsonFileReader.Result.AsQueryable()); })); }
public ConsumerTests(ITestOutputHelper output) { this.output = output; options = JsonFileReader.ReadFileAsync <Options>("TestConfig.json").GetAwaiter().GetResult(); channelPool = new ChannelPool(options); topologer = new Topologer(options); rabbitService = new RabbitService("Config.json", null, null, null, null); }
public void Should_read_an_entry() { string filePath = testDataFolder + "jsonFormat.txt"; JsonFileReader fileReader = new JsonFileReader(); Json80LegsFormat[] values = fileReader.Read(filePath, Json80LegsFormat.Converter).ToArray(); Assert.Equal(1, values.Length); Assert.Equal("url_text", values[0].url); Assert.Equal("html_text", values[0].result); }
public async Task CreateConsumerAndInitializeChannelPool() { var options = await JsonFileReader.ReadFileAsync <Options>("TestConfig.json"); Assert.NotNull(options); var con = new Consumer(options, "TestMessageConsumer"); Assert.NotNull(con); }
public void EntityConverter_ConvertJsonToObjectList_WithParsedJson_Succeeds() { string jsonarray = JsonFileReader.GetJsonFromFile("Response_Json_Array_Account.txt"); List <Account> accounts = _entityConverter.ConvertJsonArrayToObjectList <Account>(jsonarray); if (accounts.Count != 2) { throw new Exception("The count of the list isn't equal to the actual list"); } }
public void JsonFileReader_Raises_FileNotFoundException_If_Supplied_Path_Does_Not_Exists() { AssertRaise <FileNotFoundException>(() => { using (var reader = new JsonFileReader("does_not_exist.json")) { var json = reader.Read(); } }); }
public void Should_read_html_content() { string filePathJson = testDataFolder + "jsonHtmlContent.txt"; string filePathHtml = testDataFolder + "htmlContent.txt"; JsonFileReader fileReader = new JsonFileReader(); var values = fileReader.Read(filePathJson, Json80LegsFormat.Converter).ToArray(); var expected = File.ReadAllText(filePathHtml); Assert.Equal(1, values.Length); Assert.Equal("url/value", values[0].url); Assert.Equal(expected, values[0].result); }
public void Should_read_big_file() { string filePath = testDataFolder + "jsonBigFileAndPages.txt"; // 38Mb JsonFileReader fileReader = new JsonFileReader(); var values = fileReader.Read(filePath, Json80LegsFormat.Converter); Stopwatch sw = new Stopwatch(); sw.Start(); var count = 0; foreach (var value in values) { Assert.NotNull(value.url); // duplicates are not skipped Assert.NotNull(value.result); count++; } sw.Stop(); output.WriteLine("Read {0} entries in {1} ms ({2} ticks)", count, sw.ElapsedMilliseconds, sw.ElapsedTicks); }