public string[] ToString(Quote quote)
        {
            quote.ThrowIfNull("quote");

            var data = new string[]
            {
                quote.DateTime.ToString("s", CultureInfo.InvariantCulture),
                quote.Ticker,
                quote.ValueExact.ToString("F2", CultureInfo.InvariantCulture),
            };

            return data;
        }
        public void ToString_ValidParams_Success()
        {
            // Arrange
            var quote = new Quote
            {
                DateTime = new DateTime(2015, 8, 26, 13, 4, 32),
                Ticker = "ABCD",
                ValueExact = (decimal)228.34
            };

            var expectedLine = new[] { "2015-08-26T13:04:32", "ABCD", "228.34" };
            var parser = new QuoteFormatter();

            // Act
            var actualLine = parser.ToString(quote);

            // Assert
            Assert.AreEqual(expectedLine, actualLine);
        }
        public void FromString_ValidParams_Success()
        {
            // Arrange
            var line = new[] { "2015-08-26T13:04:32", "ABCD", "228.34" };

            var expectedQuote = new Quote
            {
                DateTime = new DateTime(2015, 8, 26, 13, 4, 32),
                Ticker = "ABCD",
                ValueExact = (decimal)228.34
            };

            var parser = new QuoteFormatter();

            // Act
            var quote = parser.FromString(line, 1);

            // Assert
            Assert.IsTrue(quote.Equals(expectedQuote));
        }
        public Quote FromString(string[] values, uint lineNumber)
        {
            values.ThrowIfNull("values");

            const int EXPECTED_FIELD_NUMBER = 3;

            const int INDEX_DATETIME = 0;
            const int INDEX_TICKER = 1;
            const int INDEX_VALUE = 2;

            if (values.Count() != EXPECTED_FIELD_NUMBER)
            {
                var str = string.Join(", ", values);
                throw new WrongFieldsNumberException(lineNumber, EXPECTED_FIELD_NUMBER, (uint) values.Count(), str);
            }

            var quote = new Quote();

            try
            {
                quote.DateTime = DateTime.ParseExact(values[INDEX_DATETIME].Trim(), "s", CultureInfo.InvariantCulture);
            }
            catch (Exception ex)
            {
                throw new QuoteParsingException(typeof(DateTime), values[INDEX_DATETIME], ex);
            }

            quote.Ticker = values[INDEX_TICKER];

            try
            {
                quote.ValueExact = decimal.Parse(values[INDEX_VALUE], CultureInfo.InvariantCulture);
            }
            catch (Exception ex)
            {
                throw new QuoteParsingException(typeof(double), values[INDEX_VALUE], ex);
            }

            return quote;
        }