Exemple #1
0
        public void ShouldParseAll()
        {
            string[] barLines  = { "#A:RED:5", "#B:Yellow:10" };
            Bar      expected0 = new Bar {
                Name = "A", Colour = Color.Red, Value = 5
            };
            Bar expected1 = new Bar {
                Name = "B", Colour = Color.Yellow, Value = 10
            };
            IParser parser = new SnowParser();

            var result = parser.ParseAll(barLines);

            Assert.AreEqual(2, result.Count);
            Assert.IsTrue(expected0.Equals(result[0]));
            Assert.IsTrue(expected1.Equals(result[1]));
        }
Exemple #2
0
        public void ShouldFailWhenBarLinesEmpty()
        {
            string[]  barLines   = new string[0];
            IParser   parser     = new SnowParser();
            Exception expectedEx = null;

            try
            {
                var result = parser.ParseAll(barLines);
            }
            catch (Exception ex)
            {
                expectedEx = ex;
            }

            Assert.IsNotNull(expectedEx);
            Assert.IsInstanceOfType(expectedEx, typeof(ArgumentException));
            Assert.AreEqual(expectedEx.Message, "barLines collection can not be empty\r\nParameter name: barLines");
        }
Exemple #3
0
        public IEnumerable <Bar> UploadFile()
        {
            var           httpPostedFile = HttpContext.Current?.Request?.Files?["UploadedFile"];
            List <string> lines          = new List <string>();

            if (httpPostedFile != null)
            {
                using (var reader = new StreamReader(httpPostedFile.InputStream))
                {
                    while (!reader.EndOfStream)
                    {
                        lines.Add(reader.ReadLine());
                    }
                }
            }

            IParser parser = new SnowParser();

            return(parser.ParseAll(lines.ToArray()));
        }