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 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);
		}
        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);
		}