public async Task EntityController_Update_WithNoFieldsAltered_Succeeds() { var controllerMock = new ApiConnectionEntityControllerMock(); var connector = new ApiConnectorMock(); var controllerList = new ControllerList(connector, "https://start.exactonline.nl/api/v1/"); var invoice = new SalesInvoice {Description = "New Description"}; var line = new SalesInvoiceLine {Description = "Invoice Line"}; invoice.SalesInvoiceLines = new List<SalesInvoiceLine> { line }; var controller = (Controller<SalesInvoice>)controllerList.GetController<SalesInvoice>(); var entityController = new EntityController(invoice, "ID", invoice.InvoiceID.ToString(), controllerMock, controller.GetEntityController); var returnValue = controller.AddEntityToManagedEntitiesCollection(invoice); Assert.IsTrue(returnValue); await entityController.UpdateAsync(invoice); string data = controllerMock.Data; Assert.AreEqual("", data); }
public async Task EntityController_Update_WithNewLinkedEntity_Succeeds() { var controllerMock = new ApiConnectionEntityControllerMock(); var apiConnectorMock = new ApiConnectorMock(); var controllerList = new ControllerList(apiConnectorMock, "https://start.exactonline.nl/api/v1/"); var controller = (Controller<SalesInvoice>)controllerList.GetController<SalesInvoice>(); var invoice = new SalesInvoice {Description = "New Description"}; var entityController = new EntityController(invoice, "ID", invoice.InvoiceID.ToString(), controllerMock, controller.GetEntityController); // Change State invoice.Description = "Description2"; var line = new SalesInvoiceLine {Description = "InvoiceLine2"}; invoice.SalesInvoiceLines = new List<SalesInvoiceLine> { line }; await entityController.UpdateAsync(invoice); string data = controllerMock.Data; Assert.IsTrue(data.Contains(@"""Description"":""Description2""")); Assert.IsTrue(data.Contains(@"""Description"":""InvoiceLine2""")); }
public void CreateLinkedEntities() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); // Fetch sales invoice var salesInvoiceId = CreateSalesInvoice(client, 1); var salesinvoice = client.For<SalesInvoice>().GetEntity(salesInvoiceId); // Fetch item var item = client.For<Item>().Top(1).Select("ID").Where("IsSalesItem+eq+true").Get().First(); // add line var invoiceline = new SalesInvoiceLine { Description = "New Sales Invoice Line", InvoiceID = salesinvoice.InvoiceID, Item = item.ID }; Assert.IsTrue(client.For<SalesInvoiceLine>().Insert(ref invoiceline)); }
public async Task EntityController_Update_WithExistingLinkedEntity_Succeeds() { var controllerMock = new ApiConnectionEntityControllerMock(); var connector = new ApiConnectorMock(); var controllerList = new ControllerList(connector, "https://start.exactonline.nl/api/v1/"); var invoice = new SalesInvoice {Description = "New Description"}; var line = new SalesInvoiceLine {Description = "InvoiceLine"}; invoice.SalesInvoiceLines = new List<SalesInvoiceLine> { line }; var controller = (Controller<SalesInvoice>)controllerList.GetController<SalesInvoice>(); var entityController = new EntityController(invoice, "ID", invoice.InvoiceID.ToString(), controllerMock, controller.GetEntityController); Assert.IsTrue(controller.AddEntityToManagedEntitiesCollection(invoice)); // Change State invoice.Description = "Description2"; line.Description = "InvoiceLine2"; await entityController.UpdateAsync(invoice); string data = controllerMock.Data; Assert.AreEqual(@"{""Description"":""Description2"",""SalesInvoiceLines"":[{""Description"":""InvoiceLine2""}]}", data); }
public void CreateSalesInvoiceWithLine() { var toc = new TestObjectsCreator(); var client = new ExactOnlineClient(toc.EndPoint, toc.GetOAuthAuthenticationToken); var customerId = GetCustomerId(client); var itemId = GetItemId(client); var newInvoice = new SalesInvoice { Currency = "EUR", OrderDate = new DateTime(2012, 10, 26), InvoiceTo = customerId, Journal = "70", OrderedBy = customerId, Description = "New invoice for Entity With Collection" }; var newInvoiceLine = new SalesInvoiceLine { Description = "New invoice line for Entity With Collection", Item = itemId }; var invoicelines = new List<SalesInvoiceLine> {newInvoiceLine}; newInvoice.SalesInvoiceLines = invoicelines; // Add SalesInvoice to Database Assert.IsTrue(client.For<SalesInvoice>().Insert(ref newInvoice)); // Get SalesInvoice and check if contains collections of InvoiceLines SalesInvoice salesInvoice = client.For<SalesInvoice>() .Expand("SalesInvoiceLines") .GetEntity(newInvoice.InvoiceID.ToString()); Assert.IsNotNull(salesInvoice); Assert.AreEqual(1, salesInvoice.SalesInvoiceLines.Count()); }
private static EntityController GetEntityController(object o) { // Create Object var newInvoice = new SalesInvoice {InvoiceID = new Guid("4f68481a-7a2c-4fbc-a3a0-0c494df3fa0d")}; var newInvoiceLine = new SalesInvoiceLine {Description = "NewInvoiceForEntityWithCollection"}; newInvoice.SalesInvoiceLines = new List<SalesInvoiceLine> { newInvoiceLine }; var entityController = new EntityController(newInvoice, "ID", "4f68481a-7a2c-4fbc-a3a0-0c494df3fa0d", new MockObjects.ApiConnectionMock(), null); return entityController; }
public void EntityConverter_ConvertExistingLinkedObjectToJson_Succeeds() { // Create Object var newInvoice = new SalesInvoice {InvoiceID = new Guid("4f68481a-7a2c-4fbc-a3a0-0c494df3fa0d")}; var newInvoiceLine = new SalesInvoiceLine {Description = "NewInvoiceForEntityWithCollection"}; newInvoice.SalesInvoiceLines = new List<SalesInvoiceLine> { newInvoiceLine }; //ControllerSingleton.GetInstance(new MockObjects.MAPIConnector_Controller(), "www.dummy.com/"); var entityController = new EntityController(newInvoice, "ID", "4f68481a-7a2c-4fbc-a3a0-0c494df3fa0d", new MockObjects.ApiConnectionMock(), null); newInvoiceLine.Description = "ChangedNewInvoiceForEntityWithCollection"; var entityConverter = new EntityConverter(); var controllerDelegate = new GetEntityController(GetEntityController); string json = entityConverter.ConvertObjectToJson((SalesInvoice)entityController.OriginalEntity, newInvoice, controllerDelegate); const string expected = "{\"SalesInvoiceLines\": [{\"Description\": \"ChangedNewInvoiceForEntityWithCollection\"}]}"; Assert.AreEqual(expected, json); throw new NotImplementedException(); }
public async Task EntityController_Update_WithOnlyLinkedEntityFieldsAltered_Succeeds() { var controllerMock = new ApiConnectionEntityControllerMock(); var connector = new ApiConnectorMock(); var controllerList = new ControllerList(connector, "https://start.exactonline.nl/api/v1/"); var invoice = new SalesInvoice {Description = "New Description"}; var line = new SalesInvoiceLine {Description = "InvoiceLine"}; invoice.SalesInvoiceLines = new List<SalesInvoiceLine> { line }; var controller = (Controller<SalesInvoice>)controllerList.GetController<SalesInvoice>(); var ec = new EntityController(invoice, "ID", invoice.InvoiceID.ToString(), controllerMock, controller.GetEntityController); Assert.IsTrue(controller.AddEntityToManagedEntitiesCollection(invoice)); // Change State line.Description = "InvoiceLine2"; await ec.UpdateAsync(invoice); string result = controllerMock.Data; const string expected = "{\"SalesInvoiceLines\":[{\"Description\":\"InvoiceLine2\"}]}"; Assert.AreEqual(expected, result); }
private static Guid CreateSalesInvoice(ExactOnlineClient client, int numberOfLines) { var item = client.For<Item>().Top(1).Select("ID").Where("IsSalesItem+eq+true").Get().First(); var customer = client.For<Account>().Top(1).Select("ID").Where("IsSales+eq+true").Get().First(); var salesInvoice = new SalesInvoice { OrderedBy = customer.ID, Description = "SDK User level test" }; var salesInvoiceLines = new List<SalesInvoiceLine>(); for (int iterator = 0; iterator < numberOfLines; iterator++) { var salesInvoiceLine = new SalesInvoiceLine { Item = item.ID, Quantity = 1, Description = "Line " + iterator }; salesInvoiceLines.Add(salesInvoiceLine); } salesInvoice.SalesInvoiceLines = salesInvoiceLines; client.For<SalesInvoice>().Insert(ref salesInvoice); return salesInvoice.InvoiceID; }