public void SampleData() { string sampleText = @"Hi Yvaine, Please create an expense claim for the below.Relevant details are marked up as requested… <expense><cost_centre>DEV002</cost_centre> <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 <Antoine.Lloyd @example.com> 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 ExpenseParser = new ExpenseParser(); var Expense = ExpenseParser.ExtractExpenseData(sampleText); Assert.AreEqual("DEV002", Expense.cost_centre); Assert.AreEqual((Decimal)1024.01, Expense.total); Assert.AreEqual("personal card", Expense.payment_method); Assert.AreEqual("Viaduct Steakhouse", Expense.vendor); Assert.AreEqual(" development team’s project end celebration dinner", Expense.description); Assert.AreEqual(new DateTime(2017, 4, 27), Expense.date.Date); }
public Expense ReadText(string expenseText) { try { var expenseParser = new ExpenseParser(); return(expenseParser.ExtractExpenseData(expenseText)); } //report back the specified errors catch (CustomExpenseException ex) { var response = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(ex.Message), ReasonPhrase = "Error:" + ex.Message }; throw new HttpResponseException(response); } //everything else, dont expose, todo: either log or notify in windows event log catch (Exception) { var response = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("Internal error"), ReasonPhrase = "Internal Error" }; throw new HttpResponseException(response); } }
public void UnknownCostCentre() { var ExpenseParser = new ExpenseParser(); string UnknownCostCentre = @"Hi Yvaine, Please create an expense claim for the below.Relevant details are marked up as requested… <expense> <payment_method>personal card</payment_method> </expense><total>100.00</total> xxzbc "; var Expense = ExpenseParser.ExtractExpenseData(UnknownCostCentre); Assert.AreEqual("UNKNOWN", Expense.cost_centre); }
public void MissingClosingTag() { var ExpenseParser = new ExpenseParser(); string MissingTotalText = @"Hi Yvaine, Please create an expense claim for the below.Relevant details are marked up as requested… <expense><cost_centre>DEV002</cost_centre> <payment_method>personal card</payment_method> </expense><total>100.00</total> xx <date> zbc "; try { var Expense = ExpenseParser.ExtractExpenseData(MissingTotalText); } catch (Exception ex) { Assert.AreEqual(typeof(NoClosingTagException), ex.GetType()); Assert.AreEqual("No Closing Tag for: date", ex.Message); } }