Beispiel #1
0
        public void TestSupplierInvoice()
        {
            var connector = new SupplierInvoiceConnector();

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

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

            Assert.IsFalse(connector.HasError);
            Assert.IsTrue(invoice.AccountingMethod == "ACCRUAL");

            invoice.PaymentPending = "true";
            invoice.CostCenter     = "101";
            invoice.YourReference  = "ABC";
            invoice.OurReference   = "DEF";
            invoice = connector.Update(invoice);

            Assert.IsFalse(connector.HasError);
            Assert.IsTrue(invoice.PaymentPending == "true");
            Assert.IsTrue(invoice.CostCenter == "101");
            Assert.IsTrue(invoice.YourReference == "ABC");
            Assert.IsTrue(invoice.OurReference == "DEF");

            invoice.PaymentPending = "false";
            invoice.CostCenter     = "100";
            invoice.Project        = "2";
            invoice = connector.Update(invoice);

            Assert.IsFalse(connector.HasError);
            Assert.IsTrue(invoice.PaymentPending == "false");
            Assert.IsTrue(invoice.CostCenter == "100");
            Assert.IsTrue(invoice.Project == "2");


            connector.FromDate = "2017-01-01";
            connector.ToDate   = "2017-04-03";

            var invoices = connector.Find();

            Assert.IsFalse(connector.HasError);
            Assert.IsTrue(invoices.TotalResources == "3");
        }
        public void TestSupplierInvoice()
        {
            var connector = new SupplierInvoiceConnector();

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

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

            Assert.IsFalse(connector.HasError);
            Assert.IsTrue(invoice.AccountingMethod == SupplierInvoiceConnector.AccountingMethod.ACCRUAL);

            invoice.PaymentPending = "true";
            invoice.CostCenter     = "101";
            invoice.YourReference  = "ABC";
            invoice.OurReference   = "DEF";
            invoice.Project        = "1";
            invoice = connector.Update(invoice);

            Assert.IsFalse(connector.HasError);
            Assert.IsTrue(invoice.PaymentPending == "true");
            Assert.IsTrue(invoice.CostCenter == "101");
            Assert.IsTrue(invoice.Project == "1");
            Assert.IsTrue(invoice.YourReference == "ABC");
            Assert.IsTrue(invoice.OurReference == "DEF");

            invoice.PaymentPending = "false";
            invoice.CostCenter     = "100";
            invoice.Project        = "2";
            invoice = connector.Update(invoice);

            Assert.IsFalse(connector.HasError);
            Assert.IsTrue(invoice.PaymentPending == "false");
            Assert.IsTrue(invoice.CostCenter == "100");
            Assert.IsTrue(invoice.Project == "2");
        }
        public void Test_SupplierInvoice_CRUD()
        {
            #region Arrange
            var tmpSupplier = new SupplierConnector().Create(new Supplier()
            {
                Name = "TmpSupplier"
            });
            var tmpArticle = new ArticleConnector().Create(new Article()
            {
                Description = "TmpArticle", PurchasePrice = 100
            });
            #endregion Arrange

            ISupplierInvoiceConnector connector = new SupplierInvoiceConnector();

            #region CREATE
            var newSupplierInvoice = new SupplierInvoice()
            {
                SupplierNumber      = tmpSupplier.SupplierNumber,
                Comments            = "InvoiceComments",
                InvoiceDate         = new DateTime(2010, 1, 1),
                DueDate             = new DateTime(2010, 2, 1),
                SalesType           = SalesType.Stock,
                OCR                 = "123456789",
                Total               = 5000,
                SupplierInvoiceRows = new List <SupplierInvoiceRow>()
                {
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 10, Price = 100
                    },
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 20, Price = 100
                    },
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 20, Price = 100
                    }
                }
            };

            var createdSupplierInvoice = connector.Create(newSupplierInvoice);
            Assert.AreEqual("InvoiceComments", createdSupplierInvoice.Comments);
            Assert.AreEqual("TmpSupplier", createdSupplierInvoice.SupplierName);
            Assert.AreEqual(3 + 1, createdSupplierInvoice.SupplierInvoiceRows.Count);
            //3 + 1 => A row "Leverant�rsskulder" is created by default

            #endregion CREATE

            #region UPDATE

            createdSupplierInvoice.Comments = "UpdatedInvoiceComments";

            var updatedSupplierInvoice = connector.Update(createdSupplierInvoice);
            Assert.AreEqual("UpdatedInvoiceComments", updatedSupplierInvoice.Comments);

            #endregion UPDATE

            #region READ / GET

            var retrievedSupplierInvoice = connector.Get(createdSupplierInvoice.GivenNumber);
            Assert.AreEqual("UpdatedInvoiceComments", retrievedSupplierInvoice.Comments);

            #endregion READ / GET

            #region DELETE
            //Not supported
            connector.Cancel(createdSupplierInvoice.GivenNumber);
            var cancelledInvoice = connector.Get(createdSupplierInvoice.GivenNumber);
            Assert.AreEqual(true, cancelledInvoice.Cancelled);
            #endregion DELETE

            #region Delete arranged resources
            new SupplierConnector().Delete(tmpSupplier.SupplierNumber);
            new ArticleConnector().Delete(tmpArticle.ArticleNumber);
            #endregion Delete arranged resources
        }
        public void Test_SupplierInvoice_CRUD()
        {
            //Arrange
            var tmpSupplier = new SupplierConnector().Create(new Supplier()
            {
                Name = "TmpSupplier", CountryCode = "SE", City = "Testopolis"
            });
            var tmpArticle = new ArticleConnector().Create(new Article()
            {
                Description = "TmpArticle", Type = ArticleType.STOCK, PurchasePrice = 100
            });

            //Act
            var connector = new SupplierInvoiceConnector();

            #region CREATE
            var newInvoice = new SupplierInvoice()
            {
                SupplierNumber      = tmpSupplier.SupplierNumber,
                InvoiceDate         = new DateTime(2019, 1, 20).ToString(APIConstants.DateFormat), //"2019-01-20",
                DueDate             = new DateTime(2019, 2, 20).ToString(APIConstants.DateFormat), //"2019-02-20",
                SalesType           = SalesType.STOCK,
                OCR                 = "123456789",
                SupplierInvoiceRows = new List <SupplierInvoiceRow>()
                {
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 10
                    },
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 20
                    },
                    new SupplierInvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, Quantity = 15
                    }
                }
            };

            var createdInvoice = connector.Create(newInvoice);
            MyAssert.HasNoError(connector);
            Assert.AreEqual(createdInvoice.SupplierName, "TmpSupplier");
            Assert.AreEqual(3 + 1, createdInvoice.SupplierInvoiceRows.Count);
            //3 + 1 => A row "Leverantörsskulder" is created by default

            #endregion CREATE

            #region UPDATE

            createdInvoice.OCR = "987654321";
            var updatedInvoice = connector.Update(createdInvoice);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("987654321", updatedInvoice.OCR);

            #endregion UPDATE

            #region READ / GET

            var retrievedInvoice = connector.Get(createdInvoice.GivenNumber);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("987654321", retrievedInvoice.OCR);

            #endregion READ / GET

            #region DELETE
            //Invoice does not provide DELETE method, but can be canceled
            connector.Cancel(createdInvoice.GivenNumber);
            MyAssert.HasNoError(connector);

            retrievedInvoice = connector.Get(createdInvoice.GivenNumber);
            Assert.AreEqual(true, retrievedInvoice.Cancelled);

            #endregion DELETE

            //Clean
            new SupplierConnector().Delete(tmpSupplier.SupplierNumber);
            new ArticleConnector().Delete(tmpArticle.ArticleNumber);
        }