Beispiel #1
0
        public void EquivalentFailsWithDuplicateElementInExpected()
        {
            ICollection set1 = new ICollectionAdapter("x", "y", "x");
            ICollection set2 = new ICollectionAdapter("x", "y", "z");

            Assert.False(new CollectionEquivalentConstraint(set1).Matches(set2));
        }
Beispiel #2
0
        public void EquivalentIgnoresOrder()
        {
            ICollection set1 = new ICollectionAdapter("x", "y", "z");
            ICollection set2 = new ICollectionAdapter("z", "y", "x");

            Assert.That(new CollectionEquivalentConstraint(set1).Matches(set2));
        }
Beispiel #3
0
        public void EquivalentHandlesNull()
        {
            ICollection set1 = new ICollectionAdapter(null, "x", null, "z");
            ICollection set2 = new ICollectionAdapter("z", null, "x", null);

            Assert.That(new CollectionEquivalentConstraint(set1).Matches(set2));
        }
Beispiel #4
0
        public void EquivalentHonorsIgnoreCase()
        {
            ICollection set1 = new ICollectionAdapter("x", "y", "z");
            ICollection set2 = new ICollectionAdapter("z", "Y", "X");

            Assert.That(new CollectionEquivalentConstraint(set1).IgnoreCase.Matches(set2));
        }
 /// <summary>
 /// Insert document entity.
 /// </summary>
 /// <typeparam name="TEntity">Indicating the document type.</typeparam>
 /// <param name="adapter">Indicating the document adapter.</param>
 /// <param name="entity">Indicating the document entity.</param>
 /// <param name="token">Indicating the cancellation token.</param>
 /// <returns>Async task.</returns>
 public static Task <TEntity> InsertAsync <TEntity>(
     this ICollectionAdapter <TEntity> adapter,
     TEntity entity,
     CancellationToken token)
     where TEntity : EntityBase
 {
     return(adapter.InsertAsync(entity, null, token));
 }
 /// <summary>
 /// Get document count by filter.
 /// </summary>
 /// <typeparam name="TEntity">Indicating the document type.</typeparam>
 /// <param name="adapter">Indicating the document adapter.</param>
 /// <param name="filter">Indicating the filter expression.</param>
 /// <param name="token">Indicating the cancellation token.</param>
 /// <returns>Async return count.</returns>
 public static Task <long> CountAsync <TEntity>(
     this ICollectionAdapter <TEntity> adapter,
     Expression <Func <TEntity, bool> > filter,
     CancellationToken token)
     where TEntity : EntityBase
 {
     return(adapter.CountAsync(filter, null, token));
 }
 /// <summary>
 /// Get single document by id.
 /// </summary>
 /// <typeparam name="TEntity">Indicating the document type.</typeparam>
 /// <param name="adapter">Indicating the document adapter.</param>
 /// <param name="id">Indicating the document id.</param>
 /// <param name="token">Indicating the cancellation token.</param>
 /// <returns>Async return document entity.</returns>
 public static Task <TEntity> GetSingleAsync <TEntity>(
     this ICollectionAdapter <TEntity> adapter,
     string id,
     CancellationToken token)
     where TEntity : EntityBase
 {
     return(adapter.GetSingleAsync(e => e.Id == id, token));
 }
 /// <summary>
 /// Delete document.
 /// </summary>
 /// <typeparam name="TEntity">Indicating the document type.</typeparam>
 /// <param name="adapter">Indicating the document adapter.</param>
 /// <param name="entity">Indicating the document entity.</param>
 /// <param name="token">Indicating the cancellation token.</param>
 /// <returns>Async task.</returns>
 public static Task DeleteAsync <TEntity>(
     this ICollectionAdapter <TEntity> adapter,
     TEntity entity,
     CancellationToken token)
     where TEntity : EntityBase
 {
     return(adapter.DeleteAsync(entity.Id, token));
 }
 /// <summary>
 /// Get document entity list by filter.
 /// </summary>
 /// <typeparam name="TEntity">Indicating the document type.</typeparam>
 /// <param name="adapter">Indicating the document adapter.</param>
 /// <param name="filter">Indicating the filter expression.</param>
 /// <param name="token">Indicating the cancellation token.</param>
 /// <returns>Async return list.</returns>
 public static Task <IReadOnlyList <TEntity> > GetListAsync <TEntity>(
     this ICollectionAdapter <TEntity> adapter,
     Expression <Func <TEntity, bool> > filter,
     CancellationToken token)
     where TEntity : EntityBase
 {
     return(adapter.GetListAsync(filter, null, token));
 }
 /// <summary>
 /// Batch insert document entity.
 /// </summary>
 /// <typeparam name="TEntity">Indicating the document type.</typeparam>
 /// <param name="adapter">Indicating the document adapter.</param>
 /// <param name="entities">Indicating the document entity list for batch insert.</param>
 /// <param name="token">Indicating the cancellation token.</param>
 /// <returns>Async task.</returns>
 public static Task <IReadOnlyList <TEntity> > InsertManyAsync <TEntity>(
     this ICollectionAdapter <TEntity> adapter,
     IReadOnlyList <TEntity> entities,
     CancellationToken token)
     where TEntity : EntityBase
 {
     return(adapter.InsertManyAsync(entities, null, token));
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="ObservableReadOnlyCollectionBase{T}" /> class.
 /// </summary>
 /// <param name="internalContainer">The internal container of items.</param>
 /// <param name="context">The synchronization context to use, if any.</param>
 protected ObservableReadOnlyCollectionBase(
     ICollectionAdapter <T> internalContainer,
     SynchronizationContext context)
     : base(context)
 {
     this.InternalContainer = internalContainer;
     this.resetCountLocker  = new object();
 }
        public ICompositeMemento CreateCollectionMemento <TCollection, TElement>(
            ICollectionAdapter <TCollection, TElement> adapter,
            bool cascade)
        {
            var data = new CollectionData(adapter, cascade, typeof(TElement));

            return(new CollectionMemento(data, this));
        }
 public static Task <string> CreateIndexIfNotExistAsync <TEntity>(
     this ICollectionAdapter <TEntity> adapter,
     IndexKeysDefinition <TEntity> keys,
     CreateIndexOptions options,
     CancellationToken token)
     where TEntity : EntityBase
 {
     return(adapter.CreateIndexIfNotExistAsync(keys, options, token));
 }
Beispiel #14
0
        public void EquivalentHonorsUsing()
        {
            ICollection set1 = new ICollectionAdapter("x", "y", "z");
            ICollection set2 = new ICollectionAdapter("z", "Y", "X");

            Assert.That(new CollectionEquivalentConstraint(set1)
                        .Using <string>((x, y) => String.Compare(x, y, true))
                        .Matches(set2));
        }
Beispiel #15
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ObservableCollectionBase{T}" /> class.
 /// </summary>
 /// <param name="internalContainer">The internal container of items.</param>
 /// <param name="suppressUndoable">If set to <see langword="true" />, suppresses undoable capabilities of this collection.</param>
 protected ObservableCollectionBase(
     ICollectionAdapter <T> internalContainer,
     bool suppressUndoable)
     : base(internalContainer)
 {
     this.InitializeInternalState(
         internalContainer,
         suppressUndoable);
 }
Beispiel #16
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ObservableCollectionBase{T}" /> class.
 /// </summary>
 /// <param name="internalContainer">The internal container of items.</param>
 /// <param name="context">The synchronization context to use, if any.</param>
 protected ObservableCollectionBase(
     ICollectionAdapter <T> internalContainer,
     SynchronizationContext context)
     : this(
         internalContainer,
         context,
         EnvironmentSettings.AlwaysSuppressUndoLevelsByDefault)
 {
 }
Beispiel #17
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ObservableCollectionBase{T}" /> class.
 /// </summary>
 /// <param name="internalContainer">The internal container of items.</param>
 /// <param name="suppressUndoable">If set to <see langword="true" />, suppresses undoable capabilities of this collection.</param>
 protected ObservableCollectionBase(
     ICollectionAdapter <T> internalContainer,
     bool suppressUndoable)
     : base(internalContainer)
 {
     undoContext           = new Lazy <UndoableInnerContext>(InnerContextFactory);
     this.suppressUndoable = EnvironmentSettings.DisableUndoable || suppressUndoable;
     historyLevels         = EnvironmentSettings.DefaultUndoRedoLevels;
 }
Beispiel #18
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ObservableCollectionBase{T}" /> class.
 /// </summary>
 /// <param name="internalContainer">The internal container of items.</param>
 /// <param name="context">The synchronization context to use, if any.</param>
 protected ObservableCollectionBase(
     ICollectionAdapter <T> internalContainer,
     SynchronizationContext context)
     : base(
         internalContainer,
         context)
 {
     this.InitializeInternalState(internalContainer);
 }
Beispiel #19
0
        public ListProjection(ICollectionAdapter <T> adapter)
        {
            if (adapter == null)
            {
                throw new ArgumentNullException("adapter");
            }

            this.adapter = adapter;
            adapter.Initialize(this);
        }
Beispiel #20
0
 /// <summary>
 /// Update or insert document entity.
 /// </summary>
 /// <typeparam name="TEntity">Indicating the document type.</typeparam>
 /// <param name="adapter">Indicating the document adapter.</param>
 /// <param name="entity">Indicating the document entity.</param>
 /// <param name="token">Indicating the cancellation token.</param>
 /// <returns>Async task.</returns>
 public static Task <TEntity> UpsertAsync <TEntity>(this ICollectionAdapter <TEntity> adapter, TEntity entity, CancellationToken token)
     where TEntity : EntityBase
 {
     return(adapter.UpdateAsync(
                entity,
                new UpdateOptions {
         IsUpsert = true
     },
                token));
 }
Beispiel #21
0
 /// <summary>
 /// Constructs new instance that binds source set with target collection
 /// and uses comparer to determine items equality.
 /// </summary>
 /// <param name="targetAdapter">Adapter for target collection.</param>
 /// <param name="sourceAdapter">Adapter for source set.</param>
 /// <param name="itemComparer">Comparer that is used for determing items equality.</param>
 public SetBinding(
     ICollectionAdapter targetAdapter,
     IValueAdapter sourceAdapter,
     IEqualityComparer <object> itemComparer)
     : base(targetAdapter, sourceAdapter)
 {
     if (itemComparer == null)
     {
         throw new ArgumentNullException("itemComparer");
     }
     _itemComparer = itemComparer;
 }
Beispiel #22
0
        /// <summary>
        /// Registers a custom collection though an adapter.
        /// The adapter's 'Collection' property must be set.
        /// After <see cref="IMemento.Rollback"/> is called, the collection will contain the same elements as at the time of registration.
        /// </summary>
        ///
        /// <typeparam name="TCollection">The type of the collection being registered.</typeparam>
        /// <typeparam name="TElement">The type of elements in the collection.</typeparam>
        /// <param name="adapter">An adapter for a custom collection. Its 'Collection' property should be set.</param>
        /// <returns>This IMemento instance.</returns>
        public IMemento RegisterCollection <TCollection, TElement>(ICollectionAdapter <TCollection, TElement> adapter)
        {
            adapter.ThrowIfNull("adapter");
            if (adapter.Collection == null)
            {
                throw new ArgumentException("The adapter's Collection property must not be null.", "adapter");
            }

            var memento = Factory.CreateCollectionMemento(adapter, false);

            Components.Add(memento);
            return(this);
        }
 /// <summary>
 ///   Initializes a new instance of the <see cref = "CollectionMemberMap" /> class.
 /// </summary>
 /// <param name = "memberName">Name of the member.</param>
 /// <param name = "memberReturnType">Type of the member return.</param>
 /// <param name = "getter">The getter.</param>
 /// <param name = "setter">The setter.</param>
 /// <param name = "alias">The alias.</param>
 /// <param name = "persistDefaultValue">if set to <c>true</c> [persist default value].</param>
 /// <param name = "collectionAdapter">Type of the collection.</param>
 /// <param name = "elementType">Type of the element.</param>
 public CollectionMemberMap(string memberName,
                            Type memberReturnType,
                            Func <object, object> getter,
                            Action <object, object> setter,
                            string alias,
                            bool persistDefaultValue,
                            ICollectionAdapter collectionAdapter,
                            Type elementType)
     : base(memberName, memberReturnType, getter, setter, null, alias, persistDefaultValue)
 {
     _collectionAdapter = collectionAdapter;
     ElementType        = elementType;
 }
 /// <summary>
 ///   Initializes a new instance of the <see cref = "CollectionMemberMap" /> class.
 /// </summary>
 /// <param name = "memberName">Name of the member.</param>
 /// <param name = "memberReturnType">Type of the member return.</param>
 /// <param name = "getter">The getter.</param>
 /// <param name = "setter">The setter.</param>
 /// <param name = "alias">The alias.</param>
 /// <param name = "persistDefaultValue">if set to <c>true</c> [persist default value].</param>
 /// <param name = "collectionAdapter">Type of the collection.</param>
 /// <param name = "elementType">Type of the element.</param>
 public CollectionMemberMap(string memberName,
     Type memberReturnType,
     Func<object, object> getter,
     Action<object, object> setter,
     string alias,
     bool persistDefaultValue,
     ICollectionAdapter collectionAdapter,
     Type elementType)
     : base(memberName, memberReturnType, getter, setter, null, alias, persistDefaultValue)
 {
     _collectionAdapter = collectionAdapter;
     ElementType = elementType;
 }
Beispiel #25
0
 public DataGridSelectedItemsAdapter(DataGrid control, Func <object, object> itemKeySelector)
 {
     if (control == null)
     {
         throw new ArgumentNullException("control");
     }
     if (itemKeySelector == null)
     {
         throw new ArgumentNullException("itemKeySelector");
     }
     _collectionChangedCallback = instructions => { };
     _control              = control;
     _selectorAdapter      = new ValueToCollectionAdapter(new SelectorSelectedItemsAdapter(control, itemKeySelector));
     _multiSelectorAdapter = new MultiSelectorSelectedItemsAdapter(control, itemKeySelector);
     _selectorAdapter.CollectionChangedCallback      = OnSelectorCollectionChanged;
     _multiSelectorAdapter.CollectionChangedCallback = OnMultiSelectorCollectionChanged;
 }
 /// <summary>
 /// Update document entity.
 /// </summary>
 /// <typeparam name="TEntity">Indicating the document type.</typeparam>
 /// <param name="adapter">Indicating the document adapter.</param>
 /// <param name="entity">Indicating the document entity.</param>
 /// <param name="filter">Indicating the filter for filter.</param>
 /// <param name="update">Indicating the update for update.</param>
 /// <param name="token">Indicating the cancellation token.</param>
 /// <returns>Async task.</returns>
 public static Task <UpdateResult> UpdateOneAsync <TEntity>(
     this ICollectionAdapter <TEntity> adapter,
     TEntity entity,
     FilterDefinition <TEntity> filter,
     UpdateDefinition <TEntity> update,
     CancellationToken token)
     where TEntity : EntityBase
 {
     return(adapter.UpdateOneAsync(
                entity,
                filter,
                update,
                new UpdateOptions {
         IsUpsert = true
     },
                token));
 }
Beispiel #27
0
        public void WorksWithCollectionsOfArrays()
        {
            byte[] array1 = new byte[] { 0x20, 0x44, 0x56, 0x76, 0x1e, 0xff };
            byte[] array2 = new byte[] { 0x42, 0x52, 0x72, 0xef };
            byte[] array3 = new byte[] { 0x20, 0x44, 0x56, 0x76, 0x1e, 0xff };
            byte[] array4 = new byte[] { 0x42, 0x52, 0x72, 0xef };

            ICollection set1 = new ICollectionAdapter(array1, array2);
            ICollection set2 = new ICollectionAdapter(array3, array4);

            Constraint constraint = new CollectionEquivalentConstraint(set1);

            Assert.That(constraint.Matches(set2));

            set2 = new ICollectionAdapter(array4, array3);
            Assert.That(constraint.Matches(set2));
        }
 protected CollectionBindingBase(
     ICollectionAdapter targetAdapter,
     IValueAdapter sourceAdapter)
 {
     if (targetAdapter == null)
     {
         throw new ArgumentNullException("targetAdapter");
     }
     if (sourceAdapter == null)
     {
         throw new ArgumentNullException("sourceAdapter");
     }
     _targetAdapter = targetAdapter;
     _sourceAdapter = sourceAdapter;
     _sourceAdapter.ValueChangedCallback      = OnSourceValueChangedCallback;
     _targetAdapter.CollectionChangedCallback = OnTargetCollectionChangedCallback;
 }
Beispiel #29
0
        private static Result MeasurePerformance(ICollectionAdapter collection, int collectionSize)
        {
            CollectMemory();
            collection.CreateAndFillTestData(collectionSize);
            WarmUp(collection, collectionSize);

            var result = new Result {CollectionSize = collectionSize, Name = collection.Name, LookupMode = collection.LookupMode};
            var beginWatch = new Stopwatch();
            var middleWatch = new Stopwatch();
            var endWatch = new Stopwatch();

            var middleKey = collectionSize/2;
            var endKey = collectionSize - 1;

            for (var i = 0; i < TestsCount; i++)
            {
                beginWatch.Start();
                var begin = collection.Get(0);
                beginWatch.Stop();

                middleWatch.Start();
                var middle = collection.Get(middleKey);
                middleWatch.Stop();

                endWatch.Start();
                var end = collection.Get(endKey);
                endWatch.Stop();
            }

            collection.Dispose();

            result.Begin = beginWatch.ElapsedMilliseconds;
            result.Middle = middleWatch.ElapsedMilliseconds;
            result.End = endWatch.ElapsedMilliseconds;

            return result;
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="ObservableReadOnlyCollectionBase{T}" /> class.
 /// </summary>
 /// <param name="internalContainer">The internal container of items.</param>
 protected ObservableReadOnlyCollectionBase(ICollectionAdapter <T> internalContainer)
 {
     this.InternalContainer = internalContainer;
     this.resetCountLocker  = new object();
 }
 public void CanTestContentsOfCollectionNotImplementingIList()
 {
     ICollectionAdapter ints = new ICollectionAdapter( new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} );
     Ensure.That( ints, new CollectionContainsConstraint( 9 ) );
 }
Beispiel #32
0
        public void CanTestContentsOfCollectionNotImplementingIList()
        {
            ICollectionAdapter ints = new ICollectionAdapter(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });

            Assert.That(ints, new CollectionContainsConstraint(9));
        }
Beispiel #33
0
 public SetProjection(ICollectionAdapter <T> adapter)
     : base(adapter)
 {
     set = new HashSet <T>();
     Repopulate();
 }
Beispiel #34
0
 private static void WarmUp(ICollectionAdapter collection, int collectionSize)
 {
     var middleKey = collectionSize / 2;
     var endKey = collectionSize - 1;
     var begin = collection.Get(0);
     var middle = collection.Get(middleKey);
     var end = collection.Get(endKey);
 }