public async Task TestPutItemUpdate() { using (var linksContext = new LinksContext(linksOptions)) { IActionResult result = await PutLinkCombination(); // filter the customerLinks by the new ID. There should only be one // (if more than one an exception will be thrown and test will fail) CustomerLink customer = linksContext.CustomerLink.Where(x => x.NewID == newIDs[1]).Single(); // filter the customerLinks by the old ID. There should only be one CustomerLink sameCustomer = linksContext.CustomerLink.Where(x => x.OldID == oldIDs[1]).Single(); // They should be the same now (the PUT combines them) Assert.AreSame(customer, sameCustomer); } }
//[TestMethod] //public async Task TestRegularGetCorrectContent() //{ //} //[TestMethod] //public async Task TestFilteredGet() //{ //} //[TestMethod] //public async Task TestPostCorrectResult() //{ //} //[TestMethod] //public async Task TestPostItemAdd() //{ //} /* Perform a PUT linking two customers */ private async Task <IActionResult> PutLinkCombination() { IActionResult result = null; using (var linksContext = new LinksContext(linksOptions)) { CustomerLink customer1 = linksContext.CustomerLink.Where(x => x.NewID == newIDs[1]).Single(); customer1.OldID = oldIDs[1]; NewCustomersContext newContext = new NewCustomersContext(newCOptions); OldCustomersContext oldContext = new OldCustomersContext(oldCOptions); CustomerLinksController linksController = new CustomerLinksController(linksContext, newContext, oldContext); result = await linksController.PutCombinedLink(customer1.ID, GetFullLinkFromContexts(customer1)) as IActionResult; newContext.Dispose(); oldContext.Dispose(); } return(result); }
public static CustomerLink MakeCustomerLink(MYOBCustomer customer) { var c = new CustomerLink { DisplayID = customer.DisplayID, Name = customer.CompanyName, UID = customer.Uid, URI = new Uri(customer.URI) }; if (c.UID == null) { throw new Exception($"UID not set for customer {customer.DisplayID}"); } if (c.URI == null) { throw new Exception($"URI not set for {customer.DisplayID} "); } return(c); }
/* This method packages the data from the different contexts into one combined object */ private CombinedLink GetFullLinkFromContexts(CustomerLink bareCustomerLink) { NewCustomer newCustomerData = null; using (NewCustomersContext newContext = new NewCustomersContext(newCOptions)) { if (bareCustomerLink.NewID != "") { IQueryable <NewCustomer> filteredContext = newContext.NewCustomer.Where(x => x.Id == bareCustomerLink.NewID); if (filteredContext.Count() == 1) { newCustomerData = filteredContext.Single(); } } } OldCustomer oldCustomerData = null; using (OldCustomersContext oldContext = new OldCustomersContext(oldCOptions)) { if (bareCustomerLink.OldID != -1) { IQueryable <OldCustomer> filteredContext = oldContext.OldCustomer.Where(x => x.Id == bareCustomerLink.OldID); if (filteredContext.Count() == 1) { oldCustomerData = filteredContext.Single(); } } } CombinedLink fullLink = new CombinedLink { Link = bareCustomerLink, OldC = oldCustomerData, NewC = newCustomerData }; return(fullLink); }
private CombinedLink GetFullLinkFromContexts(CustomerLink bareCustomerLink) { NewCustomer newCustomerData = null; if (bareCustomerLink.NewID != "") { IQueryable <NewCustomer> filteredContext = _newContext.NewCustomer.Where(x => x.Id == bareCustomerLink.NewID); if (filteredContext.Count() == 1) { newCustomerData = filteredContext.Single(); } } OldCustomer oldCustomerData = null; if (bareCustomerLink.OldID != -1) { IQueryable <OldCustomer> filteredContext = _oldContext.OldCustomer.Where(x => x.Id == bareCustomerLink.OldID); if (filteredContext.Count() == 1) { oldCustomerData = filteredContext.Single(); } } System.Diagnostics.Debug.WriteLine("Id: " /*+ oldCustomerData.Id*/); CombinedLink fullLink = new CombinedLink { Link = bareCustomerLink, OldC = oldCustomerData, NewC = newCustomerData }; return(fullLink); }
public void SetupDb() { using (var context = new OldCustomersContext(oldCOptions)) { OldCustomer customer0a = new OldCustomer() { Id = oldIDs[0], Username = "******", FirstName = "Elon", Surname = "Musk", Address = "Los Angeles", }; OldCustomer customer1a = new OldCustomer() { Id = oldIDs[1], Username = "******", FirstName = "Jimmy", Surname = "Whales", Address = "San Francisco" }; context.OldCustomer.Add(customer0a); context.OldCustomer.Add(customer1a); context.SaveChanges(); } using (var context = new NewCustomersContext(newCOptions)) { NewCustomer customer0b = new NewCustomer() { Id = newIDs[0], Username = "******", GivenNames = { "Elon", "Reeve", "Musk" }, Email = "*****@*****.**" }; NewCustomer customer1b = new NewCustomer() { Id = newIDs[1], Username = "******", GivenNames = { "Jimmy", "Whales" }, Email = "*****@*****.**" }; context.NewCustomer.Add(customer0b); context.NewCustomer.Add(customer1b); context.SaveChanges(); } using (var context = new LinksContext(linksOptions)) { CustomerLink customer0 = new CustomerLink() { OldID = oldIDs[0], NewID = newIDs[0] }; CustomerLink customer1a = new CustomerLink() { OldID = oldIDs[1] }; CustomerLink customer1b = new CustomerLink() { NewID = newIDs[1] }; context.CustomerLink.Add(customer0); context.CustomerLink.Add(customer1a); context.CustomerLink.Add(customer1b); context.SaveChanges(); } }
public void TestRegularGetCorrectResult() { using (var linksContext = new LinksContext(linksOptions)) { CustomerLink customerLink0 = linksContext.CustomerLink.Where(x => x.NewID == newIDs[0]).Single(); CustomerLink customerLink1a = linksContext.CustomerLink.Where(x => x.OldID == oldIDs[1]).Single(); CustomerLink customerLink1b = linksContext.CustomerLink.Where(x => x.NewID == newIDs[1]).Single(); CombinedLink customerData0 = GetFullLinkFromContexts(customerLink0); CombinedLink customerData1a = GetFullLinkFromContexts(customerLink1a); CombinedLink customerData1b = GetFullLinkFromContexts(customerLink1b); NewCustomersContext newContext = new NewCustomersContext(newCOptions); OldCustomersContext oldContext = new OldCustomersContext(oldCOptions); CustomerLinksController linksController = new CustomerLinksController(linksContext, newContext, oldContext); IEnumerable <CombinedLink> customers = linksController.GetCombinedLink(); newContext.Dispose(); oldContext.Dispose(); bool[] foundCustomer = new bool[3]; foundCustomer[0] = false; foundCustomer[1] = false; foundCustomer[2] = false; System.Console.WriteLine("Looking for customers..."); System.Diagnostics.Debug.WriteLine("Looking for customers..."); foreach (CombinedLink customer in customers) { System.Diagnostics.Debug.WriteLine("Customer found:"); System.Console.WriteLine("Customer found"); if (customer.Equals(customerData0)) { foundCustomer[0] = true; } else if (customer.Equals(customerData1a)) { foundCustomer[1] = true; } else if (customer.Equals(customerData1b)) { foundCustomer[2] = true; } } if (!foundCustomer[0]) { Assert.Fail("There was no data for Elon Musk"); } if (!foundCustomer[1]) { Assert.Fail("There was no old data for Jimmy Wales"); } if (!foundCustomer[2]) { Assert.Fail("There was no new data for Jimmy Wales"); } if (customers.Count() != 3) { Assert.Fail("There were more than 3 customer links"); } }; }
private void BtnRecordClick(Object sender, EventArgs e) { var serviceInvoiceSvc = new ServiceInvoiceService(MyConfiguration, null, MyOAuthKeyService); var serviceInvoice = new ServiceInvoice(); if ((_invoice == null)) { var customerLnk = new CustomerLink {UID = (Guid) CmboCustomer.SelectedValue}; serviceInvoice.Customer = customerLnk; serviceInvoice.ShipToAddress = TxtAddress.Text; serviceInvoice.Number = TxtInvoiceNo.Text; serviceInvoice.Date = DtDate.Value; serviceInvoice.IsTaxInclusive = ChkTaxInclusive.Checked; var lines = new List<ServiceInvoiceLine>(); foreach (DataGridViewRow row in GrdServiceLines.Rows) { if (!row.IsNewRow) { var line = new ServiceInvoiceLine { Type = InvoiceLineType.Transaction, Description = (string) row.Cells["ColDescription"].Value, Total = Convert.ToDecimal(row.Cells["ColAmount"].Value) }; if ((row.Cells["ColAccount"].Value == null)) { MessageBox.Show("you must select an account on each row"); return; } var accountlnk = new AccountLink {UID = (Guid) row.Cells["ColAccount"].Value}; line.Account = accountlnk; if ((row.Cells["ColTax"].Value == null)) { MessageBox.Show("you must select a taxcode on each row"); return; } var taxcodelnk = new TaxCodeLink {UID = (Guid) row.Cells["ColTax"].Value}; line.TaxCode = taxcodelnk; if ((row.Cells["ColJob"].Value != null)) { var joblnk = new JobLink {UID = (Guid) row.Cells["ColJob"].Value}; line.Job = joblnk; } lines.Add(line); } } serviceInvoice.Lines = lines; serviceInvoiceSvc.Insert(MyCompanyFile, serviceInvoice, MyCredentials, OnSaveComplete, OnError); ShowSpinner(); } }
private void BtnRecordClick(Object sender, EventArgs e) { var serviceInvoiceSvc = new ServiceInvoiceService(MyConfiguration, null, MyOAuthKeyService); var serviceInvoice = new ServiceInvoice(); if ((_invoice == null)) { var customerLnk = new CustomerLink { UID = (Guid)CmboCustomer.SelectedValue }; serviceInvoice.Customer = customerLnk; serviceInvoice.ShipToAddress = TxtAddress.Text; serviceInvoice.Number = TxtInvoiceNo.Text; serviceInvoice.Date = DtDate.Value; serviceInvoice.IsTaxInclusive = ChkTaxInclusive.Checked; var lines = new List <ServiceInvoiceLine>(); foreach (DataGridViewRow row in GrdServiceLines.Rows) { if (!row.IsNewRow) { var line = new ServiceInvoiceLine { Type = InvoiceLineType.Transaction, Description = (string)row.Cells["ColDescription"].Value, Total = Convert.ToDecimal(row.Cells["ColAmount"].Value) }; if ((row.Cells["ColAccount"].Value == null)) { MessageBox.Show("you must select an account on each row"); return; } var accountlnk = new AccountLink { UID = (Guid)row.Cells["ColAccount"].Value }; line.Account = accountlnk; if ((row.Cells["ColTax"].Value == null)) { MessageBox.Show("you must select a taxcode on each row"); return; } var taxcodelnk = new TaxCodeLink { UID = (Guid)row.Cells["ColTax"].Value }; line.TaxCode = taxcodelnk; if ((row.Cells["ColJob"].Value != null)) { var joblnk = new JobLink { UID = (Guid)row.Cells["ColJob"].Value }; line.Job = joblnk; } lines.Add(line); } } serviceInvoice.Lines = lines; serviceInvoiceSvc.Insert(MyCompanyFile, serviceInvoice, MyCredentials, OnSaveComplete, OnError); ShowSpinner(); } }
private void createinvoice() { var serviceInvoiceSvc = new ServiceInvoiceService(configuration, null, MyOAuthKeyService); var serviceInvoice = new ServiceInvoice(); if ((_invoice == null)) { var customerLnk = new CustomerLink { UID = (Guid)CmboCustomer.SelectedValue }; serviceInvoice.Customer = customerLnk; serviceInvoice.Date = DateTime.Parse; serviceInvoice.IsTaxInclusive = ChkTaxInclusive.Checked; var lines = new List <ServiceInvoiceLine>(); foreach (GridView1 row in GrdServiceLines.Rows) { if (!row.IsNewRow) { var line = new ServiceInvoiceLine { Type = InvoiceLineType.Transaction, Description = (string)row.Cells["ColDescription"].Value, Total = Convert.ToDecimal(row.Cells["ColAmount"].Value) }; if ((row.Cells["ColAccount"].Value == null)) { MessageBox.Show("you must select an account on each row"); return; } var accountlnk = new AccountLink { UID = (Guid)row.Cells["ColAccount"].Value }; line.Account = accountlnk; if ((row.Cells["ColTax"].Value == null)) { MessageBox.Show("you must select a taxcode on each row"); return; } var taxcodelnk = new TaxCodeLink { UID = (Guid)row.Cells["ColTax"].Value }; line.TaxCode = taxcodelnk; if ((row.Cells["ColJob"].Value != null)) { var joblnk = new JobLink { UID = (Guid)row.Cells["ColJob"].Value }; line.Job = joblnk; } lines.Add(line); } } } }