public void Ctor_Default()
        {
            var collection = new DirectoryAttributeModificationCollection();

            Assert.Equal(0, collection.Count);
            Assert.Equal(0, collection.Capacity);
        }
Пример #2
0
        protected void SetAttribute(DirectoryAttributeModificationCollection modifications, string name, string property, string value)
        {
            if (!Changes.ContainsKey(property))
            {
                return;
            }

            DirectoryAttributeModification m = new DirectoryAttributeModification();

            m.Add(value);
            m.Name = name;
            switch (Changes[property])
            {
            case ChangeType.Add:
                m.Operation = DirectoryAttributeOperation.Add;
                break;

            case ChangeType.Remove:
                m.Operation = DirectoryAttributeOperation.Delete;
                break;

            case ChangeType.Modify:
                m.Operation = DirectoryAttributeOperation.Replace;
                break;
            }

            modifications.Add(m);
        }
        public void Remove_InvalidValue_ThrowsArgumentException(object value, string paramName)
        {
            IList collection = new DirectoryAttributeModificationCollection {
                new DirectoryAttributeModification()
            };

            AssertExtensions.Throws <ArgumentException>(paramName, () => collection.Remove(value));
        }
        public void AddRange_NullObjectInValues_ThrowsArgumentException()
        {
            DirectoryAttributeModification[] attributes = new DirectoryAttributeModification[] { new DirectoryAttributeModification(), null, new DirectoryAttributeModification() };
            var collection = new DirectoryAttributeModificationCollection();

            AssertExtensions.Throws <ArgumentException>(null, () => collection.AddRange(attributes));
            Assert.Equal(0, collection.Count);
        }
        public void AddRange_ValidAttributes_AddsToCollection()
        {
            DirectoryAttributeModification[] attributes = new DirectoryAttributeModification[] { new DirectoryAttributeModification(), new DirectoryAttributeModification() };

            var collection = new DirectoryAttributeModificationCollection();

            collection.AddRange(attributes);

            Assert.Equal(attributes, collection.Cast <DirectoryAttributeModification>());
        }
Пример #6
0
        /// <summary>
        /// Collect the set of pending modifications for sending to the LDAP DSA
        /// </summary>
        /// <returns></returns>
        internal DirectoryAttributeModificationCollection ChangesAsDAMC()
        {
            DirectoryAttributeModificationCollection damc = new DirectoryAttributeModificationCollection();

            foreach (DirectoryAttributeModification dam in _changes.Values)
            {
                damc.Add(dam);
            }

            return(damc);
        }
        public void Indexer_Set_GetReturnsExpected()
        {
            var attribute = new DirectoryAttributeModification {
                "value"
            };
            var collection = new DirectoryAttributeModificationCollection {
                new DirectoryAttributeModification()
            };

            collection[0] = attribute;
            Assert.Equal(attribute, collection[0]);
        }
        public void Remove_Valid_Success()
        {
            var attribute = new DirectoryAttributeModification {
                "value"
            };
            var collection = new DirectoryAttributeModificationCollection {
                attribute
            };

            collection.Remove(attribute);
            Assert.Empty(collection);
        }
        public void IndexOf_Valid_ReturnsExpected()
        {
            var attribute = new DirectoryAttributeModification {
                "value"
            };
            var collection = new DirectoryAttributeModificationCollection {
                attribute
            };

            Assert.Equal(0, collection.IndexOf(attribute));
            Assert.Equal(-1, collection.IndexOf(new DirectoryAttributeModification()));
            Assert.Equal(-1, collection.IndexOf(null));
        }
        public void Contains_Valid_ReturnsExpected()
        {
            var attribute = new DirectoryAttributeModification {
                "value"
            };
            var collection = new DirectoryAttributeModificationCollection {
                attribute
            };

            Assert.True(collection.Contains(attribute));
            Assert.False(collection.Contains(new DirectoryAttributeModification()));
            Assert.False(collection.Contains(null));
        }
        public void CopyTo_MultipleTypes_Success()
        {
            DirectoryAttributeModification[] array = new DirectoryAttributeModification[3];
            var attribute = new DirectoryAttributeModification {
                "value"
            };

            var collection = new DirectoryAttributeModificationCollection {
                attribute
            };

            collection.CopyTo(array, 1);
            Assert.Equal(new DirectoryAttributeModification[] { null, attribute, null }, array);
        }
        public void Insert_ValidDirectoryAttribute_Success()
        {
            var attribute1 = new DirectoryAttributeModification {
                "value1"
            };
            var attribute2 = new DirectoryAttributeModification {
                "value2"
            };
            var collection = new DirectoryAttributeModificationCollection();

            collection.Insert(0, attribute1);
            collection.Insert(1, attribute2);

            Assert.Equal(new DirectoryAttributeModification[] { attribute1, attribute2 }, collection.Cast <DirectoryAttributeModification>());
        }
        public void Add_ValidAttribute_AppendsToList()
        {
            var attribute1 = new DirectoryAttributeModification {
                "value1"
            };
            var attribute2 = new DirectoryAttributeModification {
                "value2"
            };
            var collection = new DirectoryAttributeModificationCollection {
                attribute1, attribute2
            };

            Assert.Equal(2, collection.Count);
            Assert.Equal(new DirectoryAttributeModification[] { attribute1, attribute2 }, collection.Cast <DirectoryAttributeModification>());
        }
        public void Add_NullAttribute_ThrowsArgumentException()
        {
            var collection = new DirectoryAttributeModificationCollection();

            AssertExtensions.Throws <ArgumentException>(null, () => collection.Add(null));
        }
        public void Indexer_SetNull_ThrowsArgumentException()
        {
            var collection = new DirectoryAttributeModificationCollection();

            AssertExtensions.Throws <ArgumentException>(null, () => collection[0] = null);
        }
Пример #16
0
        private void UpdateValueCollectionChanges(string attrName, ADPropertyValueCollection valueCollection, DirectoryAttributeModificationCollection mods)
        {
            DirectoryAttributeModification directoryAttributeModification;

            if (valueCollection != null)
            {
                if (!valueCollection.TrackChanges)
                {
                    directoryAttributeModification = this.CreateDirAttrModification(attrName, valueCollection, null);
                    mods.Add(directoryAttributeModification);
                }
                else
                {
                    if (!valueCollection.IsValuesCleared)
                    {
                        if (valueCollection.ReplacedValues.Count <= 0)
                        {
                            if (valueCollection.DeletedValues.Count > 0)
                            {
                                directoryAttributeModification           = this.CreateDirAttrModification(attrName, valueCollection.DeletedValues, null);
                                directoryAttributeModification.Operation = DirectoryAttributeOperation.Delete;
                                mods.Add(directoryAttributeModification);
                            }
                            if (valueCollection.AddedValues.Count > 0)
                            {
                                directoryAttributeModification           = new DirectoryAttributeModification();
                                directoryAttributeModification.Operation = DirectoryAttributeOperation.Add;
                                this.CreateDirAttrModification(attrName, valueCollection.AddedValues, directoryAttributeModification);
                                mods.Add(directoryAttributeModification);
                                return;
                            }
                        }
                        else
                        {
                            directoryAttributeModification = this.CreateDirAttrModification(attrName, valueCollection.ReplacedValues, null);
                            mods.Add(directoryAttributeModification);
                            return;
                        }
                    }
                    else
                    {
                        directoryAttributeModification           = new DirectoryAttributeModification();
                        directoryAttributeModification.Name      = attrName;
                        directoryAttributeModification.Operation = DirectoryAttributeOperation.Delete;
                        mods.Add(directoryAttributeModification);
                        return;
                    }
                }
                return;
            }
            else
            {
                directoryAttributeModification           = new DirectoryAttributeModification();
                directoryAttributeModification.Name      = attrName;
                directoryAttributeModification.Operation = DirectoryAttributeOperation.Delete;
                mods.Add(directoryAttributeModification);
                return;
            }
        }
        public void AddRange_NullAttributes_ThrowsArgumentNullException()
        {
            var collection = new DirectoryAttributeModificationCollection();

            AssertExtensions.Throws <ArgumentNullException>("attributes", () => collection.AddRange((DirectoryAttributeModification[])null));
        }
Пример #18
0
 protected void SetAttribute(DirectoryAttributeModificationCollection modifications, string name, string value)
 {
     SetAttribute(modifications, name, name, value);
 }
	public void AddRange(DirectoryAttributeModificationCollection attributeCollection) {}
Пример #20
0
 public void AddRange(DirectoryAttributeModificationCollection attributeCollection)
 {
 }
        public void Insert_NullValue_ThrowsArgumentException()
        {
            var collection = new DirectoryAttributeModificationCollection();

            AssertExtensions.Throws <ArgumentException>(null, () => collection.Insert(0, null));
        }
Пример #22
0
        public void Update()
        {
            ADPropertyValueCollection value;

            this.Init();
            DebugLogger.WriteLine("ADActiveObject", string.Concat("Update called for ", this._adObject.DistinguishedName));
            DirectoryAttributeModificationCollection directoryAttributeModificationCollection = new DirectoryAttributeModificationCollection();

            if (!this._adObject.TrackChanges)
            {
                bool flag = false;
                foreach (KeyValuePair <string, ADPropertyValueCollection> keyValuePair in this._adObject)
                {
                    string key = keyValuePair.Key;
                    if (flag || string.Compare(key, "distinguishedName", StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        value = keyValuePair.Value;
                        this.UpdateValueCollectionChanges(key, value, directoryAttributeModificationCollection);
                    }
                    else
                    {
                        flag = true;
                    }
                }
            }
            else
            {
                foreach (string addedProperty in this._adObject.AddedProperties)
                {
                    value = this._adObject[addedProperty];
                    this.UpdateValueCollectionChanges(addedProperty, value, directoryAttributeModificationCollection);
                }
                foreach (string removedProperty in this._adObject.RemovedProperties)
                {
                    DirectoryAttributeModification directoryAttributeModification = new DirectoryAttributeModification();
                    directoryAttributeModification.Name      = removedProperty;
                    directoryAttributeModification.Operation = DirectoryAttributeOperation.Delete;
                    directoryAttributeModificationCollection.Add(directoryAttributeModification);
                }
                foreach (string modifiedProperty in this._adObject.ModifiedProperties)
                {
                    value = this._adObject[modifiedProperty];
                    this.UpdateValueCollectionChanges(modifiedProperty, value, directoryAttributeModificationCollection);
                }
            }
            if (directoryAttributeModificationCollection.Count != 0)
            {
                DirectoryAttributeModification[] directoryAttributeModificationArray = new DirectoryAttributeModification[directoryAttributeModificationCollection.Count];
                directoryAttributeModificationCollection.CopyTo(directoryAttributeModificationArray, 0);
                ADModifyRequest         aDModifyRequest         = new ADModifyRequest(this._adObject.DistinguishedName, directoryAttributeModificationArray);
                PermissiveModifyControl permissiveModifyControl = new PermissiveModifyControl();
                aDModifyRequest.Controls.Add(permissiveModifyControl);
                if (this._sdFlags != SecurityMasks.None)
                {
                    aDModifyRequest.Controls.Add(new SecurityDescriptorFlagControl(this._sdFlags));
                }
                this._syncOps.Modify(this._sessionHandle, aDModifyRequest);
                DebugLogger.WriteLine("ADActiveObject", string.Concat("Update succeeded for ", this._adObject.DistinguishedName));
                return;
            }
            else
            {
                return;
            }
        }