Пример #1
0
        public void Test_ReadOnlyProperty_NotSerialized()
        {
            var connector = new CustomerConnector();

            var createdCustomer = connector.Create(new Customer()
            {
                Name = "TestCustomer", CountryCode = "SE"
            });

            MyAssert.HasNoError(connector);

            connector.Update(createdCustomer);
            MyAssert.HasNoError(connector);
            Assert.IsFalse(connector.RequestContent.Contains("\"Country\":"), "Read-only property exists in Update request!");
            //Country is read-only, should not be send in update request even if its unchanged

            connector.Delete(createdCustomer.CustomerNumber);
            MyAssert.HasNoError(connector);
        }
        public void Test_issue57_fixed() // Origins from https://github.com/FortnoxAB/csharp-api-sdk/issues/57
        {
            var connector        = new CustomerConnector();
            var specificCustomer = connector.Create(new Customer()
            {
                Name = "TestCustomer", OrganisationNumber = "123456789"
            });

            Assert.IsFalse(connector.HasError);

            connector.Search.OrganisationNumber = "123456789";
            var customers = connector.Find().Entities;
            var customer  = customers.FirstOrDefault(c => c.CustomerNumber == specificCustomer.CustomerNumber);

            Assert.IsNotNull(customer);

            connector.Delete(specificCustomer.CustomerNumber);
            MyAssert.HasNoError(connector);
        }
        public void Test_issue50_fixed() // Origins from https://github.com/FortnoxAB/csharp-api-sdk/issues/50
        {
            var connector   = new CustomerConnector();
            var newCustomer = connector.Create(new Customer()
            {
                Name = "TestCustomer", City = "Växjö", Type = CustomerType.Company
            });

            MyAssert.HasNoError(connector);

            var updatedCustomer = connector.Update(new Customer()
            {
                CustomerNumber = newCustomer.CustomerNumber, City = "Stockholm"
            });

            MyAssert.HasNoError(connector);
            Assert.AreEqual(CustomerType.Company, updatedCustomer.Type);

            connector.Delete(newCustomer.CustomerNumber);
            MyAssert.HasNoError(connector);
        }
        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);
        }
        public void Test_issue84_fixed() //Origins from https://github.com/FortnoxAB/csharp-api-sdk/issues/84
        {
            //Arrange
            IArchiveConnector conn = new ArchiveConnector();
            var testRootFolder     = conn.GetFolder("TestArchive") ?? conn.CreateFolder("TestArchive");

            //Act
            IArchiveConnector connector = new ArchiveConnector();

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

            var fortnoxFile = connector.UploadFile(randomFileName, data, testRootFolder.Name);

            MyAssert.HasNoError(connector);

            //Assert
            Assert.AreEqual(randomFileName, fortnoxFile.Name);

            //Clean
            connector.DeleteFile(fortnoxFile.Id);
            MyAssert.HasNoError(connector);
        }
Пример #6
0
        public void Test_issue51_fixed() //Origins from https://github.com/FortnoxAB/csharp-api-sdk/issues/51
        {
            //Arrange
            /* Assuming several (at least 5) vouchers exists */

            //Act & Assert
            var connector = new VoucherConnector();

            connector.Limit = 2;
            var voucherResult = connector.Find();

            MyAssert.HasNoError(connector);

            connector.Page = 2;
            var voucherResult2 = connector.Find();

            MyAssert.HasNoError(connector);

            connector.Page = 3;
            var voucherResult3 = connector.Find();

            MyAssert.HasNoError(connector);
        }
Пример #7
0
        public void Test_File_Data_Upload_Download_Delete()
        {
            var connector = new ArchiveConnector();

            // UPLOAD FILE DATA
            var uploadedFile = connector.UploadFileData(Resource.fortnox_image, "FortnoxImage.png", "");

            MyAssert.HasNoError(connector);
            Assert.AreEqual("image/png", uploadedFile.ContentType);

            //DOWNLOAD FILE DATA
            var downloadedFile = new File()
            {
                Id = uploadedFile.Id
            };

            connector.DownloadFileData(downloadedFile);
            Assert.AreEqual(Resource.fortnox_image.Length, downloadedFile.Data.Length);
            MyAssert.HasNoError(connector);

            //DELETE FILE
            connector.DeleteFile(uploadedFile.Id);
            MyAssert.HasNoError(connector);
        }
Пример #8
0
        public void Test_Folder_Create_Find_Delete()
        {
            var connector = new ArchiveConnector();

            var folder = connector.CreateFolder(new Folder {
                Name = Path.GetRandomFileName()
            });

            MyAssert.HasNoError(connector);

            var subFolder1 = connector.CreateFolder(new Folder {
                Name = "TestSubFolder1"
            }, folder.Name);

            MyAssert.HasNoError(connector);
            var subFolder2 = connector.CreateFolder(new Folder {
                Name = "TestSubFolder2"
            }, folder.Name);

            MyAssert.HasNoError(connector);

            connector.FolderId = folder.Id;
            var folderContent = connector.Find();

            MyAssert.HasNoError(connector);
            Assert.AreEqual(2, folderContent.Folders.Count);
            Assert.IsTrue(folderContent.Folders.Any(f => f.Name.Equals(subFolder1.Name))); //contains subfolder1
            Assert.IsTrue(folderContent.Folders.Any(f => f.Name.Equals(subFolder2.Name))); //contains subfolder2

            connector.DeleteFolder(subFolder1.Id);
            MyAssert.HasNoError(connector);
            connector.DeleteFolder(subFolder2.Id);
            MyAssert.HasNoError(connector);
            connector.DeleteFolder(folder.Id);
            MyAssert.HasNoError(connector);
        }
        public void Test_Issue96_fixed() // Origins from https://github.com/FortnoxAB/csharp-api-sdk/issues/96
        {
            #region Arrange
            var tmpSupplier = new SupplierConnector().Create(new Supplier()
            {
                Name = "TmpSupplier"
            });
            var tmpArticle = new ArticleConnector().Create(new Article()
            {
                Description = "TmpArticle", PurchasePrice = 100
            });
            #endregion Arrange

            var connector = new SupplierInvoiceConnector();

            var createdInvoice = connector.Create(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
                    }
                }
            });
            MyAssert.HasNoError(connector);
            Assert.AreEqual(false, createdInvoice.Cancelled);

            var retrievedInvoice = connector.Get(createdInvoice.GivenNumber);
            MyAssert.HasNoError(connector);
            Assert.AreEqual(false, retrievedInvoice.Cancelled);

            connector.Search.LastModified = DateTime.Today;
            var invoiceSubsets = connector.Find().Entities;
            MyAssert.HasNoError(connector);
            foreach (var supplierInvoiceSubset in invoiceSubsets)
            {
                Assert.IsNotNull(supplierInvoiceSubset.Cancelled);
            }

            #region Delete arranged resources

            new CustomerConnector().Delete(tmpSupplier.SupplierNumber);
            new ArticleConnector().Delete(tmpArticle.ArticleNumber);

            #endregion Delete arranged resources
        }
Пример #10
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);
        }
Пример #11
0
        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);
        }
Пример #12
0
        public void Test_Contract_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 ContractConnector();

            #region CREATE
            var newContract = new Contract()
            {
                CustomerNumber = tmpCustomer.CustomerNumber,
                ContractDate   = new DateTime(2019, 1, 20).ToString(APIConstants.DateFormat), //"2019-01-20",
                Active         = false,
                Comments       = "Contract used in tests",
                ContractLength = 4,
                Continuous     = true,
                Currency       = "SEK",
                Language       = "EN",
                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
                    }
                },
                PeriodStart = "2020-01-01",
                PeriodEnd   = "2020-03-01"
            };

            var createdContract = connector.Create(newContract);
            MyAssert.HasNoError(connector);
            Assert.AreEqual(createdContract.CustomerName, "TmpCustomer");
            Assert.AreEqual(3, createdContract.InvoiceRows.Count);

            #endregion CREATE

            #region UPDATE

            createdContract.Comments = "Updated Comments";

            var updatedContract = connector.Update(createdContract);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("Updated Comments", updatedContract.Comments);

            #endregion UPDATE

            #region READ / GET

            var retrievedContract = connector.Get(createdContract.DocumentNumber);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("Updated Comments", retrievedContract.Comments);

            #endregion READ / GET

            #region DELETE
            //Contract does not provide DELETE method, but can be canceled
            connector.Finish(createdContract.DocumentNumber);
            MyAssert.HasNoError(connector);

            retrievedContract = connector.Get(createdContract.DocumentNumber);
            //Assert.AreEqual(true, retrievedContract.Finished);

            #endregion DELETE

            //Clean
            new CustomerConnector().Delete(tmpCustomer.CustomerNumber);
            new ArticleConnector().Delete(tmpArticle.ArticleNumber);
        }
Пример #13
0
        public void Test_Customer_Search()
        {
            var testId = Guid.NewGuid().ToString(); //serves to identify entities created in this test

            var connector = new CustomerConnector();

            var newCustomers = new List <Customer>()
            {
                new Customer()
                {
                    Name     = testId,
                    Address1 = "TestStreet 1",
                    Address2 = "TestStreet 2",
                    ZipCode  = "01010",
                    City     = "Testopolis",
                    Email    = "*****@*****.**",
                    Type     = CustomerType.PRIVATE,
                    Active   = true
                },
                new Customer()
                {
                    Name     = testId,
                    Address1 = "TestStreet 1",
                    Address2 = "TestStreet 2",
                    ZipCode  = "01010",
                    City     = "TestCity",
                    Email    = "*****@*****.**",
                    Type     = CustomerType.PRIVATE,
                    Active   = true
                },
                new Customer()
                {
                    Name     = testId,
                    Address1 = "TestStreet 1",
                    Address2 = "TestStreet 2",
                    ZipCode  = "01010",
                    City     = "PolisTest",
                    Email    = "*****@*****.**",
                    Type     = CustomerType.PRIVATE,
                    Active   = true
                },
                new Customer()
                {
                    Name     = testId,
                    Address1 = "TestStreet 1",
                    Address2 = "TestStreet 2",
                    ZipCode  = "01010",
                    City     = "Testopolis",
                    Email    = "*****@*****.**",
                    Type     = CustomerType.PRIVATE,
                    Active   = false
                }
            };

            for (int i = 0; i < newCustomers.Count; i++)
            {
                newCustomers[i] = connector.Create(newCustomers[i]);
                MyAssert.HasNoError(connector);
            }

            connector.Limit        = 10;
            connector.LastModified = DateTime.Today;
            connector.SortBy       = Sort.By.Customer.Name;
            connector.Offset       = 0;
            connector.Page         = 1;

            connector.FilterBy = Filter.Customer.Active; //Matched by customers 1,2,3
            connector.City     = "polis";                //Matched by customers 1,3,4
            connector.Name     = testId;                 //Matched by customers 1,2,3,4 (all)

            var retrievedCustomers = connector.Find();

            MyAssert.HasNoError(connector);
            Assert.AreEqual(2, retrievedCustomers.Entities.Count); //Final matched customers: 1,3

            foreach (var customer in newCustomers)
            {
                connector.Delete(customer.CustomerNumber);
                MyAssert.HasNoError(connector);
            }
        }