/// <summary>
        /// Create new instance of the controller
        /// </summary>
        public Controller(IApiConnection conn)
        {
            if (conn == null)
            {
                throw new ArgumentException("Instance of type APIConnection cannot be null");
            }

            // Instantiate the class variables
            _entityControllers = new Hashtable();
            _conn = conn;

            // Set keyname of the entity (name of the field that is used to identify)
            var attributes = Attribute.GetCustomAttributes(typeof(T)).Where(x => x.GetType() == typeof(DataServiceKey)).Select(a => a);             //DataServiceKey

            // Find unique value of entity
            var enumerable = attributes as IList <Attribute> ?? attributes.ToList();

            if (!enumerable.Any())
            {
                throw new Exception("Cannot find 'DataServiceKey' field. This entity cannot be managed by the Controller");
            }
            var key = (DataServiceKey)enumerable.First();

            _keyname = key.DataServiceKeyName;
            _entityControllerDelegate = GetEntityController;
        }
        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();
        }
예제 #3
0
        private readonly string _keyName; // Name of the field that identifies the entity

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Creates an instance of EntityController
        /// </summary>
        /// <param name="entity">An instance of an Entity that must be managed</param>
        /// <param name="keyName">Name of the keyname field of the entity (mostly ID)</param>
        /// <param name="identifier">Name of the identifier field of the entity (mostly ID)</param>
        /// <param name="connection">Instance of IApiConnection to connect to the specific part of the API</param>
        /// <param name="entityControllerDelegate">Delegate that gets the entity controller</param>
        public EntityController(object entity, string keyName, string identifier, IApiConnection connection, GetEntityController entityControllerDelegate)
        {
            _connection = connection;
            _keyName = keyName;
            _identifier = identifier;
            OriginalEntity = Clone(entity);
            _entityControllerDelegate = entityControllerDelegate;
        }
예제 #4
0
 /// <summary>
 /// Creates an instance of EntityController
 /// </summary>
 /// <param name="entity">An instance of an Entity that must be managed</param>
 /// <param name="keyName">Name of the keyname field of the entity (mostly ID)</param>
 /// <param name="identifier">Name of the identifier field of the entity (mostly ID)</param>
 /// <param name="connection">Instance of IApiConnection to connect to the specific part of the API</param>
 /// <param name="entityControllerDelegate">Delegate that gets the entity controller</param>
 public EntityController(object entity, string keyName, string identifier, IApiConnection connection, GetEntityController entityControllerDelegate)
 {
     _connection               = connection;
     _keyName                  = keyName;
     _identifier               = identifier;
     OriginalEntity            = Clone(entity);
     _entityControllerDelegate = entityControllerDelegate;
 }
예제 #5
0
        /// <summary>
        /// Converts an Object to Json for Updating
        /// The method creates Json using the original entity
        /// and the current entity to create Json only for altered fields
        /// </summary>
        /// <typeparam name="T">Type of Exact.Web.Api.Models</typeparam>
        /// <param name="originalEntity">Original State of the Entity</param>
        /// <param name="entity">Current State of the Entity</param>
        /// <param name="entityControllerDelegate">Delegate for entitycontroller</param>
        /// <returns>Json String</returns>
        public string ConvertObjectToJson <T>(T originalEntity, T entity, GetEntityController entityControllerDelegate)
        {
            var converter  = new ExactOnlineJsonConverter(originalEntity, entityControllerDelegate);
            var converters = new JsonConverter[1];

            converters[0] = converter;

            return(JsonConvert.SerializeObject(entity, converters));
        }
 public ExactOnlineJsonConverter(Object originalObject, GetEntityController ecDelegate)
 {
     _entityControllerDelegate = ecDelegate;
     _originalEntity           = originalObject;
     _createUpdateJson         = true;
 }
예제 #7
0
        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();
        }