public void GivenAnEmailWithoutCostCenterWhenProcessingTheContentThenSetCostCentreToUnknown() { var expectedExpenseClaimInput = new ExpenseClaimInput { CostCentre = "UNKNOWN", Total = 1024.01m, PaymentMethod = "personal card", Vendor = "Viaduct Steakhouse", Description = "development team’s project end celebration dinner", Date = "Thursday 27 April 2017" }; const string emailWithoutCostCentre = @"Hi Yvaine, Please create an expense claim for the below. Relevant details are marked up as requested… <expense> <total>1024.01</total><payment_method>personal card</payment_method> </expense> From: Ivan Castle Sent: Friday, 16 February 2018 10:32 AM To: Antoine Lloyd <*****@*****.**> Subject: test Hi Antoine, Please create a reservation at the <vendor>Viaduct Steakhouse</vendor> our <description>development team’s project end celebration dinner</description> on <date>Thursday 27 April 2017</date>. We expect to arrive around 7.15pm. Approximately 12 people but I’ll confirm exact numbers closer to the day. Regards, Ivan"; var expenseClaimInput = _dataExtractor.Extract(emailWithoutCostCentre); expenseClaimInput.Should().BeEquivalentTo(expectedExpenseClaimInput); }
public IDictionary <string, string> CreateExpenseClaimFromInput(ExpenseClaimInput input) { ValidateExpenseClaimInput(input); var xmlData = ExtractXmlDataFromText(input.ExpenseClaimText); return(GenerateOutputBasedOnXmlData(xmlData)); }
private void ValidateExpenseClaimInput(ExpenseClaimInput input) { var result = _inputValidator.Validate(input); if (!result.IsValid) { _logger.Error($"ValidateExpenseClaimInput failed:\n{string.Join("\n", result.Errors)}"); throw new ValidationException(result.Errors); } }
private void ActAndAssert(string inputText, Dictionary <string, string> expectedResult) { var input = new ExpenseClaimInput { ExpenseClaimText = inputText }; var actualResult = _service.CreateExpenseClaimFromInput(input); Assert.Equal(actualResult, expectedResult); }
public void OpeningClosingTagsMatched_Matched() { // Arrange var input = new ExpenseClaimInput { ExpenseClaimText = CommonData.ValidInput }; // Act var result = _inputValidator.Validate(input); // Assert Assert.True(result.Errors.Count == 0); }
public void TotalTagPresent_ValidData() { // Arrange var input = new ExpenseClaimInput { ExpenseClaimText = @"... <total>1024.01</total><payment_method>personal card</payment_method>" }; // Act var result = _inputValidator.Validate(input); // Assert Assert.True(result.Errors.Count == 0); }
private static ExpenseClaimInput BuildExpenseClaimInput(string email) { var expenseInformation = ExpenseExtractor.ExtractFrom(email); var expenseClaimInput = new ExpenseClaimInput { CostCentre = expenseInformation.CostCentre, Total = decimal.Parse(expenseInformation.Total), PaymentMethod = expenseInformation.PaymentMethod, Vendor = GetIndividualTagValueFor(email)[Vendor], Description = GetIndividualTagValueFor(email)[Description], Date = GetIndividualTagValueFor(email)[Date] }; return(expenseClaimInput); }
public void CreateExpenseClaimFromInput_TotalTagNotPresent() { // Arrange var input = new ExpenseClaimInput { ExpenseClaimText = @"... <expense> 1024.01</total><payment_method>personal card</payment_method> </expense>..." }; // Act var exception = Assert.Throws <ValidationException>(() => _service.CreateExpenseClaimFromInput(input)); // Assert Assert.True(exception.Failures.Count > 0); }
public void GivenAnExpenseClaimInputThenCreateAnExpenseClaim() { _validator.Setup(x => x.Validate(It.IsAny <string>())) .Returns(new DateTime(2019, 01, 15)); var expectedExpenseClaim = new ExpenseClaim("DEV002", 104.23m, "personal card") { Vendor = "Subway", Description = "Lunch Meeting", Date = new DateTime(2019, 01, 15) }; var expenseInput = new ExpenseClaimInput { CostCentre = "DEV002", Total = 104.23m, PaymentMethod = "personal card", Vendor = "Subway", Description = "Lunch Meeting", Date = "Tuesday 15 January 2019" }; var expenseClaim = _expenseClaimFactory.CreateExpenseClaimFrom(expenseInput); expenseClaim.Should().BeEquivalentTo(expectedExpenseClaim); }