public async Task GetById_WithValidData_ShouldReturnCorrectValues() { const string httpResult = "{\"invoice\":{\"id\":\"1322705\",\"created\":\"2015-06-04T16:12:59+02:00\",\"updated\":\"2019-08-08T09:21:08+02:00\",\"client_id\":\"485054\",\"contact_id\":\"\",\"invoice_number\":\"RE17\",\"number\":\"17\",\"number_pre\":\"RE\",\"number_length\":\"0\",\"title\":\"Rechnung RE17\",\"date\":\"2015-09-04\",\"supply_date\":\"\",\"supply_date_type\":\"SUPPLY_TEXT\",\"due_date\":\"2015-09-18\",\"due_days\":\"14\",\"address\":\"ACME Ltd.\\r\\nJohn Doe\\r\\nSecond Street 123\\r\\n01159 Dresden\",\"status\":\"PAID\",\"label\":\"\",\"intro\":\"Hiermit stellen wir Ihnen die folgenden Positionen in Rechnung.\",\"note\":\"Bitte \\u00fcberweisen Sie den Rechnungsbetrag bis zum 18.09.2015 auf unser Konto.\",\"total_net\":\"3885\",\"total_gross\":\"4615.5\",\"reduction\":\"\",\"total_reduction\":\"0\",\"total_net_unreduced\":\"3885\",\"total_gross_unreduced\":\"4615.5\",\"currency_code\":\"EUR\",\"quote\":\"1\",\"net_gross\":\"NET\",\"discount_rate\":\"2\",\"discount_date\":\"2015-09-11\",\"discount_days\":\"7\",\"discount_amount\":\"92.31\",\"paid_amount\":\"4523.19\",\"open_amount\":\"0\",\"payment_types\":\"\",\"customerportal_url\":\"https:\\/\\/develappersdev.billomat.net\\/customerportal\\/invoices\\/show\\/bc3654c0-b822-4aad-894f-8c5b1620241c\",\"taxes\":{\"tax\":[{\"name\":\"ust\",\"rate\":\"19\",\"amount\":\"722\",\"amount_plain\":\"722\",\"amount_rounded\":\"722\",\"amount_net\":\"3800\",\"amount_net_plain\":\"3800\",\"amount_net_rounded\":\"3800\",\"amount_gross\":\"4522\",\"amount_gross_plain\":\"4522\",\"amount_gross_rounded\":\"4522\"},{\"name\":\"gtr\",\"rate\":\"10\",\"amount\":\"8.5\",\"amount_plain\":\"8.5\",\"amount_rounded\":\"8.5\",\"amount_net\":\"85\",\"amount_net_plain\":\"85\",\"amount_net_rounded\":\"85\",\"amount_gross\":\"93.5\",\"amount_gross_plain\":\"93.5\",\"amount_gross_rounded\":\"93.5\"}]},\"invoice_id\":\"\",\"offer_id\":\"\",\"confirmation_id\":\"\",\"recurring_id\":\"\",\"dig_proceeded\":\"0\",\"template_id\":\"\",\"customfield\":\"\"}}"; const int id = 1322705; const string expectedUri = "/api/invoices/1322705"; var expectedResult = new Invoice { Id = id, Created = DateTime.Parse("2015-06-04T16:12:59+02:00", CultureInfo.InvariantCulture), //Updated = DateTime.Parse("2019-08-08T09:21:08+02:00", CultureInfo.InvariantCulture), ClientId = 485054, ContactId = null, InvoiceNumber = "RE17", Number = 17, NumberPre = "RE", NumberLength = 0, Title = "Rechnung RE17", Date = DateTime.Parse("2015-09-04", CultureInfo.InvariantCulture), SupplyDateType = SupplyDateType.SupplyDate, SupplyDate = new FreeTextSupplyDate(), DueDate = DateTime.Parse("2015-09-18", CultureInfo.InvariantCulture), DueDays = 14, Address = "ACME Ltd.\r\nJohn Doe\r\nSecond Street 123\r\n01159 Dresden", Status = InvoiceStatus.Paid, Label = null, Intro = "Hiermit stellen wir Ihnen die folgenden Positionen in Rechnung.", Note = "Bitte \u00fcberweisen Sie den Rechnungsbetrag bis zum 18.09.2015 auf unser Konto.", TotalNet = 3885f, TotalGross = 4615.5f, Reduction = null, //TotalReduction = 0, TotalNetUnreduced = 3885, TotalGrossUnreduced = 4615.5f, CurrencyCode = "EUR", Quote = 1f, NetGross = NetGrossType.Net, DiscountRate = 2f, DiscountDate = DateTime.Parse("2015-09-11", CultureInfo.InvariantCulture), DiscountDays = 7, DiscountAmount = 92.31f, PaidAmount = 4523.19f, OpenAmount = 0f, PaymentTypes = new List <string>(), CustomerPortalUrl = "https://develappersdev.billomat.net/customerportal/invoices/show/bc3654c0-b822-4aad-894f-8c5b1620241c", Taxes = new List <InvoiceTax> { new() { Name = "ust", Rate = 19f, Amount = 722f, AmountPlain = 722f, AmountRounded = 722f, AmountNet = 3800f, AmountNetPlain = 3800f, AmountNetRounded = 3800f, AmountGross = 4522f, AmountGrossPlain = 4522f, AmountGrossRounded = 4522f }, new() { Name = "gtr", Rate = 10f, Amount = 8.5f, AmountPlain = 8.5f, AmountRounded = 8.5f, AmountNet = 85f, AmountNetPlain = 85f, AmountNetRounded = 85f, AmountGross = 93.5f, AmountGrossPlain = 93.5f, AmountGrossRounded = 93.5f } },
public Invoice ApiToDomain(Api.Invoice value) { if (value == null) { return(null); } SupplyDateType?supplyDateType; ISupplyDate supplyDate; switch (value.SupplyDateType.ToLowerInvariant()) { case "supply_date": supplyDateType = SupplyDateType.SupplyDate; supplyDate = new DateSupplyDate { Date = value.SupplyDate.ToOptionalDateTime() }; break; case "delivery_date": supplyDateType = SupplyDateType.DeliveryDate; supplyDate = new DateSupplyDate { Date = value.SupplyDate.ToOptionalDateTime() }; break; case "supply_text": supplyDateType = SupplyDateType.SupplyDate; supplyDate = new FreeTextSupplyDate { Text = value.SupplyDate }; break; case "delivery_text": supplyDateType = SupplyDateType.DeliveryDate; supplyDate = new FreeTextSupplyDate { Text = value.SupplyDate }; break; case "": supplyDateType = null; supplyDate = null; break; default: throw new ArgumentOutOfRangeException(); } IReduction reduction = null; if (!string.IsNullOrEmpty(value.Reduction)) { if (value.Reduction.EndsWith("%")) { reduction = new PercentReduction { Value = float.Parse(value.Reduction.Replace("%", ""), CultureInfo.InvariantCulture) }; } else { reduction = new AbsoluteReduction { Value = float.Parse(value.Reduction, CultureInfo.InvariantCulture) }; } } return(new Invoice { Id = value.Id.ToInt(), InvoiceId = value.InvoiceId.ToOptionalInt(), ConfirmationId = value.ConfirmationId.ToOptionalInt(), OfferId = value.OfferId.ToOptionalInt(), RecurringId = value.RecurringId.ToOptionalInt(), TemplateId = value.TemplateId.ToOptionalInt(), CustomerPortalUrl = value.CustomerPortalUrl.Sanitize(), ClientId = value.ClientId.ToInt(), ContactId = value.ContactId.ToOptionalInt(), InvoiceNumber = value.InvoiceNumber, Number = value.Number.ToOptionalInt(), NumberPre = value.NumberPre.Sanitize(), NumberLength = value.NumberLength.ToInt(), Title = value.Title.Sanitize(), Date = value.Date.ToOptionalDateTime(), Address = value.Address.Sanitize(), Label = value.Label.Sanitize(), Intro = value.Intro.Sanitize(), Note = value.Note.Sanitize(), TotalGross = value.TotalGross.ToFloat(), TotalNet = value.TotalNet.ToFloat(), CurrencyCode = value.CurrencyCode, TotalGrossUnreduced = value.TotalGrossUnreduced.ToFloat(), TotalNetUnreduced = value.TotalNetUnreduced.ToFloat(), Created = value.Created.ToDateTime(), DueDate = value.DueDate.ToOptionalDateTime(), DueDays = value.DueDays.ToOptionalInt(), NetGross = value.NetGross.ToNetGrossType(), SupplyDate = supplyDate, SupplyDateType = supplyDateType, Status = value.Status.ToInvoiceStatus(), PaymentTypes = value.PaymentTypes.ToStringList(), Taxes = _taxMapper.ApiToDomain(value.Taxes), Quote = value.Quote.ToFloat(), Reduction = reduction, DiscountRate = value.DiscountRate.ToOptionalFloat(), DiscountDate = value.DiscountDate.ToOptionalDateTime(), DiscountDays = value.DiscountDays.ToOptionalInt(), DiscountAmount = value.DiscountAmount.ToOptionalFloat(), PaidAmount = value.PaidAmount.ToFloat(), OpenAmount = value.OpenAmount.ToFloat() }); }
private static Invoice ToDomain(this Api.Invoice value) { if (value == null) { return(null); } NetGrossType netGrossType; switch (value.NetGross.ToLowerInvariant()) { case "net": netGrossType = NetGrossType.Net; break; case "gross": netGrossType = NetGrossType.Gross; break; default: throw new ArgumentOutOfRangeException(); } SupplyDateType?supplyDateType; ISupplyDate supplyDate; switch (value.SupplyDateType.ToLowerInvariant()) { case "supply_date": supplyDateType = SupplyDateType.SupplyDate; supplyDate = new DateSupplyDate { Date = value.SupplyDate.ToOptionalDateTime() }; break; case "delivery_date": supplyDateType = SupplyDateType.DeliveryDate; supplyDate = new DateSupplyDate { Date = value.SupplyDate.ToOptionalDateTime() }; break; case "supply_text": supplyDateType = SupplyDateType.SupplyDate; supplyDate = new FreeTextSupplyDate { Text = value.SupplyDate }; break; case "delivery_text": supplyDateType = SupplyDateType.DeliveryDate; supplyDate = new FreeTextSupplyDate { Text = value.SupplyDate }; break; case "": supplyDateType = null; supplyDate = null; break; default: throw new ArgumentOutOfRangeException(); } InvoiceStatus status; switch (value.Status.ToLowerInvariant()) { case "draft": status = InvoiceStatus.Draft; break; case "open": status = InvoiceStatus.Open; break; case "overdue": status = InvoiceStatus.Overdue; break; case "paid": status = InvoiceStatus.Paid; break; case "canceled": status = InvoiceStatus.Canceled; break; default: throw new ArgumentOutOfRangeException(); } IReduction reduction = null; if (!string.IsNullOrEmpty(value.Reduction)) { if (value.Reduction.EndsWith("%")) { reduction = new PercentReduction { Value = float.Parse(value.Reduction.Replace("%", ""), CultureInfo.InvariantCulture) }; } else { reduction = new AbsoluteReduction { Value = float.Parse(value.Reduction, CultureInfo.InvariantCulture) }; } } return(new Invoice { Id = int.Parse(value.Id, CultureInfo.InvariantCulture), InvoiceId = value.InvoiceId.ToOptionalInt(), ConfirmationId = value.ConfirmationId.ToOptionalInt(), OfferId = value.OfferId.ToOptionalInt(), RecurringId = value.RecurringId.ToOptionalInt(), TemplateId = value.TemplateId.ToOptionalInt(), CustomerPortalUrl = value.CustomerPortalUrl, ClientId = int.Parse(value.ClientId, CultureInfo.InvariantCulture), ContactId = value.ContactId.ToOptionalInt(), InvoiceNumber = value.InvoiceNumber, Number = value.Number.ToOptionalInt(), NumberPre = value.NumberPre, NumberLength = int.Parse(value.NumberLength, CultureInfo.InvariantCulture), Title = value.Title, Date = DateTime.Parse(value.Date, CultureInfo.InvariantCulture), Address = value.Address, Label = value.Label, Intro = value.Intro, Note = value.Note, TotalGross = float.Parse(value.TotalGross, CultureInfo.InvariantCulture), TotalNet = float.Parse(value.TotalNet, CultureInfo.InvariantCulture), CurrencyCode = value.CurrencyCode, TotalGrossUnreduced = float.Parse(value.TotalGrossUnreduced, CultureInfo.InvariantCulture), TotalNetUnreduced = float.Parse(value.TotalNetUnreduced, CultureInfo.InvariantCulture), Created = DateTime.Parse(value.Created, CultureInfo.InvariantCulture), DueDate = DateTime.Parse(value.DueDate, CultureInfo.InvariantCulture), DueDays = int.Parse(value.DueDays, CultureInfo.InvariantCulture), NetGross = netGrossType, SupplyDate = supplyDate, SupplyDateType = supplyDateType, Status = status, PaymentTypes = value.PaymentTypes.ToStringList(), Taxes = value.Taxes.ToDomain(), Quote = float.Parse(value.Quote, CultureInfo.InvariantCulture), Reduction = reduction, DiscountRate = float.Parse(value.DiscountRate, CultureInfo.InvariantCulture), DiscountDate = value.DiscountDate.ToOptionalDateTime(), DiscountDays = value.DiscountDays.ToOptionalInt(), DiscountAmount = value.DiscountAmount.ToOptionalFloat(), PaidAmount = value.PaidAmount.ToOptionalFloat() ?? 0, OpenAmount = float.Parse(value.OpenAmount, CultureInfo.InvariantCulture) }); }