コード例 #1
0
        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);
        }
コード例 #2
0
        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
        }
コード例 #3
0
        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
        }
コード例 #4
0
        public void Test_Email()
        {
            #region Arrange
            var tmpCustomer = new CustomerConnector().Create(new Customer()
            {
                Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis", Email = "*****@*****.**"
            });
            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       = "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);

            var emailedInvoice = connector.Email(createdInvoice.DocumentNumber);
            Assert.AreEqual(emailedInvoice.DocumentNumber, createdInvoice.DocumentNumber);

            connector.Cancel(createdInvoice.DocumentNumber);

            #region Delete arranged resources
            new CustomerConnector().Delete(tmpCustomer.CustomerNumber);
            //new ArticleConnector().Delete(tmpArticle.ArticleNumber);
            #endregion Delete arranged resources
        }
コード例 #5
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);
        }
コード例 #6
0
        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
        }
コード例 #7
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
        }