Exemplo n.º 1
0
        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);
        }
        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);
        }
Exemplo n.º 3
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
        }
Exemplo n.º 4
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
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
            }
        }