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.Search.FinancialYearID = 1;

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

            MyAssert.HasNoError(connector);

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

            MyAssert.HasNoError(connector);

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

            MyAssert.HasNoError(connector);
        }
Esempio n. 2
0
        public void Test_TooManyRequests_fixed()
        {
            var connector = new VoucherConnector();

            for (int i = 0; i < 40; i++)
            {
                connector.Limit = 2;
                connector.Find();
                MyAssert.HasNoError(connector);
            }
        }
Esempio n. 3
0
        public void Test_Voucher_CRUD()
        {
            #region Arrange
            #endregion Arrange

            IVoucherConnector connector = new VoucherConnector();

            #region CREATE
            var newVoucher = new Voucher()
            {
                Description     = "TestVoucher",
                Comments        = "Some comments",
                VoucherSeries   = "A", //predefined series
                TransactionDate = new DateTime(2020, 1, 1),
                VoucherRows     = new List <VoucherRow>()
                {
                    new VoucherRow()
                    {
                        Account = 1930, Debit = 1500, Credit = 0
                    },
                    new VoucherRow()
                    {
                        Account = 1910, Debit = 0, Credit = 1500
                    }
                }
            };

            var createdVoucher = connector.Create(newVoucher);
            Assert.AreEqual("TestVoucher", createdVoucher.Description);

            #endregion CREATE

            #region UPDATE
            //Not supported
            #endregion UPDATE

            #region READ / GET
            var retrievedVoucher = connector.Get(createdVoucher.VoucherNumber, createdVoucher.VoucherSeries, createdVoucher.Year);
            Assert.AreEqual("TestVoucher", retrievedVoucher.Description);

            #endregion READ / GET

            #region DELETE
            connector.Delete(createdVoucher.VoucherNumber, createdVoucher.VoucherSeries, createdVoucher.Year);
            Assert.ThrowsException <FortnoxApiException>(
                () => connector.Get(createdVoucher.VoucherNumber, createdVoucher.VoucherSeries, createdVoucher.Year),
                "Entity still exists after Delete!");
            #endregion DELETE

            #region Delete arranged resources
            //Add code to delete temporary resources
            #endregion Delete arranged resources
        }
        public void Test_TooManyRequests_fixed()
        {
            var connector = new VoucherConnector();

            connector.Limit = 2;

            var watch = new Stopwatch();

            watch.Start();
            for (int i = 0; i < 40; i++)
            {
                connector.Find();
                MyAssert.HasNoError(connector);
            }

            watch.Stop();
            Console.WriteLine(@"Total time: " + watch.ElapsedMilliseconds);
        }
Esempio n. 5
0
        public void Test_VoucherFileConnection_CRUD()
        {
            #region Arrange

            var tmpVoucher = new VoucherConnector().Create(new Voucher()
            {
                Description     = "TestVoucher",
                Comments        = "Some comments",
                VoucherSeries   = "A", //predefined series
                TransactionDate = new DateTime(2020, 1, 1),
                VoucherRows     = new List <VoucherRow>()
                {
                    new VoucherRow()
                    {
                        Account = 1930, Debit = 1500, Credit = 0
                    },
                    new VoucherRow()
                    {
                        Account = 1910, Debit = 0, Credit = 1500
                    }
                }
            });
            var tmpFile = new ArchiveConnector().UploadFile("tmpImage.png", Resource.fortnox_image);
            #endregion Arrange

            IVoucherFileConnectionConnector connector = new VoucherFileConnectionConnector();

            #region CREATE
            var newVoucherFileConnection = new VoucherFileConnection()
            {
                FileId        = tmpFile.Id,
                VoucherNumber = tmpVoucher.VoucherNumber.ToString(),
                VoucherSeries = tmpVoucher.VoucherSeries
            };

            var createdVoucherFileConnection = connector.Create(newVoucherFileConnection);
            Assert.AreEqual(tmpVoucher.Description, createdVoucherFileConnection.VoucherDescription);

            #endregion CREATE

            #region UPDATE
            //Not supported
            #endregion UPDATE

            #region READ / GET

            var retrievedVoucherFileConnection = connector.Get(createdVoucherFileConnection.FileId);
            Assert.AreEqual(tmpVoucher.Description, retrievedVoucherFileConnection.VoucherDescription);

            #endregion READ / GET

            #region DELETE

            connector.Delete(createdVoucherFileConnection.FileId);

            Assert.ThrowsException <FortnoxApiException>(
                () => connector.Get(createdVoucherFileConnection.FileId),
                "Entity still exists after Delete!");

            #endregion DELETE

            #region Delete arranged resources
            new ArchiveConnector().DeleteFile(tmpFile.Id);
            #endregion Delete arranged resources
        }
Esempio n. 6
0
        public void Test_Vouchers_Find_By_Series()
        {
            //Arrange
            Thread.Sleep(2);

            var voucher1 = new Voucher()
            {
                Description     = "TestVoucher",
                Comments        = "Some comments",
                VoucherSeries   = "TST", //predefined series
                TransactionDate = new DateTime(2020, 1, 1),
                VoucherRows     = new List <VoucherRow>()
                {
                    new VoucherRow()
                    {
                        Account = 1930, Debit = 1500, Credit = 0
                    },
                    new VoucherRow()
                    {
                        Account = 1910, Debit = 0, Credit = 1500
                    }
                }
            };
            var voucher2 = new Voucher()
            {
                Description     = "TestVoucher",
                Comments        = "Some comments",
                VoucherSeries   = "TST", //predefined series
                TransactionDate = new DateTime(2020, 1, 1),
                VoucherRows     = new List <VoucherRow>()
                {
                    new VoucherRow()
                    {
                        Account = 1930, Debit = 1500, Credit = 0
                    },
                    new VoucherRow()
                    {
                        Account = 1910, Debit = 0, Credit = 1500
                    }
                }
            };
            var voucher3 = new Voucher()
            {
                Description     = "TestVoucher",
                Comments        = "Some comments",
                VoucherSeries   = "A", //predefined series
                TransactionDate = new DateTime(2020, 1, 1),
                VoucherRows     = new List <VoucherRow>()
                {
                    new VoucherRow()
                    {
                        Account = 1930, Debit = 1500, Credit = 0
                    },
                    new VoucherRow()
                    {
                        Account = 1910, Debit = 0, Credit = 1500
                    }
                }
            };

            IVoucherConnector connector = new VoucherConnector();

            voucher1 = connector.Create(voucher1);
            voucher2 = connector.Create(voucher2);
            voucher3 = connector.Create(voucher3);

            //Act
            var settings = new VoucherSearch()
            {
                LastModified  = DateTime.Now.AddSeconds(-2),
                VoucherSeries = "TST"
            };

            //Assert
            var vouchers = connector.Find(settings);

            Assert.AreEqual(2, vouchers.TotalResources);

            //Clean
            connector.Delete(voucher3.VoucherNumber, voucher3.VoucherSeries, voucher3.Year);
            connector.Delete(voucher2.VoucherNumber, voucher2.VoucherSeries, voucher2.Year);
            connector.Delete(voucher1.VoucherNumber, voucher1.VoucherSeries, voucher1.Year);
        }