コード例 #1
0
        public void CheckGSTAndTotalExcludingGST()
        {
            string content = @"Hi Yvaine,
                                <expense>
                                <total>1024.01</total>
                                </expense>
                                Regards,
                                Ivan";

            IContentExtractor extractor = new ContentExtractor();
            RelevantDataBO    actual;
            var result = extractor.GetRelevantData(content, out actual);

            Assert.True(result);
            Assert.NotNull(actual);

            Assert.NotNull(actual.Expense);


            var expected = new RelevantDataBO()
            {
                Expense = new ExpenseBO()
                {
                    Total             = 1024.01M,
                    TotalExcludingGST = 890.44M,
                    GST = 133.57M
                }
            };

            Assert.Equal(expected.Expense.Total, actual.Expense.Total);
            Assert.Equal(expected.Expense.TotalExcludingGST, actual.Expense.TotalExcludingGST);
            Assert.Equal(expected.Expense.GST, actual.Expense.GST);
        }
コード例 #2
0
        private void AssertResponse(RelevantDataBO expected, RelevantDataBO actual)
        {
            Assert.NotNull(actual);

            Assert.Equal(expected.Date, actual.Date);
            Assert.Equal(expected.Description, actual.Description);
            Assert.Equal(expected.Vendor, actual.Vendor);

            Assert.NotNull(actual.Expense);
            Assert.Equal(expected.Expense.CostCentre, actual.Expense.CostCentre);
            Assert.Equal(expected.Expense.PaymentMethod, actual.Expense.PaymentMethod);
            Assert.Equal(expected.Expense.Total, actual.Expense.Total);
            Assert.Equal(expected.Expense.TotalExcludingGST, actual.Expense.TotalExcludingGST);
            Assert.Equal(expected.Expense.GST, actual.Expense.GST);
        }
コード例 #3
0
        public void NoCostCentre()
        {
            string content = @"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";

            IContentExtractor extractor = new ContentExtractor();
            RelevantDataBO    actual;
            var result = extractor.GetRelevantData(content, out actual);

            Assert.True(result);
            Assert.NotNull(actual);
            Assert.NotNull(actual.Expense);


            var expected = new RelevantDataBO()
            {
                Date        = new System.DateTime(2017, 4, 27),
                Description = "development team’s project end celebration dinner",
                Vendor      = "Viaduct Steakhouse",
                Expense     = new ExpenseBO()
                {
                    CostCentre        = "UNKNOWN",
                    PaymentMethod     = "personal card",
                    Total             = 1024.01M,
                    TotalExcludingGST = 890.44M,
                    GST = 133.57M
                }
            };


            AssertResponse(expected, actual);
        }
コード例 #4
0
        /// <summary>
        /// Extract relevant data from plain text
        /// </summary>
        /// <param name="content">plain text</param>
        /// <param name="relevantData">Business Object of structural content data</param>
        /// <returns>Success: return true; Fail: return false</returns>
        public bool GetRelevantData(string content, out RelevantDataBO relevantData)
        {
            relevantData = new RelevantDataBO();

            string mixed = content;
            string xml   = "<FOO>" + mixed + "</FOO>";

            try
            {
                XDocument dox = XDocument.Parse(xml);

                var totalString = GetElementValue(dox, "total");

                if (String.IsNullOrEmpty(totalString))
                {
                    // if no total, reject request.
                    Log.Warning("Input data has no total value.");
                    return(false);
                }

                decimal total;
                if (decimal.TryParse(totalString, out total))
                {
                    var costCentre = GetElementValue(dox, "cost_centre");

                    var totalExcludingGst = PriceCalculator.GetTotalExcludingGst(total);
                    var gst = PriceCalculator.GetGST(total, totalExcludingGst);
                    relevantData.Expense = new ExpenseBO
                    {
                        Total             = total,
                        GST               = gst,
                        TotalExcludingGST = totalExcludingGst,
                        CostCentre        = String.IsNullOrEmpty(costCentre) ? "UNKNOWN" : costCentre,
                        PaymentMethod     = GetElementValue(dox, "payment_method")
                    };
                }
                else
                {
                    // if total is not number, reject request.
                    Log.Warning("Input total value is invalid.");
                    return(false);
                }

                relevantData.Vendor      = GetElementValue(dox, "vendor");
                relevantData.Description = GetElementValue(dox, "description");
                var dateText = GetElementValue(dox, "date");

                // Get date based on custom format
                string   pattern = "dddd dd MMMM yyyy";
                DateTime dt;
                if (DateTime.TryParseExact(dateText, pattern, CultureInfo.InvariantCulture,
                                           DateTimeStyles.None,
                                           out dt))
                {
                    relevantData.Date = dt;
                }
            }
            catch (System.Xml.XmlException ex)
            {
                Log.Warning(ex, "Input xml Data has format error");
                return(false);
            }catch (ArgumentOutOfRangeException ex)
            {
                Log.Warning(ex, ex.Message);
                throw;
            }


            return(true);
        }