public void EntityConverter_ConvertJsonToObjectList_WithCorrectInput_Succeeds()
        {
            string         jsonarray = JsonFileReader.GetJsonFromFile("Response_Json_Array_Account.txt");
            List <Account> accounts  = _entityConverter.ConvertJsonArrayToObjectList <Account>(jsonarray);

            if (accounts.Count != 2)
            {
                throw new Exception("The count of the list isn't equal to the actual list");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets specific collection of entities and return a skip token if there are more than
        /// 60 entities to be returned.
        /// </summary>
        /// <param name="query">oData query</param>
        /// <param name="token">The skip token if there are more results than could be retrieved
        /// via the REST API or <code>null</code></param>
        /// <returns>List of entity Objects</returns>
        public List <T> Get(string query, out string token)
        {
            // Get the response and convert it to a list of entities of the specific type
            string response = _conn.Get(query);

            // Search for skip token in json response
            dynamic json = JsonConvert.DeserializeObject(response);

            // This contains the url to the API call for the remaining entities including a skiptoken.
            string next = json["d"].__next;

            // Skiptoken has format "$skiptoken=xyz" in the url and we want to extract xyz.
            var match = Regex.Match(next ?? "", @"\$skiptoken=([^&#]*)");

            // Extract the skip token
            token = match.Success ? match.Groups[1].Value : null;

            // TODO: ApiResponseCleaner should extract Guid
            response = ApiResponseCleaner.GetJsonArray(response);

            var rc       = new EntityConverter();
            var entities = rc.ConvertJsonArrayToObjectList <T>(response);

            // If the entity isn't managed already, register to managed entity collection
            foreach (var entity in entities)
            {
                AddEntityToManagedEntitiesCollection(entity);
            }

            // Convert list
            return(entities.ConvertAll(x => x));
        }
 /// <summary>
 /// Returns the current user data
 /// </summary>
 /// <returns>Me entity</returns>
 public async Task<Me> CurrentMeAsync()
 {
     var conn = new ApiConnection(_apiConnector, _exactOnlineApiUrl + "current/Me");
     string response = await conn.GetAsync("$select=CurrentDivision").ConfigureAwait(false);
     response = ApiResponseCleaner.GetJsonArray(response);
     var converter = new EntityConverter();
     var currentMe = converter.ConvertJsonArrayToObjectList<Me>(response);
     return currentMe.FirstOrDefault();
 }
		/// <summary>
		/// Returns the current user data
		/// </summary>
		/// <returns>Me entity</returns>
		public Me CurrentMe()
		{
			var conn = new ApiConnection(_apiConnector, _exactOnlineApiUrl + "current/Me");
			string response = conn.Get("$select=CurrentDivision");
			response = ApiResponseCleaner.GetJsonArray(response);
			var converter = new EntityConverter();
			var currentMe = converter.ConvertJsonArrayToObjectList<Me>(response);
			return currentMe.FirstOrDefault();
        }
        public void EntityConverter_ConvertLinkedEntityJsonArrayToObjects_Succeeds()
        {
            string json                  = ApiResponseCleaner.GetJsonArray(JsonFileReader.GetJsonFromFile("Response_Json_Array_SalesInvoice_WithLinkedEntities.txt"));
            var    converter             = new EntityConverter();
            List <SalesInvoice> invoices = converter.ConvertJsonArrayToObjectList <SalesInvoice>(json);

            foreach (var invoice in invoices)
            {
                var sil = (List <SalesInvoiceLine>)invoice.SalesInvoiceLines;
                Assert.IsTrue(sil.Count > 0);
            }
        }
Ejemplo n.º 6
0
        private void ParseObjectList()
        {
            var converter = new EntityConverter();

            for (int i = 0; i < 100; i++)
            {
                string         json     = ApiResponseCleaner.GetJsonArray(JsonArray);
                List <Account> accounts = converter.ConvertJsonArrayToObjectList <Account>(json);
                if (accounts.Count != 2)
                {
                    throw new Exception("The count of the list isn't equal to the actual list");
                }
            }
        }
Ejemplo n.º 7
0
        public void ParseObjectList_LinkedEntities()
        {
            var converter = new EntityConverter();

            for (int i = 0; i < 100; i++)
            {
                string json = ApiResponseCleaner.GetJsonArray(LinkedEntities);
                List <SalesInvoice> invoices = converter.ConvertJsonArrayToObjectList <SalesInvoice>(json);

                foreach (var invoice in invoices)
                {
                    var sil = (List <SalesInvoiceLine>)invoice.SalesInvoiceLines;
                    Assert.IsTrue(sil.Count > 0);
                }
            }
        }
        /// <summary>
        /// Gets specific collection of entities and return a skipToken if there are more than
        /// 60 entities to be returned.
        /// </summary>
        /// <param name="query">oData query</param>
        /// <param name="skipToken">The skip token to be used to get the next page of data.</param>
        /// <returns>List of entity Objects</returns>
        public List <T> Get(string query, ref string skipToken)
        {
            // Get the response and convert it to a list of entities of the specific type
            string response = _conn.Get(query);

            skipToken = ApiResponseCleaner.GetSkipToken(response);
            response  = ApiResponseCleaner.GetJsonArray(response);

            var rc       = new EntityConverter();
            var entities = rc.ConvertJsonArrayToObjectList <T>(response);

            // If the entity isn't managed already, register to managed entity collection
            foreach (var entity in entities)
            {
                AddEntityToManagedEntitiesCollection(entity);
            }

            // Convert list
            return(entities.ConvertAll(x => x));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets specific collection of entities and return a skipToken if there are more than
        /// 60 entities to be returned.
        /// </summary>
        /// <param name="query">oData query</param>
        /// <returns>List of entity Objects</returns>
        public async Task <Models.ApiList <T> > GetAsync(string query)
        {
            // Get the response and convert it to a list of entities of the specific type
            string response = await _conn.GetAsync(query).ConfigureAwait(false);

            string skipToken = ApiResponseCleaner.GetSkipToken(response);

            response = ApiResponseCleaner.GetJsonArray(response);

            var rc       = new EntityConverter();
            var entities = rc.ConvertJsonArrayToObjectList <T>(response);

            // If the entity isn't managed already, register to managed entity collection
            foreach (var entity in entities)
            {
                AddEntityToManagedEntitiesCollection(entity);
            }

            // Convert list
            return(new Models.ApiList <T>(entities.ConvertAll(x => x), skipToken));
        }
 public void EntityConverter_ConvertLongJson_Fails()
 {
     var    entityConverter = new EntityConverter();
     string json            = JsonFileReader.GetJsonFromFile("Response_Json_Array_Account_Long.txt");
     var    accounts        = entityConverter.ConvertJsonArrayToObjectList <Account>(json);
 }
Ejemplo n.º 11
0
 public void EntityConverter_ConvertLongJson_Fails()
 {
     var entityConverter = new EntityConverter();
     string json = JsonFileReader.GetJsonFromFile("Response_Json_Array_Account_Long.txt");
     var accounts = entityConverter.ConvertJsonArrayToObjectList<Account>(json);
 }
Ejemplo n.º 12
0
        public void EntityConverter_ConvertLinkedEntityJsonArrayToObjects_Succeeds()
        {
            string json = ApiResponseCleaner.GetJsonArray(JsonFileReader.GetJsonFromFile("Response_Json_Array_SalesInvoice_WithLinkedEntities.txt"));
            var converter = new EntityConverter();
            List<SalesInvoice> invoices = converter.ConvertJsonArrayToObjectList<SalesInvoice>(json);

            foreach (var invoice in invoices)
            {
                var sil = (List<SalesInvoiceLine>)invoice.SalesInvoiceLines;
                Assert.IsTrue(sil.Count > 0);
            }
        }
Ejemplo n.º 13
0
        private void ParseObjectList()
        {
            var converter = new EntityConverter();

            for (int i = 0; i < 100; i++)
            {
                string json = ApiResponseCleaner.GetJsonArray(JsonArray);
                List<Account> accounts = converter.ConvertJsonArrayToObjectList<Account>(json);
                if (accounts.Count != 2)
                {
                    throw new Exception("The count of the list isn't equal to the actual list");
                }
            }
        }
Ejemplo n.º 14
0
        public void ParseObjectList_LinkedEntities()
        {
            var converter = new EntityConverter();

            for (int i = 0; i < 100; i++)
            {
                string json = ApiResponseCleaner.GetJsonArray(LinkedEntities);
                List<SalesInvoice> invoices = converter.ConvertJsonArrayToObjectList<SalesInvoice>(json);

                foreach (var invoice in invoices)
                {
                    var sil = (List<SalesInvoiceLine>)invoice.SalesInvoiceLines;
                    Assert.IsTrue(sil.Count > 0);
                }
            }
        }
		public async Task EntityConverter_ConvertLongJson_Fails()
		{
            // This failed for another reason in the original code, not because it was to long. Not clear to me why this should fail.
            var entityConverter = new EntityConverter();
			string json = JsonFileReader.GetJsonFromFile("Response_Json_Array_Account_Long.txt");
			var accounts = entityConverter.ConvertJsonArrayToObjectList<Account>(await ApiResponseCleaner.GetJsonArrayAsync(json));
		}