public void Test_Issue_44() // Origins from https://github.com/FortnoxAB/csharp-api-sdk/issues/44 { //Arrange var customerConnector = new CustomerConnector(); var tmpCustomer = customerConnector.Create(new Customer() { Name = "TmpTestCustomer" }); IInvoiceConnector connector = new InvoiceConnector(); var newInvoce = connector.Create(new Invoice() { InvoiceDate = new DateTime(2019, 1, 20), //"2019-01-20", DueDate = new DateTime(2019, 2, 20), //"2019-02-20", CustomerNumber = tmpCustomer.CustomerNumber, InvoiceType = InvoiceType.Invoice, InvoiceRows = new List <InvoiceRow>() { //Add Empty rows new InvoiceRow(), //Empty Row new InvoiceRow(), //Empty Row new InvoiceRow() { AccountNumber = 0000 }, new InvoiceRow(), //Empty Row } }); }
public void Test_Issue_44() // Origins from https://github.com/FortnoxAB/csharp-api-sdk/issues/44 { //Arrange var customerConnector = new CustomerConnector(); var tmpCustomer = customerConnector.Create(new Customer() { Name = "TmpTestCustomer" }); var connector = new InvoiceConnector(); var newInvoce = connector.Create(new Invoice() { InvoiceDate = new DateTime(2019, 1, 20).ToString(APIConstants.DateFormat), //"2019-01-20", DueDate = new DateTime(2019, 2, 20).ToString(APIConstants.DateFormat), //"2019-02-20", CustomerNumber = tmpCustomer.CustomerNumber, InvoiceType = InvoiceType.INVOICE, InvoiceRows = new List <InvoiceRow>() { //Add Empty rows new InvoiceRow(), //Empty Row new InvoiceRow(), //Empty Row new InvoiceRow() { AccountNumber = "0000" }, new InvoiceRow(), //Empty Row } }); MyAssert.HasNoError(connector); }
public void Test_InvoiceWithLabels() { #region Arrange var tmpCustomer = new CustomerConnector().Create(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis" }); var tmpArticle = new ArticleConnector().Create(new Article() { Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 100 }); #endregion Arrange ILabelConnector labelConnector = new LabelConnector(); var label1 = labelConnector.Create(new Label() { Description = TestUtils.RandomString() }); var label2 = labelConnector.Create(new Label() { Description = TestUtils.RandomString() }); IInvoiceConnector connector = new InvoiceConnector(); var invoice = new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2019, 1, 20), //"2019-01-20", DueDate = new DateTime(2019, 2, 20), //"2019-02-20", InvoiceType = InvoiceType.CashInvoice, PaymentWay = PaymentWay.Cash, Comments = "TestInvoice", InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, Price = 100 }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, Price = 100 } }, Labels = new List <LabelReference>() { new LabelReference(label1.Id), new LabelReference(label2.Id) } }; var createdInvoice = connector.Create(invoice); Assert.AreEqual(2, createdInvoice.Labels.Count); //Clean connector.Cancel(createdInvoice.DocumentNumber); labelConnector.Delete(label1.Id); labelConnector.Delete(label2.Id); }
public void Test_DueDate() { #region Arrange var tmpCustomer = new CustomerConnector().Create(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis" }); var tmpArticle = new ArticleConnector().Create(new Article() { Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 100 }); #endregion Arrange IInvoiceConnector connector = new InvoiceConnector(); var newInvoice = new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2019, 1, 20), //"2019-01-20", Comments = "TestInvoice", InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 10, Price = 100 }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, Price = 100 }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, Price = 100 } } }; var createdInvoice = connector.Create(newInvoice); Assert.AreEqual("2019-01-20", createdInvoice.InvoiceDate?.ToString(APIConstants.DateFormat)); Assert.AreEqual("2019-02-19", createdInvoice.DueDate?.ToString(APIConstants.DateFormat)); var newInvoiceDate = new DateTime(2019, 1, 1); var dateChange = newInvoiceDate - newInvoice.InvoiceDate.Value; var newDueDate = createdInvoice.DueDate?.AddDays(dateChange.Days); createdInvoice.InvoiceDate = newInvoiceDate; createdInvoice.DueDate = newDueDate; var updatedInvoice = connector.Update(createdInvoice); Assert.AreEqual("2019-01-01", updatedInvoice.InvoiceDate?.ToString(APIConstants.DateFormat)); Assert.AreEqual("2019-01-31", updatedInvoice.DueDate?.ToString(APIConstants.DateFormat)); connector.Cancel(createdInvoice.DocumentNumber); #region Delete arranged resources new CustomerConnector().Delete(tmpCustomer.CustomerNumber); //new ArticleConnector().Delete(tmpArticle.ArticleNumber); #endregion Delete arranged resources }
public void Test_Issue98_fixed() // Origins from https://github.com/FortnoxAB/csharp-api-sdk/issues/98 { #region Arrange var tmpCustomer = new CustomerConnector().Create(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis" }); var tmpArticle = new ArticleConnector().Create(new Article() { Description = "TmpArticle", PurchasePrice = 100 }); #endregion Arrange IInvoiceConnector connector = new InvoiceConnector(); var largeId = (long)2 * int.MaxValue + TestUtils.RandomInt(); var newInvoice = new Invoice() { DocumentNumber = largeId, CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2019, 1, 20), DueDate = new DateTime(2019, 2, 20), InvoiceType = InvoiceType.CashInvoice, PaymentWay = PaymentWay.Cash, Comments = "TestInvoice", InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 10, Price = 100 }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, Price = 100 }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, Price = 100 } } }; var createdInvoice = connector.Create(newInvoice); Assert.AreEqual(largeId, createdInvoice.DocumentNumber); #region Delete arranged resources new InvoiceConnector().Cancel(createdInvoice.DocumentNumber); new CustomerConnector().Delete(tmpCustomer.CustomerNumber); //new ArticleConnector().Delete(tmpArticle.ArticleNumber); #endregion Delete arranged resources }
public void Test_InvoicePayment_Find() { #region Arrange var tmpCustomer = new CustomerConnector().Create(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis" }); var tmpArticle = new ArticleConnector().Create(new Article() { Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 10 }); var invoiceConnector = new InvoiceConnector(); var tmpInvoice = invoiceConnector.Create(new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2020, 1, 20), DueDate = new DateTime(2020, 6, 20), InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 2, Price = 10 }, } }); invoiceConnector.Bookkeep(tmpInvoice.DocumentNumber); #endregion Arrange IInvoicePaymentConnector connector = new InvoicePaymentConnector(); var newInvoicePayment = new InvoicePayment() { InvoiceNumber = tmpInvoice.DocumentNumber, Amount = 10.5m, AmountCurrency = 10.5m, PaymentDate = new DateTime(2020, 2, 1) }; for (var i = 0; i < 5; i++) { connector.Create(newInvoicePayment); MyAssert.HasNoError(connector); } connector.Search.InvoiceNumber = tmpInvoice.DocumentNumber.ToString(); var payments = connector.Find(); Assert.AreEqual(5, payments.Entities.Count); Assert.AreEqual(10.5m, payments.Entities.First().Amount); foreach (var entity in payments.Entities) { connector.Delete(entity.Number); MyAssert.HasNoError(connector); } }
public void Test_Email() { #region Arrange var cc = new CustomerConnector(); var ac = new ArticleConnector(); var tmpCustomer = cc.Create(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis", Email = "*****@*****.**" }); var tmpArticle = ac.Create(new Article() { Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 100 }); MyAssert.HasNoError(cc); MyAssert.HasNoError(ac); #endregion Arrange IInvoiceConnector connector = new InvoiceConnector(); var newInvoice = new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2019, 1, 20), //"2019-01-20", DueDate = new DateTime(2019, 2, 20), //"2019-02-20", InvoiceType = InvoiceType.CashInvoice, PaymentWay = PaymentWay.Cash, Comments = "Testing invoice email feature", InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 10, Price = 100 }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, Price = 100 }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, Price = 100 } } }; var createdInvoice = connector.Create(newInvoice); MyAssert.HasNoError(connector); var emailedInvoice = connector.Email(createdInvoice.DocumentNumber); MyAssert.HasNoError(connector); Assert.AreEqual(emailedInvoice.DocumentNumber, createdInvoice.DocumentNumber); #region Delete arranged resources new CustomerConnector().Delete(tmpCustomer.CustomerNumber); new ArticleConnector().Delete(tmpArticle.ArticleNumber); #endregion Delete arranged resources }
public void Test_Print() { #region Arrange var cc = new CustomerConnector(); var ac = new ArticleConnector(); var tmpCustomer = cc.Create(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis" }); var tmpArticle = ac.Create(new Article() { Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 100 }); #endregion Arrange IInvoiceConnector connector = new InvoiceConnector(); var newInvoice = new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2019, 1, 20), //"2019-01-20", DueDate = new DateTime(2019, 2, 20), //"2019-02-20", InvoiceType = InvoiceType.CashInvoice, PaymentWay = PaymentWay.Cash, Comments = "TestInvoice", InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 10, Price = 100 }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, Price = 100 }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, Price = 100 } } }; var createdInvoice = connector.Create(newInvoice); var fileData = connector.Print(createdInvoice.DocumentNumber); MyAssert.IsPDF(fileData); connector.Cancel(createdInvoice.DocumentNumber); #region Delete arranged resources new CustomerConnector().Delete(tmpCustomer.CustomerNumber); //new ArticleConnector().Delete(tmpArticle.ArticleNumber); #endregion Delete arranged resources }
public void Test_Invoice_CustomVAT() { #region Arrange var tmpCustomer = new CustomerConnector().Create(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis" }); var tmpArticle = new ArticleConnector().Create(new Article() { Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 100 }); #endregion Arrange IInvoiceConnector connector = new InvoiceConnector(); var newInvoice = new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2019, 1, 20), //"2019-01-20", DueDate = new DateTime(2019, 2, 20), //"2019-02-20", InvoiceType = InvoiceType.CashInvoice, PaymentWay = PaymentWay.Cash, Comments = "TestInvoice", InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 10, Price = 100, VAT = 1.23m }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, Price = 100, VAT = 1.23m }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, Price = 100, VAT = 1.23m } } }; var createdInvoice = connector.Create(newInvoice); Assert.AreEqual(3, createdInvoice.InvoiceRows.Count); Assert.AreEqual(1.23m, createdInvoice.InvoiceRows.First().VAT); #region Delete arranged resources new InvoiceConnector().Cancel(createdInvoice.DocumentNumber); new CustomerConnector().Delete(tmpCustomer.CustomerNumber); //new ArticleConnector().Delete(tmpArticle.ArticleNumber); #endregion Delete arranged resources }
public void Test_InvoiceFileConnection_CRUD() { #region Arrange var tmpCustomer = new CustomerConnector().Create(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis" }); var tmpArticle = new ArticleConnector().Create(new Article() { Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 10 }); var invoiceConnector = new InvoiceConnector(); var tmpInvoice = invoiceConnector.Create(new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2020, 1, 20), DueDate = new DateTime(2020, 6, 20), InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 2, Price = 10 }, } }); var inboxConnector = new InboxConnector(); var tmpFile = inboxConnector.UploadFile("tmpInvoiceFile.pdf", Resource.invoice_example, StaticFolders.CustomerInvoices); #endregion Arrange IInvoiceFileConnectionConnector connector = new InvoiceFileConnectionConnector(); #region CREATE var newInvoiceFileConnection = new InvoiceFileConnection() { EntityId = tmpInvoice.DocumentNumber, FileId = tmpFile.ArchiveFileId, IncludeOnSend = false, EntityType = EntityType.Invoice }; var createdInvoiceFileConnection = connector.Create(newInvoiceFileConnection); MyAssert.HasNoError(connector); Assert.AreEqual(false, createdInvoiceFileConnection.IncludeOnSend); #endregion CREATE #region UPDATE createdInvoiceFileConnection.IncludeOnSend = true; var updatedInvoiceFileConnection = connector.Update(createdInvoiceFileConnection); MyAssert.HasNoError(connector); Assert.AreEqual(true, updatedInvoiceFileConnection.IncludeOnSend); #endregion UPDATE #region READ / GET var retrievedInvoiceFileConnection = connector.GetConnections(createdInvoiceFileConnection.EntityId, createdInvoiceFileConnection.EntityType)?.FirstOrDefault(); MyAssert.HasNoError(connector); Assert.AreEqual(true, retrievedInvoiceFileConnection?.IncludeOnSend); #endregion READ / GET #region DELETE connector.Delete(createdInvoiceFileConnection.Id); MyAssert.HasNoError(connector); retrievedInvoiceFileConnection = connector.GetConnections(createdInvoiceFileConnection.EntityId, createdInvoiceFileConnection.EntityType)?.FirstOrDefault(); Assert.AreEqual(null, retrievedInvoiceFileConnection, "Entity still exists after Delete!"); #endregion DELETE #region Delete arranged resources new CustomerConnector().Delete(tmpCustomer.CustomerNumber); new ArticleConnector().Delete(tmpArticle.ArticleNumber); new InboxConnector().DeleteFile(tmpFile.Id); #endregion Delete arranged resources }
public void Test_Invoice_CRUD() { //Arrange var tmpCustomer = new CustomerConnector().Create(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis" }); var tmpArticle = new ArticleConnector().Create(new Article() { Description = "TmpArticle", Type = ArticleType.STOCK, PurchasePrice = 100 }); //Act var connector = new InvoiceConnector(); #region CREATE var newInvoice = new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2019, 1, 20).ToString(APIConstants.DateFormat), //"2019-01-20", DueDate = new DateTime(2019, 2, 20).ToString(APIConstants.DateFormat), //"2019-02-20", InvoiceType = InvoiceType.CASHINVOICE, PaymentWay = "CASH", InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 10 }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20 }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15 } } }; var createdInvoice = connector.Create(newInvoice); MyAssert.HasNoError(connector); Assert.AreEqual(createdInvoice.CustomerName, "TmpCustomer"); Assert.AreEqual(3, createdInvoice.InvoiceRows.Count); #endregion CREATE #region UPDATE createdInvoice.City = "UpdatedCity"; var updatedInvoice = connector.Update(createdInvoice); MyAssert.HasNoError(connector); Assert.AreEqual("UpdatedCity", updatedInvoice.City); #endregion UPDATE #region READ / GET var retrievedInvoice = connector.Get(createdInvoice.DocumentNumber); MyAssert.HasNoError(connector); Assert.AreEqual("UpdatedCity", retrievedInvoice.City); #endregion READ / GET #region DELETE //Invoice does not provide DELETE method, but can be canceled connector.Cancel(createdInvoice.DocumentNumber); MyAssert.HasNoError(connector); retrievedInvoice = connector.Get(createdInvoice.DocumentNumber); Assert.AreEqual(true, retrievedInvoice.Cancelled); #endregion DELETE //Clean new CustomerConnector().Delete(tmpCustomer.CustomerNumber); new ArticleConnector().Delete(tmpArticle.ArticleNumber); }
public void Test_InvoicePayment_CRUD() { #region Arrange var tmpCustomer = new CustomerConnector().Create(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis" }); var tmpArticle = new ArticleConnector().Create(new Article() { Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 10 }); var invoiceConnector = new InvoiceConnector(); var tmpInvoice = invoiceConnector.Create(new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2020, 1, 20), DueDate = new DateTime(2020, 6, 20), InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 2, Price = 10 }, } }); invoiceConnector.Bookkeep(tmpInvoice.DocumentNumber); MyAssert.HasNoError(invoiceConnector); #endregion Arrange IInvoicePaymentConnector connector = new InvoicePaymentConnector(); #region CREATE var newInvoicePayment = new InvoicePayment() { InvoiceNumber = tmpInvoice.DocumentNumber, Amount = 10.5m, AmountCurrency = 10.5m, PaymentDate = new DateTime(2020, 2, 1) }; var createdInvoicePayment = connector.Create(newInvoicePayment); MyAssert.HasNoError(connector); Assert.AreEqual("2020-02-01", createdInvoicePayment.PaymentDate?.ToString(APIConstants.DateFormat)); #endregion CREATE #region UPDATE createdInvoicePayment.PaymentDate = new DateTime(2020, 3, 1); var updatedInvoicePayment = connector.Update(createdInvoicePayment); MyAssert.HasNoError(connector); Assert.AreEqual("2020-03-01", updatedInvoicePayment.PaymentDate?.ToString(APIConstants.DateFormat)); #endregion UPDATE #region READ / GET var retrievedInvoicePayment = connector.Get(createdInvoicePayment.Number); MyAssert.HasNoError(connector); Assert.AreEqual("2020-03-01", retrievedInvoicePayment.PaymentDate?.ToString(APIConstants.DateFormat)); #endregion READ / GET #region DELETE connector.Delete(createdInvoicePayment.Number); MyAssert.HasNoError(connector); retrievedInvoicePayment = connector.Get(createdInvoicePayment.Number); Assert.AreEqual(null, retrievedInvoicePayment, "Entity still exists after Delete!"); #endregion DELETE #region Delete arranged resources new CustomerConnector().Delete(tmpCustomer.CustomerNumber); new ArticleConnector().Delete(tmpArticle.ArticleNumber); #endregion Delete arranged resources }
public void Test_ContractAccrual_Find() { #region Arrange var tmpCustomer = new CustomerConnector().Create(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis" }); var tmpArticle = new ArticleConnector().Create(new Article() { Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 100 }); var tmpInvoice = new InvoiceConnector().Create(new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2019, 1, 20), //"2019-01-20", DueDate = new DateTime(2019, 2, 20), //"2019-02-20", Comments = "TestInvoice", InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 6, Price = 1000 }, } }); #endregion Arrange IInvoiceAccrualConnector connector = new InvoiceAccrualConnector(); var marks = TestUtils.RandomString(); var newInvoiceAccrual = new InvoiceAccrual() { Description = marks, Period = "MONTHLY", AccrualAccount = 2990, RevenueAccount = 3990, StartDate = new DateTime(2020, 3, 25), EndDate = new DateTime(2020, 6, 25), Total = 6000, InvoiceAccrualRows = new List <InvoiceAccrualRow>() { new InvoiceAccrualRow() { Account = 2990, Credit = 0, Debit = 2000 }, new InvoiceAccrualRow() { Account = 3990, Credit = 2000, Debit = 0 } } }; for (var i = 0; i < 5; i++) { newInvoiceAccrual.InvoiceNumber = tmpInvoice.DocumentNumber; connector.Create(newInvoiceAccrual); MyAssert.HasNoError(connector); var contractConnector = new InvoiceConnector(); tmpInvoice.DocumentNumber = null; tmpInvoice = contractConnector.Create(tmpInvoice); MyAssert.HasNoError(contractConnector); } var contractAccruals = connector.Find(); Assert.AreEqual(5, contractAccruals.Entities.Count(x => x.Description.StartsWith(marks))); foreach (var entry in contractAccruals.Entities.Where(x => x.Description.StartsWith(marks))) { connector.Delete(entry.InvoiceNumber); MyAssert.HasNoError(connector); } #region Delete arranged resources new ArticleConnector().Delete(tmpArticle.ArticleNumber); new CustomerConnector().Delete(tmpCustomer.CustomerNumber); #endregion Delete arranged resources }
public void Test_Filter_By_AccountRange() { #region Arrange var tmpCustomer = new CustomerConnector().Create(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis" }); var tmpArticle = new ArticleConnector().Create(new Article() { Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 100 }); #endregion Arrange IInvoiceConnector connector = new InvoiceConnector(); var invoice1 = new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2019, 1, 20), //"2019-01-20", DueDate = new DateTime(2019, 2, 20), //"2019-02-20", InvoiceType = InvoiceType.CashInvoice, PaymentWay = PaymentWay.Cash, Comments = "TestInvoice", InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { AccountNumber = 1010, ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, Price = 100 }, new InvoiceRow() { AccountNumber = 4000, ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, Price = 100 } } }; var invoice2 = new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2019, 1, 20), //"2019-01-20", DueDate = new DateTime(2019, 2, 20), //"2019-02-20", InvoiceType = InvoiceType.CashInvoice, PaymentWay = PaymentWay.Cash, Comments = "TestInvoice", InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { AccountNumber = 2010, ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, Price = 100 }, new InvoiceRow() { AccountNumber = 4000, ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, Price = 100 } } }; var invoice3 = new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2019, 1, 20), //"2019-01-20", DueDate = new DateTime(2019, 2, 20), //"2019-02-20", InvoiceType = InvoiceType.CashInvoice, PaymentWay = PaymentWay.Cash, Comments = "TestInvoice", InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { AccountNumber = 3000, ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, Price = 100 }, new InvoiceRow() { AccountNumber = 3000, ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, Price = 100 } } }; invoice1 = connector.Create(invoice1); invoice2 = connector.Create(invoice2); invoice3 = connector.Create(invoice3); var filter = new InvoiceSearch() { CustomerNumber = tmpCustomer.CustomerNumber, }; var invoices = connector.Find(filter); Assert.AreEqual(3, invoices.Entities.Count); filter.AccountNumberFrom = "1000"; filter.AccountNumberTo = "1999"; invoices = connector.Find(filter); Assert.AreEqual(1, invoices.Entities.Count); Assert.AreEqual(invoice1.DocumentNumber, invoices.Entities.First().DocumentNumber); filter.AccountNumberFrom = "2000"; filter.AccountNumberTo = "2999"; invoices = connector.Find(filter); Assert.AreEqual(1, invoices.Entities.Count); Assert.AreEqual(invoice2.DocumentNumber, invoices.Entities.First().DocumentNumber); filter.AccountNumberFrom = "3000"; filter.AccountNumberTo = "3999"; invoices = connector.Find(filter); Assert.AreEqual(1, invoices.Entities.Count); Assert.AreEqual(invoice3.DocumentNumber, invoices.Entities.First().DocumentNumber); filter.AccountNumberFrom = "4000"; filter.AccountNumberTo = "4999"; invoices = connector.Find(filter); Assert.AreEqual(2, invoices.Entities.Count); }
public void Test_Invoice_CRUD() { #region Arrange var tmpCustomer = new CustomerConnector().Create(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis" }); var tmpArticle = new ArticleConnector().Create(new Article() { Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 100 }); #endregion Arrange IInvoiceConnector connector = new InvoiceConnector(); #region CREATE var newInvoice = new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2019, 1, 20), //"2019-01-20", DueDate = new DateTime(2019, 2, 20), //"2019-02-20", InvoiceType = InvoiceType.CashInvoice, PaymentWay = PaymentWay.Cash, Comments = "TestInvoice", InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 10, Price = 100 }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, Price = 100 }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, Price = 100 } } }; var createdInvoice = connector.Create(newInvoice); Assert.AreEqual("TestInvoice", createdInvoice.Comments); Assert.AreEqual("TmpCustomer", createdInvoice.CustomerName); Assert.AreEqual(3, createdInvoice.InvoiceRows.Count); #endregion CREATE #region UPDATE createdInvoice.Comments = "UpdatedInvoice"; var updatedInvoice = connector.Update(createdInvoice); Assert.AreEqual("UpdatedInvoice", updatedInvoice.Comments); #endregion UPDATE #region READ / GET var retrievedInvoice = connector.Get(createdInvoice.DocumentNumber); Assert.AreEqual("UpdatedInvoice", retrievedInvoice.Comments); #endregion READ / GET #region DELETE //Not available, Cancel instead connector.Cancel(createdInvoice.DocumentNumber); var cancelledInvoice = connector.Get(createdInvoice.DocumentNumber); Assert.AreEqual(true, cancelledInvoice.Cancelled); #endregion DELETE #region Delete arranged resources new CustomerConnector().Delete(tmpCustomer.CustomerNumber); //new ArticleConnector().Delete(tmpArticle.ArticleNumber); #endregion Delete arranged resources }
public void Test_Find() { #region Arrange var tmpCustomer = new CustomerConnector().Create(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis" }); var tmpArticle = new ArticleConnector().Create(new Article() { Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 100 }); #endregion Arrange IInvoiceConnector connector = new InvoiceConnector(); var newInvoice = new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2019, 1, 20), //"2019-01-20", DueDate = new DateTime(2019, 2, 20), //"2019-02-20", InvoiceType = InvoiceType.CashInvoice, PaymentWay = PaymentWay.Cash, Comments = "TestInvoice", InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 10, Price = 100 }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, Price = 100 }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, Price = 100 } } }; //Add entries for (var i = 0; i < 5; i++) { connector.Create(newInvoice); } //Apply base test filter var searchSettings = new InvoiceSearch(); searchSettings.CustomerNumber = tmpCustomer.CustomerNumber; var fullCollection = connector.Find(searchSettings); Assert.AreEqual(5, fullCollection.TotalResources); Assert.AreEqual(5, fullCollection.Entities.Count); Assert.AreEqual(1, fullCollection.TotalPages); Assert.AreEqual(tmpCustomer.CustomerNumber, fullCollection.Entities.First().CustomerNumber); //Apply Limit searchSettings.Limit = 2; var limitedCollection = connector.Find(searchSettings); Assert.AreEqual(5, limitedCollection.TotalResources); Assert.AreEqual(2, limitedCollection.Entities.Count); Assert.AreEqual(3, limitedCollection.TotalPages); //Delete entries (DELETE not supported) foreach (var invoice in fullCollection.Entities) { connector.Cancel(invoice.DocumentNumber); } #region Delete arranged resources new CustomerConnector().Delete(tmpCustomer.CustomerNumber); //new ArticleConnector().Delete(tmpArticle.ArticleNumber); #endregion Delete arranged resources }