public void ApiResponseCleaner_FetchJsonObject_WithEscapeCharacter_Succeeds() { const string sampleJsonResponse = @"{ ""d"": { ""Remarks"": ""\\escape test"" }}"; var cleanedJson = ApiResponseCleaner.GetJsonObject(sampleJsonResponse); const string expectedCleanedJson = @"{""Remarks"":""\\escape test""}"; Assert.AreEqual(expectedCleanedJson, cleanedJson); }
public void EntityConverter_ConvertLinkedEntityJsonToObject_Succeeds() { string json = ApiResponseCleaner.GetJsonObject(JsonFileReader.GetJsonFromFile("Response_Json_Object_SalesInvoice.txt")); var converter = new EntityConverter(); var invoice = converter.ConvertJsonToObject <SalesInvoice>(json); var lines = (List <SalesInvoiceLine>)invoice.SalesInvoiceLines; Assert.IsNotNull(invoice); Assert.IsTrue(lines.Count > 0); }
/// <summary> /// Get entity using specific GUID /// </summary> /// <param name="guid">Global Unique Identifier of the entity</param> /// <param name="parameters">parameters</param> /// <returns>Entity if exists. Null if entity not exists.</returns> public T GetEntity(string guid, string parameters) { if (guid.Contains('}') || guid.Contains('{')) { throw new Exception("Bad Guid: Guid cannot contain '}' or '{'"); } // Convert the resonse to an object of the specific type var response = _conn.GetEntity(_keyname, guid, parameters); response = ApiResponseCleaner.GetJsonObject(response); var ec = new EntityConverter(); var entity = ec.ConvertJsonToObject <T>(response); // If entity isn't managed already, add entity to EntityController AddEntityToManagedEntitiesCollection(entity); return(entity); }
public void EntityConverter_ConvertJsonToDynamicObject_WithCorrectJson_Succeeds() { string jsonsresponse = JsonFileReader.GetJsonFromFile("Response_Json_Object_GLAccount.txt"); string json = ApiResponseCleaner.GetJsonObject(jsonsresponse); dynamic glaccountObject = _entityConverter.ConvertJsonToDynamicObject(json); Assert.AreEqual("D", (string)glaccountObject.BalanceSide); Assert.AreEqual("W", (string)glaccountObject.BalanceType); Assert.AreEqual("4406", (string)glaccountObject.Code); Assert.AreEqual(false, (Boolean)glaccountObject.Compress); Assert.AreEqual(null, (string)glaccountObject.Costcenter); Assert.AreEqual(null, (string)glaccountObject.CostcenterDescription); Assert.AreEqual("10/25/2013 02:24:29", (string)glaccountObject.Created); Assert.AreEqual("99d87844-e4ef-4ac5-968c-fb863eaced16", (string)glaccountObject.Creator); Assert.AreEqual(null, (string)glaccountObject.CreatorFullName); Assert.AreEqual("Test", (string)glaccountObject.Description); Assert.AreEqual("499156", (string)glaccountObject.Division); Assert.AreEqual("0", (string)glaccountObject.ExcludeVATListing); Assert.AreEqual("0", (string)glaccountObject.ExpenseNonDeductiblePercentage); Assert.AreEqual("3c534e79-c4fe-44d2-9765-00b30573c2de", (string)glaccountObject.ID); Assert.AreEqual(false, (Boolean)glaccountObject.IsBlocked); Assert.AreEqual(false, (Boolean)glaccountObject.Matching); Assert.AreEqual("12/02/2013 13:44:27", (string)glaccountObject.Modified); Assert.AreEqual("10091f1b-4661-4854-9fd0-cf5f5f668cbd", (string)glaccountObject.Modifier); Assert.AreEqual("Edward Jackson", (string)glaccountObject.ModifierFullName); Assert.AreEqual(null, (string)glaccountObject.PrivateGLAccount); Assert.AreEqual("0", (string)glaccountObject.PrivatePercentage); Assert.AreEqual(null, (string)glaccountObject.ReportingCode); Assert.AreEqual(false, (Boolean)glaccountObject.RevalueCurrency); Assert.AreEqual("RENTE ", (string)glaccountObject.SearchCode); Assert.AreEqual("120", (string)glaccountObject.Type); Assert.AreEqual("Other costs", (string)glaccountObject.TypeDescription); Assert.AreEqual("0", (string)glaccountObject.UseCostcenter); Assert.AreEqual("0", (string)glaccountObject.UseCostunit); Assert.AreEqual(null, (string)glaccountObject.VATCode); Assert.AreEqual(null, (string)glaccountObject.VATDescription); Assert.AreEqual(null, (string)glaccountObject.VATGLAccountType); Assert.AreEqual(null, (string)glaccountObject.VATNonDeductibleGLAccount); Assert.AreEqual("0", (string)glaccountObject.VATNonDeductiblePercentage); Assert.AreEqual(null, (string)glaccountObject.YearEndCostGLAccount); Assert.AreEqual(null, (string)glaccountObject.YearEndReflectionGLAccount); }
/// <summary> /// Creates an entity in Exact Online /// </summary> /// <param name="entity">Entity to create</param> /// <returns>True if succeed</returns> public Boolean Create(ref T entity) { var supportedActions = GetSupportedActions(entity); if (!supportedActions.CanCreate) { throw new Exception("Cannot create entity. Entity does not support creation. Please see the Reference Documentation."); } // Get Json code var created = false; var converter = new EntityConverter(); var emptyEntity = Activator.CreateInstance <T>(); var json = converter.ConvertObjectToJson(emptyEntity, entity, _entityControllerDelegate); // Send to API var response = _conn.Post(json); if (!response.Contains("error")) { created = true; // Set values of API in account entity (to ensure GUID is set) response = ApiResponseCleaner.GetJsonObject(response); var ec = new EntityConverter(); entity = ec.ConvertJsonToObject <T>(response); // Try to add the entity to the managed entities collections if (!AddEntityToManagedEntitiesCollection(entity)) { throw new Exception("This entity already exists"); } // Check if the endpoint supports a read action. Some endpoints such as PrintQuotation only support create (POST). if (supportedActions.CanRead) { // Get entity with linked entities (API Response for creating does not return the linked entities) entity = GetEntity(GetIdentifierValue(entity), _expandfield); } } return(created); }
/// <summary> /// Creates an entity in Exact Online /// </summary> /// <param name="entity">Entity to create</param> /// <returns>True if succeed</returns> public Boolean Create(ref T entity) { if (!IsCreateable(entity)) { throw new Exception("Cannot create entity. Entity does not support creation. Please see the Reference Documentation."); } // Get Json code var created = false; var converter = new EntityConverter(); var emptyEntity = Activator.CreateInstance <T>(); var json = converter.ConvertObjectToJson(emptyEntity, entity, _entityControllerDelegate); // Send to API var response = _conn.Post(json); if (!response.Contains("error")) { created = true; // Set values of API in account entity (to ensure GUID is set) response = ApiResponseCleaner.GetJsonObject(response); var ec = new EntityConverter(); entity = ec.ConvertJsonToObject <T>(response); // Try to add the entity to the managed entities collections if (!AddEntityToManagedEntitiesCollection(entity)) { throw new Exception("This entity already exists"); } /* IGNORE the additional GET request until it is resolved properly by the API team (https://github.com/exactonline/exactonline-api-dotnet-client/issues/9) * // Get entity with linked entities (API Response for creating does not return the linked entities) * entity = GetEntity(GetIdentifierValue(entity), _expandfield); */ } return(created); }
public void ApiResponseCleaner_FetchJsonObject_WithoutDKeyValuePair_Fails() { ApiResponseCleaner.GetJsonObject(JsonFileReader.GetJsonFromFile("ApiResponse_Json_Object_WithoutD.txt")); }
public void ApiResponseCleaner_FetchJsonObject_WithCorrectValues_Succeeds() { ApiResponseCleaner.GetJsonObject(JsonFileReader.GetJsonFromFile("ApiResponse_Json_Object.txt")); }