public void Test_Customer_Update_UndefinedProperties()
        {
            var connector = new CustomerConnector();

            //Arrange - Create customer
            var existingCustomer = connector.Create(new Customer()
            {
                Name     = "TestCustomer",
                Address1 = "TestStreet 1",
                Type     = CustomerType.PRIVATE,
                VATType  = VATType.EUVAT
            });

            MyAssert.HasNoError(connector);

            //Act - Update customer
            var updatedCustomerData = new Customer()
            {
                CustomerNumber = existingCustomer.CustomerNumber,
                Address1       = "Updated Address"
            };

            var updatedCustomer = connector.Update(updatedCustomerData);

            MyAssert.HasNoError(connector);
            Assert.AreEqual("Updated Address", updatedCustomer.Address1);
            Assert.AreEqual("TestCustomer", updatedCustomer.Name);
            Assert.AreEqual(CustomerType.PRIVATE, updatedCustomer.Type);
            Assert.AreEqual(VATType.EUVAT, updatedCustomer.VATType);

            //Clean
            connector.Delete(existingCustomer.CustomerNumber);
            MyAssert.HasNoError(connector);
        }
Exemple #2
0
        public void Test_Issue_44() // Origins from https://github.com/FortnoxAB/csharp-api-sdk/issues/44
        {
            //Arrange
            var customerConnector = new CustomerConnector();
            var tmpCustomer       = customerConnector.Create(new Customer()
            {
                Name = "TmpTestCustomer"
            });

            IInvoiceConnector connector = new InvoiceConnector();

            var newInvoce = connector.Create(new Invoice()
            {
                InvoiceDate    = new DateTime(2019, 1, 20), //"2019-01-20",
                DueDate        = new DateTime(2019, 2, 20), //"2019-02-20",
                CustomerNumber = tmpCustomer.CustomerNumber,
                InvoiceType    = InvoiceType.Invoice,
                InvoiceRows    = new List <InvoiceRow>()
                {                     //Add Empty rows
                    new InvoiceRow(), //Empty Row
                    new InvoiceRow(), //Empty Row
                    new InvoiceRow()
                    {
                        AccountNumber = 0000
                    },
                    new InvoiceRow(), //Empty Row
                }
            });
        }
        public void Test_Issue95_fixed() //Origins from https://github.com/FortnoxAB/csharp-api-sdk/issues/95
        {
            //Arrange
            //Creates a customer with ElectronicInvoice option for deliviery type
            var connector   = new CustomerConnector();
            var tmpCustomer = connector.Create(new Customer()
            {
                Name = "TestCustomer",
                DefaultDeliveryTypes = new DefaultDeliveryTypes()
                {
                    Invoice = DefaultDeliveryType.ElectronicInvoice
                }
            });

            MyAssert.HasNoError(connector);

            //Act && Assert
            var customer = connector.Get(tmpCustomer.CustomerNumber);

            MyAssert.HasNoError(connector);
            Assert.AreEqual(DefaultDeliveryType.ElectronicInvoice, customer.DefaultDeliveryTypes.Invoice);

            //Clean
            connector.Delete(tmpCustomer.CustomerNumber);
            MyAssert.HasNoError(connector);
        }
Exemple #4
0
        public void Test_Issue_44() // Origins from https://github.com/FortnoxAB/csharp-api-sdk/issues/44
        {
            //Arrange
            var customerConnector = new CustomerConnector();
            var tmpCustomer       = customerConnector.Create(new Customer()
            {
                Name = "TmpTestCustomer"
            });

            var connector = new InvoiceConnector();

            var newInvoce = connector.Create(new Invoice()
            {
                InvoiceDate    = new DateTime(2019, 1, 20).ToString(APIConstants.DateFormat), //"2019-01-20",
                DueDate        = new DateTime(2019, 2, 20).ToString(APIConstants.DateFormat), //"2019-02-20",
                CustomerNumber = tmpCustomer.CustomerNumber,
                InvoiceType    = InvoiceType.INVOICE,
                InvoiceRows    = new List <InvoiceRow>()
                {                     //Add Empty rows
                    new InvoiceRow(), //Empty Row
                    new InvoiceRow(), //Empty Row
                    new InvoiceRow()
                    {
                        AccountNumber = "0000"
                    },
                    new InvoiceRow(), //Empty Row
                }
            });

            MyAssert.HasNoError(connector);
        }
Exemple #5
0
        public void Test_Customer_CRUD()
        {
            #region Arrange
            //Add code to create required resources
            #endregion Arrange

            ICustomerConnector connector = new CustomerConnector();

            #region CREATE
            var newCustomer = new Customer()
            {
                Name        = "TestCustomer",
                Address1    = "TestStreet 1",
                Address2    = "TestStreet 2",
                ZipCode     = "01010",
                City        = "Testopolis",
                CountryCode = "SE", //CountryCode needs to be valid
                Email       = "*****@*****.**",
                Type        = CustomerType.Private,
                Active      = false
            };

            var createdCustomer = connector.Create(newCustomer);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("TestCustomer", createdCustomer.Name);

            #endregion CREATE

            #region UPDATE

            createdCustomer.Name = "UpdatedTestCustomer";

            var updatedCustomer = connector.Update(createdCustomer);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("UpdatedTestCustomer", updatedCustomer.Name);

            #endregion UPDATE

            #region READ / GET

            var retrievedCustomer = connector.Get(createdCustomer.CustomerNumber);
            MyAssert.HasNoError(connector);
            Assert.AreEqual("UpdatedTestCustomer", retrievedCustomer.Name);

            #endregion READ / GET

            #region DELETE

            connector.Delete(createdCustomer.CustomerNumber);
            MyAssert.HasNoError(connector);

            retrievedCustomer = connector.Get(createdCustomer.CustomerNumber);
            Assert.AreEqual(null, retrievedCustomer, "Entity still exists after Delete!");

            #endregion DELETE

            #region Delete arranged resources
            //Add code to delete temporary resources
            #endregion Delete arranged resources
        }
Exemple #6
0
        public void Test_Find()
        {
            #region Arrange
            //Add code to create required resources
            #endregion Arrange

            var testKeyMark = TestUtils.RandomString();

            ICustomerConnector connector = new CustomerConnector();
            var newCustomer = new Customer()
            {
                Name        = "TestCustomer",
                Address1    = "TestStreet 1",
                Address2    = "TestStreet 2",
                ZipCode     = "01010",
                City        = testKeyMark,
                CountryCode = "SE", //CountryCode needs to be valid
                Email       = "*****@*****.**",
                Type        = CustomerType.Private,
                Active      = false,
                Comments    = testKeyMark
            };

            //Add entries
            for (var i = 0; i < 5; i++)
            {
                connector.Create(newCustomer);
            }

            //Apply base test filter
            connector.Search.City = testKeyMark;
            var fullCollection = connector.Find();
            MyAssert.HasNoError(connector);

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

            //Apply Limit
            connector.Search.Limit = 2;
            var limitedCollection = connector.Find();
            MyAssert.HasNoError(connector);

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

            //Delete entries
            foreach (var entry in fullCollection.Entities)
            {
                connector.Delete(entry.CustomerNumber);
            }

            #region Delete arranged resources
            //Add code to delete temporary resources
            #endregion Delete arranged resources
        }
Exemple #7
0
        public void Test_Email()
        {
            #region Arrange
            var cc          = new CustomerConnector();
            var ac          = new ArticleConnector();
            var tmpCustomer = cc.Create(new Customer()
            {
                Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis", Email = "*****@*****.**"
            });
            var tmpArticle = ac.Create(new Article()
            {
                Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 100
            });
            MyAssert.HasNoError(cc);
            MyAssert.HasNoError(ac);
            #endregion Arrange

            IInvoiceConnector connector = new 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       = "Testing invoice email feature",
                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
                    }
                }
            };

            var createdInvoice = connector.Create(newInvoice);
            MyAssert.HasNoError(connector);

            var emailedInvoice = connector.Email(createdInvoice.DocumentNumber);
            MyAssert.HasNoError(connector);
            Assert.AreEqual(emailedInvoice.DocumentNumber, createdInvoice.DocumentNumber);

            #region Delete arranged resources
            new CustomerConnector().Delete(tmpCustomer.CustomerNumber);
            new ArticleConnector().Delete(tmpArticle.ArticleNumber);
            #endregion Delete arranged resources
        }
        public void Test_FailedCreate_NoEntity()
        {
            var connector = new CustomerConnector();

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

            Assert.IsNull(createdCustomer);
        }
        public void Test_Print()
        {
            #region Arrange
            var cc          = new CustomerConnector();
            var ac          = new ArticleConnector();
            var tmpCustomer = cc.Create(new Customer()
            {
                Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis"
            });
            var tmpArticle = ac.Create(new Article()
            {
                Description = "TmpArticle", Type = ArticleType.Stock, PurchasePrice = 100
            });
            #endregion Arrange

            IInvoiceConnector connector = new 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
                    }
                }
            };

            var createdInvoice = connector.Create(newInvoice);

            var fileData = connector.Print(createdInvoice.DocumentNumber);
            MyAssert.IsPDF(fileData);

            connector.Cancel(createdInvoice.DocumentNumber);

            #region Delete arranged resources
            new CustomerConnector().Delete(tmpCustomer.CustomerNumber);
            //new ArticleConnector().Delete(tmpArticle.ArticleNumber);
            #endregion Delete arranged resources
        }
Exemple #10
0
        public void Test_EmptyNestedObject()
        {
            ICustomerConnector connector = new CustomerConnector();

            var createdCustomer = connector.Create(new Customer()
            {
                Name = "TestUser",
                DefaultDeliveryTypes = new DefaultDeliveryTypes() //Empty Object
            });

            connector.Delete(createdCustomer.CustomerNumber);
        }
Exemple #11
0
        public void Test_ReadOnlyProperty_Deserialized()
        {
            ICustomerConnector connector = new CustomerConnector();

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

            Assert.AreEqual("Sverige", createdCustomer.Country);

            connector.Delete(createdCustomer.CustomerNumber);
        }
        public void Test_EmptyNestedObject()
        {
            var connector = new CustomerConnector();

            var createdCustomer = connector.Create(new Customer()
            {
                Name = "TestUser",
                DefaultDeliveryTypes = new InvoiceDefaultDeliveryTypes() //Empty Object
            });

            MyAssert.HasNoError(connector);

            connector.Delete(createdCustomer.CustomerNumber);
            MyAssert.HasNoError(connector);
        }
Exemple #13
0
        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
            });

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

            Assert.AreEqual(CustomerType.Company, updatedCustomer.Type);

            connector.Delete(newCustomer.CustomerNumber);
        }
Exemple #14
0
        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"
            });

            var searchSettings = new CustomerSearch();

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

            Assert.IsNotNull(customer);

            connector.Delete(specificCustomer.CustomerNumber);
        }
        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_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);
            }
        }