public void modifying_single_value_generates_Replace_operation() { RmPerson person = new RmPerson { DisplayName = "original-name" }; var resourceChanges = new RmResourceChanges(person); resourceChanges.BeginChanges(); person.DisplayName = "new-name"; person.LastName = "last name"; var changes = resourceChanges.GetChanges(); Assert.Equal(2, changes.Count); Assert.NotEmpty(changes.Where(x => x.Name.Name == RmPerson.AttributeNames.LastName.Name && x.Value.ToString() == "last name") ); Assert.NotEmpty(changes.Where(x => x.Name.Name == RmResource.AttributeNames.DisplayName.Name && x.Value.ToString() == "new-name") ); foreach (var change in changes) { Assert.Equal(RmAttributeChangeOperation.Replace, change.Operation); } }
public void RemoveAlias01() { #if _ RmPerson person = new RmPerson(); person.MailAliases.Add("one"); person.MailAliases.Add("two"); RmResourceChanges changes = new RmResourceChanges(person); changes.BeginChanges(); person.MailAliases.Remove("two"); var changesList = changes.GetChanges(); Assert.AreEqual(1, changesList.Count); Assert.AreEqual(RmAttributeChangeOperation.Delete, changesList[0].Operation); Assert.AreEqual("two", changesList[0].Value); #endif }
public void AddAlias01() { #if _ RmPerson person = new RmPerson(); person.MailAliases.Add("one"); person.MailAliases.Add("two"); RmResourceChanges changes = new RmResourceChanges(person); changes.BeginChanges(); person.MailAliases.Add("three"); var changesList = changes.GetChanges(); Assert.AreEqual(1, changesList.Count); Assert.AreEqual(RmAttributeChangeOperation.Add, changesList[0].Operation); Assert.AreEqual("three", changesList[0].Value); #endif }
public void FirstNameChange01() { string before = "Before"; string after = "After"; RmPerson person = new RmPerson() { FirstName = before }; RmResourceChanges changes = new RmResourceChanges(person); changes.BeginChanges(); person.FirstName = after; var changesList = changes.GetChanges(); Assert.AreEqual(1, changesList.Count); Assert.AreEqual(RmAttributeChangeOperation.Replace, changesList[0].Operation); Assert.AreEqual(after, changesList[0].Value); }
public void ManagerChange01() { RmReference manager1 = new RmReference("{54C0FFDB-548A-45df-A7A4-7386EE8120A7}"); RmReference manager2 = new RmReference("{C4360DE1-C589-4444-B960-92930878A7AC}"); RmPerson person = new RmPerson() { Manager = manager1 }; RmResourceChanges changes = new RmResourceChanges(person); changes.BeginChanges(); person.Manager = manager2; var changesList = changes.GetChanges(); Assert.AreEqual(1, changesList.Count); Assert.AreEqual(RmAttributeChangeOperation.Replace, changesList[0].Operation); Assert.AreEqual(manager2, changesList[0].Value); }
public void setting_single_valued_reference_generates_Replace_operation() { RmPerson person = new RmPerson(); var resourceChanges = new RmResourceChanges(person); resourceChanges.BeginChanges(); person.Manager = new RmReference("2CFAAD59-A6ED-4A96-91A2-52992361929A"); var changes = resourceChanges.GetChanges(); Assert.Equal(1, changes.Count); var change = changes.Single(); Assert.Equal(RmAttributeChangeOperation.Replace, change.Operation); Assert.Equal(RmPerson.AttributeNames.Manager.Name, change.Name.Name); Assert.Equal(person.Manager, change.Value); }
public bool Update(RmResourceChanges changes) { Initialize(); int changesCount = changes.GetChanges().Count; if (changesCount == 0) { _log.Debug("Requested to update resource {0} of type {1} but no changes are present. Aborting.", changes.RmObject.ObjectID.Value, changes.RmObject.ObjectType); return(true); } _log.Info("Updating resource {0} of type {1} with {2} changes", changes.RmObject.ObjectID.Value, changes.RmObject.ObjectType, changesCount); bool updated = _defaultClient.Put(changes); changes.AcceptChanges(); return(updated); }
public void clearing_single_valued_date_generates_Delete_operation___otherwise_fim_web_service_throws() { RmPerson person = new RmPerson { EmployeeEndDate = new DateTime(2011, 1, 1) }; var resourceChanges = new RmResourceChanges(person); resourceChanges.BeginChanges(); person.EmployeeEndDate = null; var changes = resourceChanges.GetChanges(); Assert.Equal(1, changes.Count); var change = changes.Single(); Assert.Equal(RmAttributeChangeOperation.Delete, change.Operation); Assert.Equal(RmPerson.AttributeNames.EmployeeEndDate.Name, change.Name.Name); Assert.Equal(person.EmployeeEndDate, change.Value); }
public void clearing_single_valued_reference_generates_Delete_operation___otherwise_fim_web_service_throws() { RmPerson person = new RmPerson { Manager = new RmReference("2CFAAD59-A6ED-4A96-91A2-52992361929A") }; var resourceChanges = new RmResourceChanges(person); resourceChanges.BeginChanges(); person.Manager = null; var changes = resourceChanges.GetChanges(); Assert.Equal(1, changes.Count); var change = changes.Single(); Assert.Equal(RmAttributeChangeOperation.Delete, change.Operation); Assert.Equal(RmPerson.AttributeNames.Manager.Name, change.Name.Name); Assert.Equal(person.Manager, change.Value); }
public Message CreatePutRequest(RmResourceChanges transaction) { if (transaction == null) { throw new ArgumentException("transaction"); } RmResource rmObject = transaction.RmObject; if (rmObject == null) { throw new InvalidOperationException("transaction does not have rmObject"); } lock (rmObject) { RequestPut putRequest = new RequestPut(); putRequest.ResourceReferenceProperty = rmObject.ObjectID.ToString(); if (String.IsNullOrEmpty(rmObject.Locale) == false) { putRequest.ResourceLocaleProperty = CultureInfo.GetCultureInfo(rmObject.Locale).ToString(); //System.Globalization.CultureInfo(rmObject.Locale) } putRequest.ModifyRequest = new ModifyRequest(); IList <RmAttributeChange> changes = transaction.GetChanges(); foreach (RmAttributeChange attributeChange in changes) { if (!string.IsNullOrEmpty(ProhibitedAttributes.Find(p => p.Equals(attributeChange.Name.Name, StringComparison.OrdinalIgnoreCase)))) { continue; } DirectoryAccessChange putReqChange = BuildDirectoryAccessChange(attributeChange); if (base.IsMultiValued(attributeChange.Name)) { putReqChange.Operation = attributeChange.Operation.ToString(); } else { if (attributeChange.Operation == RmAttributeChangeOperation.Add) { putReqChange.Operation = RmAttributeChangeOperation.Replace.ToString(); } else if (attributeChange.Operation == RmAttributeChangeOperation.Delete) { putReqChange.Operation = RmAttributeChangeOperation.Replace.ToString(); putReqChange.AttributeValue = null; } } putRequest.ModifyRequest.Changes.Add(putReqChange); } Message msgRequest = null; lock (putRequest) { msgRequest = Message.CreateMessage(MessageVersion.Default, Constants.WsTransfer.PutAction, putRequest.ModifyRequest, new ClientSerializer(typeof(ModifyRequest))); ClientHelper.AddImdaHeaders(putRequest, msgRequest); ClientHelper.AddRmHeaders(putRequest, msgRequest); } return(msgRequest); } }
/// <summary> /// Constructs a put request based on the changes tracked in the transaction. /// </summary> /// <param name="transaction">The transaction object which tracked the changes made to an object.</param> /// <returns></returns> public virtual PutRequest CreatePutRequest(RmResourceChanges transaction) { if (transaction == null) { throw new ArgumentNullException("transaction"); } RmResource rmObject = transaction.RmObject; if (rmObject == null) { throw new InvalidOperationException("transaction does not have rmObject"); } if (rmObject.ObjectID == null) { throw new InvalidOperationException("The rmObject does not have an ObjectID."); } lock (rmObject) { PutRequest putRequest = new PutRequest(); putRequest.ResourceReferenceProperty = new ResourceReferenceProperty(rmObject.ObjectID.ToString()); if (string.IsNullOrEmpty(rmObject.Locale) == false) { putRequest.ResourceLocaleProperty = new ResourceLocaleProperty(new System.Globalization.CultureInfo(rmObject.Locale)); } putRequest.ModifyRequest = new ModifyRequest(); IList <RmAttributeChange> changes = transaction.GetChanges(); foreach (RmAttributeChange attributeChange in changes) { if (this.ProhibitedAttributes.ContainsKey(attributeChange.Name.Name)) { continue; } DirectoryAccessChange putReqChange = BuildDirectoryAccessChange(attributeChange); if (base.IsMultiValued(attributeChange.Name)) { putReqChange.Operation = attributeChange.Operation.ToString(); } else { if (attributeChange.Operation == RmAttributeChangeOperation.Add) { putReqChange.Operation = RmAttributeChangeOperation.Replace.ToString(); } else if (attributeChange.Operation == RmAttributeChangeOperation.Delete) { putReqChange.Operation = RmAttributeChangeOperation.Replace.ToString(); putReqChange.AttributeValue = null; } else { putReqChange.Operation = attributeChange.Operation.ToString(); } } putRequest.ModifyRequest.Changes.Add(putReqChange); } return(putRequest); } }