public void Test_NoRateLimiter_TooManyRequest_Error() { ConnectionSettings.UseRateLimiter = false; var connector = new CustomerConnector(); ErrorInformation error = null; int i; for (i = 0; i < 200; i++) { connector.Search.City = TestUtils.RandomString(); connector.Find(); if (connector.HasError) { error = connector.Error; break; } } //Restore settings ConnectionSettings.UseRateLimiter = true; //Assert //Assert.IsTrue(failed > 0); Console.WriteLine($@"Succesful requests: {i}"); Assert.IsNotNull(error); Assert.IsTrue(error.Message.Contains("Too Many Requests")); }
public void TestCustomer() { var connector = new CustomerConnector(); connector.AccessToken = at; connector.ClientSecret = cs; var customer = connector.Get("0022"); customer.GLN = "123"; customer.GLNDelivery = "12345"; customer.Active = "false"; customer = connector.Update(customer); Assert.IsFalse(connector.HasError); Assert.IsTrue(customer.Active == "false"); connector.FilterBy = Filter.Customer.Inactive; var customers = connector.Find(); Assert.IsFalse(connector.HasError); Assert.IsTrue(customers.TotalResources == "1"); customer.Active = "true"; connector.Update(customer); Assert.IsFalse(connector.HasError); Assert.IsTrue(customer.Active == "true"); }
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); }
public void Test_NoRateLimiter_TooManyRequest_Error() { var connector = new CustomerConnector(); connector.UseRateLimiter = false; FortnoxApiException error = null; int i; for (i = 0; i < 200; i++) { var searchSettings = new CustomerSearch(); searchSettings.City = TestUtils.RandomString(); try { connector.Find(searchSettings); } catch (FortnoxApiException ex) { error = ex; break; } } //Assert //Assert.IsTrue(failed > 0); Console.WriteLine($@"Succesful requests: {i}"); Assert.IsNotNull(error); Console.WriteLine(error.Message); Assert.IsTrue(error.Message.Contains("Too Many Requests")); Thread.Sleep(5 * 1000); //Sleep to cooldown/recover from "debt" (otherwise following tests will fail with TooManyRequests) }
public void Test_Paging() { const int large = 20; const int small = 5; var connector = new CustomerConnector(); connector.Limit = large; connector.SortBy = Sort.By.Customer.CustomerNumber; connector.SortOrder = Sort.Order.Ascending; var largeCustomerCollection = connector.Find(); //get up to 'large' number of entities var totalCustomers = largeCustomerCollection.TotalResources; var neededPages = GetNeededPages(Math.Min(totalCustomers, large), small); var mergedCollection = new List <CustomerSubset>(); for (int i = 0; i < neededPages; i++) { connector.Limit = small; connector.Page = i + 1; var smallCustomerCollection = connector.Find(); mergedCollection.AddRange(smallCustomerCollection.Entities); } for (int i = 0; i < largeCustomerCollection.Entities.Count; i++) { Assert.AreEqual(largeCustomerCollection.Entities[i].CustomerNumber, mergedCollection[i].CustomerNumber); } }
public void Test_Find_ParamsNullable() { var connector = new CustomerConnector() { Name = "TestName", City = null, FilterBy = null, SortBy = null, SortOrder = null, LastModified = null, Limit = null, Offset = null, Page = null }; connector.Find(); MyAssert.HasNoError(connector); Assert.IsFalse(connector.RequestUriString.Contains("city=")); Assert.IsFalse(connector.RequestUriString.Contains("filter=")); Assert.IsFalse(connector.RequestUriString.Contains("sortby=")); Assert.IsFalse(connector.RequestUriString.Contains("sortorder=")); Assert.IsFalse(connector.RequestUriString.Contains("lastmodified=")); Assert.IsFalse(connector.RequestUriString.Contains("limit=")); Assert.IsFalse(connector.RequestUriString.Contains("offset=")); Assert.IsFalse(connector.RequestUriString.Contains("page=")); }
public void Test_Find_ParamsAdded() { var connector = new CustomerConnector { Name = "TestName", City = "TestCity", FilterBy = Filter.Customer.Active, SortBy = Sort.By.Customer.Name, SortOrder = Sort.Order.Ascending, LastModified = new DateTime(2000, 01, 01, 20, 10, 05), //2000-01-20 20:10:05 Limit = 10, Offset = 0, Page = 1 }; connector.Find(); MyAssert.HasNoError(connector); Assert.IsTrue(connector.RequestUriString.Contains("name=TestName")); Assert.IsTrue(connector.RequestUriString.Contains("city=TestCity")); Assert.IsTrue(connector.RequestUriString.Contains("filter=active")); Assert.IsTrue(connector.RequestUriString.Contains("sortby=name")); Assert.IsTrue(connector.RequestUriString.Contains("sortorder=ascending")); Assert.IsTrue(connector.RequestUriString.Contains("lastmodified=2000-01-01+20%3a10%3a05")); //"lastmodified=2000-01-20 20:10:05" in URL encoding Assert.IsTrue(connector.RequestUriString.Contains("limit=10")); Assert.IsTrue(connector.RequestUriString.Contains("offset=0")); Assert.IsTrue(connector.RequestUriString.Contains("page=1")); }
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); }
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_issue73_async_non_blockable() { var connector = new CustomerConnector(); var searchSettings = new CustomerSearch(); searchSettings.Limit = 2; var watch = new Stopwatch(); watch.Start(); var runningTasks = new List <Task <EntityCollection <CustomerSubset> > >(); for (int i = 0; i < 40; i++) { runningTasks.Add(connector.FindAsync(searchSettings)); } Console.WriteLine(@"Thread free after: " + watch.ElapsedMilliseconds); Assert.IsTrue(watch.ElapsedMilliseconds < 1000); watch.Start(); foreach (var runningTask in runningTasks) { var result = runningTask.GetAwaiter().GetResult(); Assert.IsNotNull(result); } watch.Stop(); Console.WriteLine(@"Total time: " + watch.ElapsedMilliseconds); }
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 }
public void TestCustomer() { var connector = new CustomerConnector(); connector.Authorization = new StaticTokenAuth(at, cs); var customer = connector.Get("0022"); customer.GLN = "123"; customer.GLNDelivery = "12345"; customer.Active = "false"; customer = connector.Update(customer); Assert.IsFalse(connector.HasError); Assert.IsTrue(customer.Active == "false"); connector.FilterBy = Filter.Customer.Inactive; var customers = connector.Find(); Assert.IsFalse(connector.HasError); Assert.IsTrue(customers.CustomerSubset.Any(c => c.CustomerNumber == "0022")); customer.Active = "true"; connector.Update(customer); Assert.IsFalse(connector.HasError); Assert.IsTrue(customer.Active == "true"); customers = connector.Find(); Assert.IsFalse(customers.CustomerSubset.Any(c => c.CustomerNumber == "0022")); }
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_InvoiceWithLabels() { #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 }); #endregion Arrange ILabelConnector labelConnector = new LabelConnector(); var label1 = labelConnector.Create(new Label() { Description = TestUtils.RandomString() }); var label2 = labelConnector.Create(new Label() { Description = TestUtils.RandomString() }); IInvoiceConnector connector = new InvoiceConnector(); 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", InvoiceType = InvoiceType.CashInvoice, PaymentWay = PaymentWay.Cash, Comments = "TestInvoice", InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20, Price = 100 }, new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15, Price = 100 } }, Labels = new List <LabelReference>() { new LabelReference(label1.Id), new LabelReference(label2.Id) } }; var createdInvoice = connector.Create(invoice); Assert.AreEqual(2, createdInvoice.Labels.Count); //Clean connector.Cancel(createdInvoice.DocumentNumber); labelConnector.Delete(label1.Id); labelConnector.Delete(label2.Id); }
public void Test_TaxReductionChanges_2021() { var tmpCustomer = new CustomerConnector().Create(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis" }); var houseworkArticle = new ArticleConnector().Create(new Article() { Description = "TmpArticle", Type = ArticleType.Service, HouseworkType = HouseworkType.SolarCells, Housework = true }); var houseworkInvoice = new InvoiceConnector().Create(new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2021, 1, 20), //"2019-01-20", DueDate = new DateTime(2021, 2, 20), //"2019-02-20", Comments = "TestInvoice", TaxReductionType = TaxReductionType.Green, InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { ArticleNumber = houseworkArticle.ArticleNumber, DeliveredQuantity = 10, HouseWorkHoursToReport = 10, Price = 1000 }, new InvoiceRow() { ArticleNumber = houseworkArticle.ArticleNumber, DeliveredQuantity = 20, HouseWorkHoursToReport = 20, Price = 1000 }, new InvoiceRow() { ArticleNumber = houseworkArticle.ArticleNumber, DeliveredQuantity = 15, HouseWorkHoursToReport = 15, Price = 1000 } } }); Assert.AreEqual(true, houseworkInvoice.HouseWork); Assert.AreEqual(TaxReductionType.Green, houseworkInvoice.TaxReductionType); var createdTaxReduction = new TaxReductionConnector().Create(new TaxReduction() { CustomerName = "TmpCustomer", AskedAmount = 100, SocialSecurityNumber = "760412-0852", ReferenceNumber = houseworkInvoice.DocumentNumber, ReferenceDocumentType = ReferenceDocumentType.Invoice }); Assert.AreEqual(100, createdTaxReduction.AskedAmount); //Check if invoice is still the same var retrievedInvoice = new InvoiceConnector().Get(houseworkInvoice.DocumentNumber); Assert.AreEqual(true, retrievedInvoice.HouseWork); Assert.AreEqual(TaxReductionType.Green, retrievedInvoice.TaxReductionType); }
public void TestConnection1() { var cc = new CustomerConnector(); cc.Authorization = new StaticTokenAuth("", ""); cc.Find(); }
public void TestConnection1() { var cc = new CustomerConnector(); cc.AccessToken = ""; cc.ClientSecret = ""; cc.Find(); }
public void Test_DueDate() { #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 }); #endregion Arrange IInvoiceConnector connector = new InvoiceConnector(); var newInvoice = new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2019, 1, 20), //"2019-01-20", 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); Assert.AreEqual("2019-01-20", createdInvoice.InvoiceDate?.ToString(APIConstants.DateFormat)); Assert.AreEqual("2019-02-19", createdInvoice.DueDate?.ToString(APIConstants.DateFormat)); var newInvoiceDate = new DateTime(2019, 1, 1); var dateChange = newInvoiceDate - newInvoice.InvoiceDate.Value; var newDueDate = createdInvoice.DueDate?.AddDays(dateChange.Days); createdInvoice.InvoiceDate = newInvoiceDate; createdInvoice.DueDate = newDueDate; var updatedInvoice = connector.Update(createdInvoice); Assert.AreEqual("2019-01-01", updatedInvoice.InvoiceDate?.ToString(APIConstants.DateFormat)); Assert.AreEqual("2019-01-31", updatedInvoice.DueDate?.ToString(APIConstants.DateFormat)); connector.Cancel(createdInvoice.DocumentNumber); #region Delete arranged resources new CustomerConnector().Delete(tmpCustomer.CustomerNumber); //new ArticleConnector().Delete(tmpArticle.ArticleNumber); #endregion Delete arranged resources }
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 }
public void Test_Issue98_fixed() // Origins from https://github.com/FortnoxAB/csharp-api-sdk/issues/98 { #region Arrange var tmpCustomer = new CustomerConnector().Create(new Customer() { Name = "TmpCustomer", CountryCode = "SE", City = "Testopolis" }); var tmpArticle = new ArticleConnector().Create(new Article() { Description = "TmpArticle", PurchasePrice = 100 }); #endregion Arrange IInvoiceConnector connector = new InvoiceConnector(); var largeId = (long)2 * int.MaxValue + TestUtils.RandomInt(); var newInvoice = new Invoice() { DocumentNumber = largeId, CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2019, 1, 20), DueDate = new DateTime(2019, 2, 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); Assert.AreEqual(largeId, createdInvoice.DocumentNumber); #region Delete arranged resources new InvoiceConnector().Cancel(createdInvoice.DocumentNumber); new CustomerConnector().Delete(tmpCustomer.CustomerNumber); //new ArticleConnector().Delete(tmpArticle.ArticleNumber); #endregion Delete arranged resources }
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_InvoicePayment_Find() { #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 = 10 }); var invoiceConnector = new InvoiceConnector(); var tmpInvoice = invoiceConnector.Create(new Invoice() { CustomerNumber = tmpCustomer.CustomerNumber, InvoiceDate = new DateTime(2020, 1, 20), DueDate = new DateTime(2020, 6, 20), InvoiceRows = new List <InvoiceRow>() { new InvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 2, Price = 10 }, } }); invoiceConnector.Bookkeep(tmpInvoice.DocumentNumber); #endregion Arrange IInvoicePaymentConnector connector = new InvoicePaymentConnector(); var newInvoicePayment = new InvoicePayment() { InvoiceNumber = tmpInvoice.DocumentNumber, Amount = 10.5m, AmountCurrency = 10.5m, PaymentDate = new DateTime(2020, 2, 1) }; for (var i = 0; i < 5; i++) { connector.Create(newInvoicePayment); MyAssert.HasNoError(connector); } connector.Search.InvoiceNumber = tmpInvoice.DocumentNumber.ToString(); var payments = connector.Find(); Assert.AreEqual(5, payments.Entities.Count); Assert.AreEqual(10.5m, payments.Entities.First().Amount); foreach (var entity in payments.Entities) { connector.Delete(entity.Number); MyAssert.HasNoError(connector); } }
public void Test_Contract_Find() { #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 }); #endregion Arrange IContractConnector connector = new ContractConnector(); var newContract = new Contract() { CustomerNumber = tmpCustomer.CustomerNumber, ContractDate = new DateTime(2019, 1, 20), //"2019-01-20", Active = false, Comments = "TestContract", ContractLength = 4, Continuous = true, Currency = "SEK", Language = Language.English, InvoiceRows = new List <ContractInvoiceRow>() { new ContractInvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 10 }, new ContractInvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 20 }, new ContractInvoiceRow() { ArticleNumber = tmpArticle.ArticleNumber, DeliveredQuantity = 15 } }, PeriodStart = new DateTime(2020, 01, 01), PeriodEnd = new DateTime(2020, 03, 01) }; for (var i = 0; i < 5; i++) { connector.Create(newContract); MyAssert.HasNoError(connector); } connector.Search.CustomerNumber = tmpCustomer.CustomerNumber; var contracts = connector.Find(); Assert.AreEqual(5, contracts.Entities.Count); Assert.AreEqual("INACTIVE", contracts.Entities.First().Status); }
public void TestConnection_NoCredenials_Error() { //Arrange ConnectionCredentials.AccessToken = null; ConnectionCredentials.ClientSecret = null; //Act ICustomerConnector cc = new CustomerConnector(); cc.Find(null); }
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 }
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_FailedUpdate_NoEntity() { var connector = new CustomerConnector(); var createdCustomer = connector.Update(new Customer() { Name = "TestCustomer", CustomerNumber = "NotExistingCustomerNumber" }); Assert.IsNull(createdCustomer); }
public void TestConnection_WrongCredenials_Error() { //Arrange ConnectionCredentials.AccessToken = "ABC"; ConnectionCredentials.ClientSecret = "DEF"; //Act ICustomerConnector cc = new CustomerConnector(); cc.Find(null); }
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); }
public void TestConnection_EmptyCredenials_Error() { //Arrange ConnectionCredentials.AccessToken = ""; ConnectionCredentials.ClientSecret = ""; //Act ICustomerConnector cc = new CustomerConnector(); cc.Find(); Assert.IsTrue(cc.HasError); }