Esempio n. 1
0
    public async Task Test_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.InvoiceConnector;
        var newInvoice = new Invoice()
        {
            CustomerNumber = tmpCustomer.CustomerNumber,
            InvoiceDate    = new DateTime(2019, 1, 20), //"2019-01-20",
            DueDate        = new DateTime(2019, 2, 20), //"2019-02-20",
            InvoiceType    = InvoiceType.CashInvoice,
            PaymentWay     = PaymentWay.Cash,
            Comments       = "TestInvoice",
            InvoiceRows    = new List <InvoiceRow>()
            {
                new InvoiceRow()
                {
                    ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 10, Price = 100
                },
                new InvoiceRow()
                {
                    ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, Price = 100
                },
                new InvoiceRow()
                {
                    ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, Price = 100
                }
            }
        };

        //Add entries
        for (var i = 0; i < 5; i++)
        {
            await connector.CreateAsync(newInvoice);
        }

        //Apply base test filter
        var searchSettings = new InvoiceSearch();
        searchSettings.CustomerNumber = tmpCustomer.CustomerNumber;
        var fullCollection = await connector.FindAsync(searchSettings);

        Assert.AreEqual(5, fullCollection.TotalResources);
        Assert.AreEqual(5, fullCollection.Entities.Count);
        Assert.AreEqual(1, fullCollection.TotalPages);

        Assert.AreEqual(tmpCustomer.CustomerNumber, fullCollection.Entities.First().CustomerNumber);

        //Apply Limit
        searchSettings.Limit = 2;
        var limitedCollection = await connector.FindAsync(searchSettings);

        Assert.AreEqual(5, limitedCollection.TotalResources);
        Assert.AreEqual(2, limitedCollection.Entities.Count);
        Assert.AreEqual(3, limitedCollection.TotalPages);

        //Delete entries (DELETE not supported)
        foreach (var invoice in fullCollection.Entities)
        {
            await connector.CancelAsync(invoice.DocumentNumber);
        }

        #region Delete arranged resources
        await FortnoxClient.CustomerConnector.DeleteAsync(tmpCustomer.CustomerNumber);

        //FortnoxClient.ArticleConnector.Delete(tmpArticle.ArticleNumber);
        #endregion Delete arranged resources
    }