コード例 #1
0
ファイル: Testv300.cs プロジェクト: Zwapgrid/fortnox-sdk
        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);
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        public void Test_Invoice_FilterByLabel()
        {
            #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()
            });
            var label3 = labelConnector.Create(new Label()
            {
                Description = TestUtils.RandomString()
            });

            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()
                    {
                        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 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()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, Price = 100
                    },
                    new InvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, Price = 100
                    }
                },
                Labels = new List <LabelReference>()
                {
                    new LabelReference(label2.Id),
                    new LabelReference(label3.Id),
                }
            };

            invoice1 = connector.Create(invoice1);
            invoice2 = connector.Create(invoice2);

            var filter = new InvoiceSearch()
            {
                CustomerNumber = tmpCustomer.CustomerNumber
            };

            var invoices = connector.Find(filter);
            Assert.AreEqual(2, invoices.Entities.Count);

            filter.LabelReference = label1.Id;
            invoices = connector.Find(filter);
            Assert.AreEqual(1, invoices.Entities.Count);

            filter.LabelReference = label2.Id;
            invoices = connector.Find(filter);
            Assert.AreEqual(2, invoices.Entities.Count);

            filter.LabelReference = label3.Id;
            invoices = connector.Find(filter);
            Assert.AreEqual(1, invoices.Entities.Count);

            //Clean
            connector.Cancel(invoice1.DocumentNumber);
            connector.Cancel(invoice2.DocumentNumber);
            labelConnector.Delete(label1.Id);
            labelConnector.Delete(label2.Id);
        }
コード例 #4
0
        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);
        }
コード例 #5
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.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
        }