Example #1
0
        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);
        }
Example #2
0
        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_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);
        }
Example #4
0
        public void Test_TaxReductionChanges_2021()
        {
            var tmpCustomer = new CustomerConnector().Create(new Customer()
            {
                Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis"
            });

            var houseworkArticle = new ArticleConnector().Create(new Article()
            {
                Description   = "TmpArticle",
                Type          = ArticleType.Service,
                HouseworkType = HouseworkType.SolarCells,
                Housework     = true
            });

            var houseworkInvoice = new InvoiceConnector().Create(new Invoice()
            {
                CustomerNumber   = tmpCustomer.CustomerNumber,
                InvoiceDate      = new DateTime(2021, 1, 20), //"2019-01-20",
                DueDate          = new DateTime(2021, 2, 20), //"2019-02-20",
                Comments         = "TestInvoice",
                TaxReductionType = TaxReductionType.Green,
                InvoiceRows      = new List <InvoiceRow>()
                {
                    new InvoiceRow()
                    {
                        ArticleNumber = houseworkArticle.ArticleNumber, DeliveredQuantity = 10, HouseWorkHoursToReport = 10, Price = 1000
                    },
                    new InvoiceRow()
                    {
                        ArticleNumber = houseworkArticle.ArticleNumber, DeliveredQuantity = 20, HouseWorkHoursToReport = 20, Price = 1000
                    },
                    new InvoiceRow()
                    {
                        ArticleNumber = houseworkArticle.ArticleNumber, DeliveredQuantity = 15, HouseWorkHoursToReport = 15, Price = 1000
                    }
                }
            });

            Assert.AreEqual(true, houseworkInvoice.HouseWork);
            Assert.AreEqual(TaxReductionType.Green, houseworkInvoice.TaxReductionType);

            var createdTaxReduction = new TaxReductionConnector().Create(new TaxReduction()
            {
                CustomerName          = "TmpCustomer",
                AskedAmount           = 100,
                SocialSecurityNumber  = "760412-0852",
                ReferenceNumber       = houseworkInvoice.DocumentNumber,
                ReferenceDocumentType = ReferenceDocumentType.Invoice
            });

            Assert.AreEqual(100, createdTaxReduction.AskedAmount);

            //Check if invoice is still the same
            var retrievedInvoice = new InvoiceConnector().Get(houseworkInvoice.DocumentNumber);

            Assert.AreEqual(true, retrievedInvoice.HouseWork);
            Assert.AreEqual(TaxReductionType.Green, retrievedInvoice.TaxReductionType);
        }
        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
        }
Example #6
0
        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);
            }
        }
Example #7
0
        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
        }
Example #8
0
        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_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
        }
Example #10
0
        public void TestRequestingInvoiceByYourOrderNumber()
        {
            var connector = new InvoiceConnector
            {
                Authorization   = new StaticTokenAuth(at, cs),
                YourOrderNumber = "20190809"
            };
            var invoice = connector.Find();

            Assert.IsTrue(invoice.InvoiceSubset != null);
            Assert.IsTrue(invoice.InvoiceSubset.First() != null);
        }
        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
        }
Example #12
0
        public void Test_Search()
        {
            var connector = new InvoiceConnector();

            connector.Search.FromDate = new DateTime(2020, 10, 10);
            connector.Search.ToDate   = new DateTime(2020, 10, 15);

            var result = connector.Find();

            Assert.IsTrue(result.Entities.Count > 0);
            foreach (var invoice in result.Entities)
            {
                Assert.IsTrue(invoice.InvoiceDate >= connector.Search.FromDate);
                Assert.IsTrue(invoice.InvoiceDate <= connector.Search.ToDate);
            }
        }
Example #13
0
        public void TestInvoice()
        {
            var connector = new InvoiceConnector();

            connector.Authorization = new StaticTokenAuth(at, cs);

            var invoice = connector.Get("988");

            invoice.PaymentWay = "CASH";
            invoice            = connector.Update(invoice);
            Assert.IsFalse(connector.HasError);
            Assert.IsTrue(invoice.PaymentWay == "CASH");

            invoice.PaymentWay = "AA";
            invoice            = connector.Update(invoice);
            Assert.IsFalse(connector.HasError);
            Assert.IsTrue(invoice.PaymentWay == "AA");
        }
Example #14
0
        public void TestInvoice()
        {
            var connector = new InvoiceConnector();

            connector.AccessToken  = at;
            connector.ClientSecret = cs;

            var invoice = connector.Get("988");

            invoice.PaymentWay = InvoiceConnector.PaymentWay.CASH;
            invoice            = connector.Update(invoice);
            Assert.IsFalse(connector.HasError);
            Assert.IsTrue(invoice.PaymentWay == InvoiceConnector.PaymentWay.CASH);

            invoice.PaymentWay = InvoiceConnector.PaymentWay.AG;
            invoice            = connector.Update(invoice);
            Assert.IsFalse(connector.HasError);
            Assert.IsTrue(invoice.PaymentWay == InvoiceConnector.PaymentWay.AG);
        }
Example #15
0
        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
        }
Example #16
0
        public void Test_TaxReduction_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.Service, PurchasePrice = 1000
            });
            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 = 10, HouseWorkHoursToReport = 10, Price = 1000, HouseWorkType = HouseworkType.Gardening, HouseWork = true
                    },
                    new InvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, HouseWorkHoursToReport = 20, Price = 1000, HouseWorkType = HouseworkType.Gardening, HouseWork = true
                    },
                    new InvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, HouseWorkHoursToReport = 15, Price = 1000, HouseWorkType = HouseworkType.Gardening, HouseWork = true
                    }
                }
            });
            #endregion Arrange

            ITaxReductionConnector connector = new TaxReductionConnector();

            #region CREATE

            var newTaxReduction = new TaxReduction()
            {
                //TypeOfReduction = TypeOfReduction.RUT,
                CustomerName          = "TmpCustomer",
                AskedAmount           = 100,
                SocialSecurityNumber  = "760412-0852",
                ReferenceNumber       = tmpInvoice.DocumentNumber,
                ReferenceDocumentType = ReferenceDocumentType.Invoice
            };

            var createdTaxReduction = connector.Create(newTaxReduction);
            MyAssert.HasNoError(connector);
            Assert.AreEqual(100, createdTaxReduction.AskedAmount);

            #endregion CREATE

            #region UPDATE

            createdTaxReduction.AskedAmount = 200;

            var updatedTaxReduction = connector.Update(createdTaxReduction);
            MyAssert.HasNoError(connector);
            Assert.AreEqual(200, updatedTaxReduction.AskedAmount);

            #endregion UPDATE

            #region READ / GET

            var retrievedTaxReduction = connector.Get(createdTaxReduction.Id);
            MyAssert.HasNoError(connector);
            Assert.AreEqual(200, retrievedTaxReduction.AskedAmount);

            #endregion READ / GET

            #region DELETE
            //Can not delete tax redution if there is only one, therefore one more is created
            connector.Create(new TaxReduction()
            {
                //TypeOfReduction = TypeOfReduction.RUT,
                CustomerName          = "TmpCustomer",
                AskedAmount           = 200,
                SocialSecurityNumber  = "880515-2033",
                ReferenceNumber       = tmpInvoice.DocumentNumber,
                ReferenceDocumentType = ReferenceDocumentType.Invoice
            });

            connector.Delete(createdTaxReduction.Id);
            MyAssert.HasNoError(connector);

            retrievedTaxReduction = connector.Get(createdTaxReduction.Id);
            Assert.AreEqual(null, retrievedTaxReduction, "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
        }
Example #17
0
        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.Service, PurchasePrice = 1000
            });
            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 = 10, HouseWorkHoursToReport = 10, Price = 1000, HouseWorkType = HouseworkType.Gardening, HouseWork = true
                    },
                    new InvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, HouseWorkHoursToReport = 20, Price = 1000, HouseWorkType = HouseworkType.Gardening, HouseWork = true
                    },
                    new InvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, HouseWorkHoursToReport = 15, Price = 1000, HouseWorkType = HouseworkType.Gardening, HouseWork = true
                    }
                }
            });
            #endregion Arrange

            //var testKeyMark = TestUtils.RandomString();

            ITaxReductionConnector connector = new TaxReductionConnector();
            var newTaxReduction = new TaxReduction()
            {
                CustomerName          = "TmpCustomer",
                AskedAmount           = 200,
                ReferenceNumber       = tmpInvoice.DocumentNumber,
                ReferenceDocumentType = ReferenceDocumentType.Invoice
            };

            //Add entries
            for (var i = 0; i < 5; i++)
            {
                newTaxReduction.SocialSecurityNumber = TestUtils.RandomPersonalNumber();
                connector.Create(newTaxReduction);
                MyAssert.HasNoError(connector);
            }

            //Apply base test filter
            connector.Search.ReferenceNumber = tmpInvoice.DocumentNumber.ToString();
            var fullCollection = connector.Find();
            MyAssert.HasNoError(connector);

            Assert.AreEqual(5, fullCollection.TotalResources);
            Assert.AreEqual(5, fullCollection.Entities.Count);
            Assert.AreEqual(1, fullCollection.TotalPages);

            //Apply Limit
            connector.Search.Limit = 2;
            var limitedCollection = connector.Find();
            MyAssert.HasNoError(connector);

            Assert.AreEqual(5, limitedCollection.TotalResources);
            Assert.AreEqual(2, limitedCollection.Entities.Count);
            Assert.AreEqual(3, limitedCollection.TotalPages);

            //Delete entries
            foreach (var entry in fullCollection.Entities)
            {
                connector.Delete(entry.Id);
            }

            #region Delete arranged resources
            new CustomerConnector().Delete(tmpCustomer.CustomerNumber);
            new ArticleConnector().Delete(tmpArticle.ArticleNumber);
            #endregion Delete arranged resources
        }
Example #18
0
        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);
        }
Example #19
0
        public void Test_InvoiceAccrual_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
            });

            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();

            #region CREATE
            var newInvoiceAccrual = new InvoiceAccrual()
            {
                Description        = "TestInvoiceAccrual",
                InvoiceNumber      = tmpInvoice.DocumentNumber,
                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
                    }
                }
            };

            var createdInvoiceAccrual = connector.Create(newInvoiceAccrual);
            Assert.AreEqual("TestInvoiceAccrual", createdInvoiceAccrual.Description);

            #endregion CREATE

            #region UPDATE

            createdInvoiceAccrual.Description = "UpdatedTestInvoiceAccrual";

            var updatedInvoiceAccrual = connector.Update(createdInvoiceAccrual);
            Assert.AreEqual("UpdatedTestInvoiceAccrual", updatedInvoiceAccrual.Description);

            #endregion UPDATE

            #region READ / GET

            var retrievedInvoiceAccrual = connector.Get(createdInvoiceAccrual.InvoiceNumber);
            Assert.AreEqual("UpdatedTestInvoiceAccrual", retrievedInvoiceAccrual.Description);

            #endregion READ / GET

            #region DELETE

            connector.Delete(createdInvoiceAccrual.InvoiceNumber);

            Assert.ThrowsException <FortnoxApiException>(
                () => connector.Get(createdInvoiceAccrual.InvoiceNumber),
                "Entity still exists after Delete!");

            #endregion DELETE

            #region Delete arranged resources

            new InvoiceConnector().Cancel(tmpInvoice.DocumentNumber);
            //new CustomerConnector().Delete(tmpCustomer.CustomerNumber);
            //new ArticleConnector().Delete(tmpArticle.ArticleNumber);
            #endregion Delete arranged resources
        }
Example #20
0
        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_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
        }
Example #23
0
        public void Test_InvoiceAccrual_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

            IInvoiceAccrualConnector connector = new InvoiceAccrualConnector();

            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",
                Comments       = "TestInvoice",
                InvoiceRows    = new List <InvoiceRow>()
                {
                    new InvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 6, Price = 1000
                    },
                }
            };

            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++)
            {
                var createdInvoice = new InvoiceConnector().Create(invoice);

                newInvoiceAccrual.InvoiceNumber = createdInvoice.DocumentNumber;
                connector.Create(newInvoiceAccrual);
            }

            var contractAccruals = connector.Find(null);
            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);
                new InvoiceConnector().Cancel(entry.InvoiceNumber);
            }

            #region Delete arranged resources
            //new ArticleConnector().Delete(tmpArticle.ArticleNumber);
            new CustomerConnector().Delete(tmpCustomer.CustomerNumber);
            #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
        }