Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        /// <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());
        }
Exemplo n.º 3
0
        public void AUserShouldBeAbleToSwitchEncryptionJsonFile()
        {
            IEncryptor encryptor  = new ReverseEncryptor();
            var        fileReader = new JsonFileReader(encryptor);

            var filename = $@"{_currentDirectory}\files\jsonFile.json";

            var actualReversedText = fileReader.Read(filename);

            fileReader.SetEncryptor(VoidEncryptor.Instance);

            var actualText = fileReader.Read(filename);

            Assert.AreEqual("}\n\r\"!dlrow olleH\" :\"txet\"  \n\r{", actualReversedText);
            Assert.AreEqual("{\r\n  \"text\": \"Hello world!\"\r\n}", actualText);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public virtual IReadOnlyList <Invoice> GetAll()
        {
            var plays    = _json.Read <Dictionary <string, PlayEntity> >("plays");
            var invoices = _json.Read <InvoiceEntity[]>("invoices");

            return(invoices
                   .Select(invoice => invoice.Performances
                           .Aggregate(new Invoice(invoice.Customer),
                                      (accumulateInvoice, perfomance) =>
                                      accumulateInvoice
                                      .AddPerfomance(_perfomaceBuilder
                                                     .WithPerfomanceEntity(perfomance)
                                                     .WithPlayEntity(plays.GetValueOrDefault(perfomance.PlayId))
                                                     .Build())))
                   .ToList());
        }
Exemplo n.º 6
0
 /// <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());
     }));
 }
Exemplo n.º 7
0
        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>());
            }
        }
Exemplo n.º 8
0
 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();
         }
     });
 }
Exemplo n.º 9
0
        public void AUserShouldBeAbleToReadAJsonFile()
        {
            IFileReader fileReader = new JsonFileReader();

            var filename = $@"{_currentDirectory}\files\jsonFile.json";

            var actual = fileReader.Read(filename);

            Assert.AreEqual("{\r\n  \"text\": \"Hello world!\"\r\n}", actual);
        }
Exemplo n.º 10
0
        static void LoadConfiguration(string applicationPath, string configurationFilePath)
        {
            Configuration = new AppConfiguration
            {
                ApplicationPath = applicationPath
            };

            using (var reader = new JsonFileReader(Path.Combine(applicationPath, configurationFilePath)))
                Configuration.FromJson(reader.Read());
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        public void AUserShouldBeAbleToReadAEncryptedJsonFile()
        {
            IEncryptor  encryptor  = new ReverseEncryptor();
            IFileReader fileReader = new JsonFileReader(encryptor);

            var filename = $@"{_currentDirectory}\files\jsonFile.json";

            var actual = fileReader.Read(filename);

            Assert.AreEqual("}\n\r\"!dlrow olleH\" :\"txet\"  \n\r{", actual);
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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);
        }