Exemple #1
0
        public void GetJson_DataWithNulls()
        {
            var inputData = new List <List <object> >();

            inputData.Add(new List <object>(new object[] { "City", "Month", "Temperature", "Rainfall" }));
            inputData.Add(new List <object>(new object[] { null, "Feb", "20", null }));
            inputData.Add(new List <object>(new object[] { "Lviv", "Jun", null, "200" }));

            IList <JObject> expected = new List <JObject>()
            {
                JObject.Parse(@"{
                    'City': null,
                    'Month': 'Feb',
                    'Temperature': 20,
                    'Rainfall': null,
                }"),
                JObject.Parse(@"{
                    'City': 'Lviv',
                    'Month': 'Jun',
                    'Temperature': null,
                    'Rainfall': 200,
                }")
            };

            IDataParser dataParser = Factory.CreateDataParser();
            var         result     = dataParser.GetJson(inputData);

            AssertListsJobjects(expected, result);
        }
Exemple #2
0
        public IHttpActionResult Post()
        {
            var httpRequest = HttpContext.Current.Request;

            if (httpRequest.Files.Count == 0)
            {
                return(null);
            }
            var postedFile = httpRequest.Files[0];
            var fileType   = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.') + 1,
                                                           postedFile.FileName.Length - postedFile.FileName.LastIndexOf('.') - 1);
            var fileName = Guid.NewGuid().ToString("n");
            var filePath = HttpContext.Current.Server.MapPath(String.Format("~/Storage/{0}.{1}", fileName, fileType));

            try
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Storage/"));
                postedFile.SaveAs(filePath);
                var parser = ParserFactory.GetFileParser(fileType);
                var result = _dataParser.GetJson(parser.Parse(fileName));
                File.Delete(filePath);
                return(Ok(new { Data = result, Message = (string)null }));
            }
            catch (Exception e)
            {
                return(Ok(new { Message = e.Message }));
            }
        }
Exemple #3
0
        public void GetJson_FullData()
        {
            var inputData = new List <List <object> >();

            inputData.Add(new List <object>(new object[] { "City", "Month", "Temperature", "Rainfall" }));
            inputData.Add(new List <object>(new object[] { "Lviv", "Feb", "20", "200" }));

            IList <JObject> expected = new List <JObject>()
            {
                JObject.Parse(@"{
                    'City': 'Lviv',
                    'Month': 'Feb',
                    'Temperature': 20,
                    'Rainfall': 200,
                }")
            };

            IDataParser dataParser = Factory.CreateDataParser();
            // object[,] comInteropArray = TestHelper.CreateArrayWithStartingIndex1(inputData);
            var result = dataParser.GetJson(inputData);

            AssertListsJobjects(expected, result);
        }