Exemple #1
0
    public async Task Test_InvoiceAccrual_CRUD()
    {
        #region Arrange
        var tmpCustomer = await FortnoxClient.CustomerConnector.CreateAsync(new Customer()
        {
            Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis"
        });

        var tmpArticle = await FortnoxClient.ArticleConnector.CreateAsync(new Article()
        {
            Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 100
        });

        var tmpInvoice = await FortnoxClient.InvoiceConnector.CreateAsync(new Invoice()
        {
            CustomerNumber = tmpCustomer.CustomerNumber,
            InvoiceDate    = new DateTime(2019, 1, 20), //"2019-01-20",
            DueDate        = new DateTime(2019, 2, 20), //"2019-02-20",
            Comments       = "TestInvoice",
            InvoiceRows    = new List <InvoiceRow>()
            {
                new InvoiceRow()
                {
                    ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 6, Price = 1000
                },
            }
        });

        #endregion Arrange

        var connector = FortnoxClient.InvoiceAccrualConnector;

        #region CREATE
        var newInvoiceAccrual = new InvoiceAccrual()
        {
            Description        = "TestInvoiceAccrual",
            InvoiceNumber      = tmpInvoice.DocumentNumber,
            Period             = "MONTHLY",
            AccrualAccount     = 2990,
            RevenueAccount     = 3990,
            StartDate          = new DateTime(2020, 3, 25),
            EndDate            = new DateTime(2020, 6, 25),
            Total              = 6000,
            InvoiceAccrualRows = new List <InvoiceAccrualRow>()
            {
                new InvoiceAccrualRow()
                {
                    Account = 2990, Credit = 0, Debit = 2000
                },
                new InvoiceAccrualRow()
                {
                    Account = 3990, Credit = 2000, Debit = 0
                }
            }
        };

        var createdInvoiceAccrual = await connector.CreateAsync(newInvoiceAccrual);

        Assert.AreEqual("TestInvoiceAccrual", createdInvoiceAccrual.Description);

        #endregion CREATE

        #region UPDATE

        createdInvoiceAccrual.Description = "UpdatedTestInvoiceAccrual";

        var updatedInvoiceAccrual = await connector.UpdateAsync(createdInvoiceAccrual);

        Assert.AreEqual("UpdatedTestInvoiceAccrual", updatedInvoiceAccrual.Description);

        #endregion UPDATE

        #region READ / GET

        var retrievedInvoiceAccrual = await connector.GetAsync(createdInvoiceAccrual.InvoiceNumber);

        Assert.AreEqual("UpdatedTestInvoiceAccrual", retrievedInvoiceAccrual.Description);

        #endregion READ / GET

        #region DELETE

        await connector.DeleteAsync(createdInvoiceAccrual.InvoiceNumber);

        await Assert.ThrowsExceptionAsync <FortnoxApiException>(
            async() => await connector.GetAsync(createdInvoiceAccrual.InvoiceNumber),
            "Entity still exists after Delete!");

        #endregion DELETE

        #region Delete arranged resources

        await FortnoxClient.InvoiceConnector.CancelAsync(tmpInvoice.DocumentNumber);

        //FortnoxClient.CustomerConnector.Delete(tmpCustomer.CustomerNumber);
        //FortnoxClient.ArticleConnector.Delete(tmpArticle.ArticleNumber);
        #endregion Delete arranged resources
    }
 public async Task <InvoiceAccrual> UpdateAsync(InvoiceAccrual invoiceAccrual)
 {
     return(await BaseUpdate(invoiceAccrual, invoiceAccrual.InvoiceNumber.ToString()).ConfigureAwait(false));
 }
Exemple #3
0
    public async Task Test_InvoiceAccrual_Find()
    {
        #region Arrange
        var tmpCustomer = await FortnoxClient.CustomerConnector.CreateAsync(new Customer()
        {
            Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis"
        });

        var tmpArticle = await FortnoxClient.ArticleConnector.CreateAsync(new Article()
        {
            Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 100
        });

        #endregion Arrange

        var connector = FortnoxClient.InvoiceAccrualConnector;

        var invoice = new Invoice()
        {
            CustomerNumber = tmpCustomer.CustomerNumber,
            InvoiceDate    = new DateTime(2019, 1, 20), //"2019-01-20",
            DueDate        = new DateTime(2019, 2, 20), //"2019-02-20",
            Comments       = "TestInvoice",
            InvoiceRows    = new List <InvoiceRow>()
            {
                new InvoiceRow()
                {
                    ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 6, Price = 1000
                },
            }
        };

        var marks             = TestUtils.RandomString();
        var newInvoiceAccrual = new InvoiceAccrual()
        {
            Description        = marks,
            Period             = "MONTHLY",
            AccrualAccount     = 2990,
            RevenueAccount     = 3990,
            StartDate          = new DateTime(2020, 3, 25),
            EndDate            = new DateTime(2020, 6, 25),
            Total              = 6000,
            InvoiceAccrualRows = new List <InvoiceAccrualRow>()
            {
                new InvoiceAccrualRow()
                {
                    Account = 2990, Credit = 0, Debit = 2000
                },
                new InvoiceAccrualRow()
                {
                    Account = 3990, Credit = 2000, Debit = 0
                }
            }
        };

        for (var i = 0; i < 5; i++)
        {
            var createdInvoice = await FortnoxClient.InvoiceConnector.CreateAsync(invoice);

            newInvoiceAccrual.InvoiceNumber = createdInvoice.DocumentNumber;
            await connector.CreateAsync(newInvoiceAccrual);
        }

        var contractAccruals = await connector.FindAsync(null);

        Assert.AreEqual(5, contractAccruals.Entities.Count(x => x.Description.StartsWith(marks)));

        foreach (var entry in contractAccruals.Entities.Where(x => x.Description.StartsWith(marks)))
        {
            await connector.DeleteAsync(entry.InvoiceNumber);

            await FortnoxClient.InvoiceConnector.CancelAsync(entry.InvoiceNumber);
        }

        #region Delete arranged resources
        //FortnoxClient.ArticleConnector.Delete(tmpArticle.ArticleNumber);
        await FortnoxClient.CustomerConnector.DeleteAsync(tmpCustomer.CustomerNumber);

        #endregion Delete arranged resources
    }
 /// <summary>
 /// Creates a new invoiceAccrual
 /// </summary>
 /// <param name="invoiceAccrual">The invoiceAccrual to create</param>
 /// <returns>The created invoiceAccrual</returns>
 public InvoiceAccrual Create(InvoiceAccrual invoiceAccrual)
 {
     return(CreateAsync(invoiceAccrual).Result);
 }
 public async Task <InvoiceAccrual> CreateAsync(InvoiceAccrual invoiceAccrual)
 {
     return(await BaseCreate(invoiceAccrual).ConfigureAwait(false));
 }
 /// <summary>
 /// Updates a invoiceAccrual
 /// </summary>
 /// <param name="invoiceAccrual">The invoiceAccrual to update</param>
 /// <returns>The updated invoiceAccrual</returns>
 public InvoiceAccrual Update(InvoiceAccrual invoiceAccrual)
 {
     return(UpdateAsync(invoiceAccrual).Result);
 }
Exemple #7
0
        public void Test_InvoiceAccrual_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 = 100
            });

            var tmpInvoice = new InvoiceConnector().Create(new Invoice()
            {
                CustomerNumber = tmpCustomer.CustomerNumber,
                InvoiceDate    = new DateTime(2019, 1, 20), //"2019-01-20",
                DueDate        = new DateTime(2019, 2, 20), //"2019-02-20",
                Comments       = "TestInvoice",
                InvoiceRows    = new List <InvoiceRow>()
                {
                    new InvoiceRow()
                    {
                        ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 6, Price = 1000
                    },
                }
            });
            #endregion Arrange

            IInvoiceAccrualConnector connector = new InvoiceAccrualConnector();

            #region CREATE
            var newInvoiceAccrual = new InvoiceAccrual()
            {
                Description        = "TestInvoiceAccrual",
                InvoiceNumber      = tmpInvoice.DocumentNumber,
                Period             = "MONTHLY",
                AccrualAccount     = 2990,
                RevenueAccount     = 3990,
                StartDate          = new DateTime(2020, 3, 25),
                EndDate            = new DateTime(2020, 6, 25),
                Total              = 6000,
                InvoiceAccrualRows = new List <InvoiceAccrualRow>()
                {
                    new InvoiceAccrualRow()
                    {
                        Account = 2990, Credit = 0, Debit = 2000
                    },
                    new InvoiceAccrualRow()
                    {
                        Account = 3990, Credit = 2000, Debit = 0
                    }
                }
            };

            var createdInvoiceAccrual = connector.Create(newInvoiceAccrual);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("TestInvoiceAccrual", createdInvoiceAccrual.Description);

            #endregion CREATE

            #region UPDATE

            createdInvoiceAccrual.Description = "UpdatedTestInvoiceAccrual";

            var updatedInvoiceAccrual = connector.Update(createdInvoiceAccrual);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("UpdatedTestInvoiceAccrual", updatedInvoiceAccrual.Description);

            #endregion UPDATE

            #region READ / GET

            var retrievedInvoiceAccrual = connector.Get(createdInvoiceAccrual.InvoiceNumber);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("UpdatedTestInvoiceAccrual", retrievedInvoiceAccrual.Description);

            #endregion READ / GET

            #region DELETE

            connector.Delete(createdInvoiceAccrual.InvoiceNumber);
            MyAssert.HasNoError(connector);

            retrievedInvoiceAccrual = connector.Get(createdInvoiceAccrual.InvoiceNumber);
            Assert.AreEqual(null, retrievedInvoiceAccrual, "Entity still exists after Delete!");

            #endregion DELETE

            #region Delete arranged resources
            new CustomerConnector().Delete(tmpCustomer.CustomerNumber);
            new ArticleConnector().Delete(tmpArticle.ArticleNumber);
            #endregion Delete arranged resources
        }
Exemple #8
0
 /// <summary>
 /// Create a new invoice accrual
 /// </summary>
 /// <param name="invoiceAccrual">The invoice accrual to create</param>
 /// <returns>The created invoice accrual</returns>
 public InvoiceAccrual Create(InvoiceAccrual invoiceAccrual)
 {
     return(BaseCreate(invoiceAccrual));
 }
Exemple #9
0
 /// <summary>
 /// Updates an invoice accrual
 /// </summary>
 /// <param name="invoiceAccrual">The invoice accrual to update</param>
 /// <returns>The updated invoice accrual</returns>
 public InvoiceAccrual Update(InvoiceAccrual invoiceAccrual)
 {
     return(BaseUpdate(invoiceAccrual, invoiceAccrual.InvoiceNumber));
 }
Exemple #10
0
 public async Task <InvoiceAccrual> CreateAsync(InvoiceAccrual invoiceAccrual)
 {
     return(await BaseCreate(invoiceAccrual));
 }