Esempio n. 1
0
        public void Test_GetSupplierFolder()
        {
            IArchiveConnector connector1 = new InboxConnector();
            var folder1 = connector1.GetFolder(StaticFolders.SupplierInvoices);

            Assert.AreEqual("inbox_s", folder1.Id);

            IArchiveConnector connector2 = new ArchiveConnector();
            var folder2 = connector2.GetFolder(StaticFolders.SupplierInvoices);

            Assert.AreEqual("inbox_s", folder2.Id);
        }
        public void Test_Issue99_v2_fixed() // Origins from https://github.com/FortnoxAB/csharp-api-sdk/issues/99
        {
            #region Arrange
            IArchiveConnector ac = new InboxConnector();

            var data           = Resource.fortnox_image;
            var randomFileName = TestUtils.RandomString() + ".txt";

            var fortnoxFile = ac.UploadFile(randomFileName, data, StaticFolders.SupplierInvoices);
            MyAssert.HasNoError(ac);

            #endregion Arrange

            var archiveConnector = new ArchiveConnector();
            var case1            = archiveConnector.DownloadFile(fortnoxFile.Id, IdType.Id);
            var case2            = archiveConnector.DownloadFile(fortnoxFile.Id, IdType.FileId);
            var case3            = archiveConnector.DownloadFile(fortnoxFile.ArchiveFileId, IdType.Id);
            var case4            = archiveConnector.DownloadFile(fortnoxFile.ArchiveFileId, IdType.FileId);

            Assert.IsNotNull(case1);
            Assert.IsNull(case2);
            Assert.IsNull(case3);
            Assert.IsNotNull(case4);

            var inboxConnector = new InboxConnector();
            var case5          = inboxConnector.DownloadFile(fortnoxFile.Id, IdType.Id);
            var case6          = inboxConnector.DownloadFile(fortnoxFile.Id, IdType.FileId);

            var case7 = inboxConnector.DownloadFile(fortnoxFile.ArchiveFileId, IdType.Id);
            var case8 = inboxConnector.DownloadFile(fortnoxFile.ArchiveFileId, IdType.FileId);

            Assert.IsNotNull(case5);
            Assert.IsNotNull(case6); //Why not null?
            Assert.IsNull(case7);
            Assert.IsNotNull(case8);

            //Clean
            inboxConnector.DeleteFile(fortnoxFile.Id);
            MyAssert.HasNoError(archiveConnector);
        }
Esempio n. 3
0
        public void Test_Issue99_v1_fixed() // Origins from https://github.com/FortnoxAB/csharp-api-sdk/issues/99
        {
            #region Arrange
            IArchiveConnector ac = new ArchiveConnector();

            var data           = Resource.fortnox_image;
            var randomFileName = TestUtils.RandomString() + ".txt";

            var fortnoxFile = ac.UploadFile(randomFileName, data, StaticFolders.SupplierInvoices);

            #endregion Arrange

            var archiveConnector = new ArchiveConnector();
            var case1            = archiveConnector.DownloadFile(fortnoxFile.Id, IdType.Id);     //no error
            Assert.ThrowsException <FortnoxApiException>(
                () => archiveConnector.DownloadFile(fortnoxFile.Id, IdType.FileId));             //has error
            Assert.ThrowsException <FortnoxApiException>(
                () => archiveConnector.DownloadFile(fortnoxFile.ArchiveFileId, IdType.Id));      //has error
            var case4 = archiveConnector.DownloadFile(fortnoxFile.ArchiveFileId, IdType.FileId); //no error

            Assert.IsNotNull(case1);
            Assert.IsNotNull(case4);

            var inboxConnector = new InboxConnector();
            var case5          = inboxConnector.DownloadFile(fortnoxFile.Id, IdType.Id);     //no error
            var case6          = inboxConnector.DownloadFile(fortnoxFile.Id, IdType.FileId); //no error, why?

            Assert.ThrowsException <FortnoxApiException>(
                () => inboxConnector.DownloadFile(fortnoxFile.ArchiveFileId, IdType.Id));      //has error
            var case8 = inboxConnector.DownloadFile(fortnoxFile.ArchiveFileId, IdType.FileId); //no error

            Assert.IsNotNull(case5);
            Assert.IsNotNull(case6);
            Assert.IsNotNull(case8);

            //Clean
            archiveConnector.DeleteFile(fortnoxFile.Id);
        }
Esempio n. 4
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
        }
        public void Test_SupplierInvoiceFileConnection_CRUD()
        {
            #region Arrange
            var tmpSupplier = new SupplierConnector().Create(new Supplier()
            {
                Name = "TmpSupplier"
            });
            var tmpArticle = new ArticleConnector().Create(new Article()
            {
                Description = "TmpArticle", PurchasePrice = 100
            });
            var tmpSpplierInvoice = new SupplierInvoiceConnector().Create(new SupplierInvoice()
            {
                SupplierNumber      = tmpSupplier.SupplierNumber,
                Comments            = "InvoiceComments",
                InvoiceDate         = new DateTime(2020, 1, 1),
                DueDate             = new DateTime(2020, 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 tmpFile = new InboxConnector().UploadFile("tmpImage.png", Resource.fortnox_image, StaticFolders.SupplierInvoices);
            #endregion Arrange

            ISupplierInvoiceFileConnectionConnector connector = new SupplierInvoiceFileConnectionConnector();

            #region CREATE
            var newSupplierInvoiceFileConnection = new SupplierInvoiceFileConnection()
            {
                SupplierInvoiceNumber = tmpSpplierInvoice.GivenNumber.ToString(),
                FileId = tmpFile.Id
            };

            var createdSupplierInvoiceFileConnection = connector.Create(newSupplierInvoiceFileConnection);
            MyAssert.HasNoError(connector);
            Assert.AreEqual(tmpSupplier.Name, createdSupplierInvoiceFileConnection.SupplierName);

            #endregion CREATE

            #region UPDATE
            //Not supported
            #endregion UPDATE

            #region READ / GET

            var retrievedSupplierInvoiceFileConnection = connector.Get(createdSupplierInvoiceFileConnection.FileId);
            MyAssert.HasNoError(connector);
            Assert.AreEqual(tmpSupplier.Name, retrievedSupplierInvoiceFileConnection.SupplierName);

            #endregion READ / GET

            #region DELETE

            connector.Delete(createdSupplierInvoiceFileConnection.FileId);
            MyAssert.HasNoError(connector);

            retrievedSupplierInvoiceFileConnection = connector.Get(createdSupplierInvoiceFileConnection.FileId);
            Assert.AreEqual(null, retrievedSupplierInvoiceFileConnection, "Entity still exists after Delete!");

            #endregion DELETE

            #region Delete arranged resources
            new ArticleConnector().Delete(tmpArticle.ArticleNumber);
            new SupplierConnector().Delete(tmpSupplier.SupplierNumber);
            #endregion Delete arranged resources
        }