private CollectionDiffWithValue<Entity, Entity> TestSyncWithValue(Entity[] oldItems, EntityProto[] newItems, int addedCount = 0, int removedCount = 0, int editedCount = 0, int unchangedCount = 0) { var list = oldItems.ToList(); var result = CollectionHelper.SyncWithContent(list, newItems, EqualityEntity, FacEntity, Update, null); Assert.IsNotNull(result, "result is not null"); Assert.AreEqual(addedCount > 0 || removedCount > 0 || editedCount > 0, result.Changed, "is changed"); Assert.AreEqual(addedCount, result.Added.Length, "Aadded"); Assert.AreEqual(editedCount, result.Edited.Length, "Edited"); Assert.AreEqual(removedCount, result.Removed.Length, "Removed"); Assert.AreEqual(unchangedCount, result.Unchanged.Length, "Unchanged"); return result; }
/// <summary> /// Issues a <c>CompundCreateRequest</c> to the target <c>CrmService</c>. /// </summary> /// <param name="entity">The <c>Entity</c> to be created.</param> /// <param name="children">The <c>Array</c> of <c>Entity</c> objects that contains the children.</param> protected void CreateNewCompoundEntity(Entity entity, Entity[] children) { if (entity == null) { throw new AdapterException(string.Format(CultureInfo.CurrentCulture, Resources.ArgumentNullExceptionMessage), new ArgumentNullException("entity")) { ExceptionId = AdapterException.SystemExceptionGuid }; } entity.Attributes.Remove(CRM2011AdapterUtilities.IsNew); OptionSetValue state = null; OptionSetValue status = null; state = RemoveStateCode(entity); if (state != null) { status = RemoveStatusCode(entity); } entity.RelatedEntities.Add(new Relationship((entity.LogicalName == "salesorder" ? "order" : entity.LogicalName) + "_details"), new EntityCollection(children.ToList())); CreateRequest request = new CreateRequest() { Target = entity }; if (this.DoesDetectDuplicates == true) { request["SuppressDuplicateDetection"] = false; } PrepEntityForCreate(entity); this.CallCrmExecuteWebMethod(request); this.ApplyStateAndStatus(entity, state, status); }