public void ToString_WithNoOffers_FormatsOutputCorrectly()
        {
            var cResult = new CalculationResult();

            cResult.Add(12.34M);
            Assert.AreEqual(
                "Subtotal: £12.34" + Environment.NewLine +
                "(No offers available)" + Environment.NewLine +
                "Total: £12.34" + Environment.NewLine, cResult.ToString());
        }
        public void ToString_WithOffersInPence2Digits_FormatsOutputCorrectly()
        {
            var cResult = new CalculationResult();

            cResult.Add(12.34M);
            cResult.AddOffer(new Offer
            {
                Description = "TestOffer",
                PriceDelta  = -0.1M
            }, -0.3M);
            Assert.AreEqual(
                "Subtotal: £12.34" + Environment.NewLine +
                "TestOffer: -30p" + Environment.NewLine +
                "Total: £12.04" + Environment.NewLine, cResult.ToString());
        }
        public void ToString_should_return_success_message()
        {
            // arrange
            var model = new CalculationResult
            {
                Validation        = ValidationResult.Success(),
                Result            = 0.5M,
                Inputs            = new[] { new Probability(1M), new Probability(0.5M) },
                CalculationDate   = new DateTime(2019, 1, 2, 3, 4, 5),
                TypeOfCalculation = "TEST"
            };

            // act
            var actual = model.ToString();

            // assert
            actual.Should().Be("2019-01-02T03:04:05 => Success => Type of Calculation: 'TEST', Inputs: [1,0.5], Result: 0.5");
        }
        public void ToString_should_return_validation_failed_message()
        {
            // arrange
            var model = new CalculationResult
            {
                Validation        = ValidationResult.Fail("FAIL"),
                Result            = 0.5M,
                Inputs            = new[] { new Probability(1M), new Probability(0.5M) },
                CalculationDate   = new DateTime(2019, 1, 2, 3, 4, 5),
                TypeOfCalculation = "TEST"
            };

            // act
            var actual = model.ToString();

            // assert
            actual.Should().Be("2019-01-02T03:04:05 => Validation Failed => FAIL");
        }
        public async Task LogAsync(CalculationResult result)
        {
            var filePath = Path.Combine(Directory.GetCurrentDirectory(), "logs");
            var fileName = Path.Combine(filePath, "log.txt");

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            if (!File.Exists(fileName))
            {
                await File.WriteAllTextAsync(fileName, result.ToString());
            }
            else
            {
                await File.AppendAllTextAsync(fileName, "\r\n" + result);
            }
        }
예제 #6
0
 /// <summary>
 /// Gets the current calculation result
 /// </summary>
 /// <returns></returns>
 public string GetResult()
 {
     return(CalculationResult.ToString(CultureInfo.InvariantCulture));
 }