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);
        }
예제 #2
0
        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);

            #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
            inboxConnector.DeleteFile(fortnoxFile.Id);
        }
예제 #3
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
        }