private static void AssertCollectionContainsExactlyUnordered(CopyOnWriteCollection <int> collection, IEnumerable <int> expectedItems) { foreach (var item in expectedItems) { Assert.True(collection.TryRemove(item)); } Assert.Equal(0, collection.Count); }
public void AddRangeShouldResultInExpectedCount(int expectedCount) { var items = Enumerable.Range(0, expectedCount).ToArray(); var collection = new CopyOnWriteCollection <int>(); collection.AddRange(items); Assert.Equal(expectedCount, collection.Count); }
public void SnapshotShouldReturnAddedItems(int nrItems) { var items = Enumerable.Range(0, nrItems).ToArray(); var collection = new CopyOnWriteCollection <int>(); collection.AddRange(items); Assert.Equal(items, collection.Snapshot); }
public void RemoveAndGetAllShouldReturnAllItems(int nrItems) { var items = Enumerable.Range(0, nrItems).ToArray(); var collection = new CopyOnWriteCollection <int>(); collection.AddRange(items); Assert.Equal(items, collection.RemoveAndGetAll()); }
public void TryRemoveShouldReturnTrueForKnownItem() { var knownItems = Enumerable.Range(0, 5).ToArray(); var collection = new CopyOnWriteCollection <int>(); collection.AddRange(knownItems); Assert.True(collection.TryRemove(knownItems[2])); }
public HttpProxyClientState( CopyOnWriteCollection <HttpProxyHandlerState> handlerStates, IScheduledActivity healthCheckActivity, IScheduledActivity refillActivity) { HandlerStates = handlerStates; HealthCheckActivity = healthCheckActivity; RefillActivity = refillActivity; }
public void TryRemoveShouldReturnFalseForUnknownItem() { const int unknownItem = -1; var knownItems = Enumerable.Range(0, 5).ToArray(); var collection = new CopyOnWriteCollection <int>(); collection.AddRange(knownItems); Assert.False(collection.TryRemove(unknownItem)); }
public void RemoveAndGetAllShouldEmptyTheArray(int nrItems) { var items = Enumerable.Range(0, nrItems).ToArray(); var collection = new CopyOnWriteCollection <int>(); collection.AddRange(items); collection.RemoveAndGetAll(); Assert.Equal(new int[0], collection.Snapshot); }
public void TryRemoveOfLastItemShouldEmptyTheArray() { var collection = new CopyOnWriteCollection <int>(); const int lastItem = 3; collection.AddRange(new[] { lastItem }); collection.TryRemove(lastItem); Assert.Equal(new int[0], collection.Snapshot); }
public void TryRemoveShouldDecrementCountForKnownItem() { var knownItems = Enumerable.Range(0, 5).ToArray(); var collection = new CopyOnWriteCollection <int>(); collection.AddRange(knownItems); collection.TryRemove(knownItems[2]); Assert.Equal(knownItems.Length - 1, collection.Count); }
public void TryRemoveShouldRemoveKnownItem() { var knownItems = Enumerable.Range(0, 5).ToArray(); var collection = new CopyOnWriteCollection <int>(); collection.AddRange(knownItems); collection.TryRemove(knownItems[2]); Assert.DoesNotContain(knownItems[2], collection.Snapshot); }
public void TryRemoveShouldNotChangeCountForUnknownItem() { const int unknownItem = -1; var knownItems = Enumerable.Range(0, 5).ToArray(); var collection = new CopyOnWriteCollection <int>(); collection.AddRange(knownItems); collection.TryRemove(unknownItem); Assert.Equal(knownItems.Length, collection.Count); }
public void AddRangeShouldAddNewItemsAfterOldItems() { var oldItems = Enumerable.Range(0, 5).ToArray(); var newItems = Enumerable.Range(0, 3).ToArray(); var collection = new CopyOnWriteCollection <int>(); collection.AddRange(oldItems); collection.AddRange(newItems); var expectedItems = new int[oldItems.Length + newItems.Length]; oldItems.CopyTo(expectedItems, 0); newItems.CopyTo(expectedItems, oldItems.Length); Assert.Equal(expectedItems, collection.Snapshot); }
public void AddRangeShouldAllowParallelCalls() { var collection = new CopyOnWriteCollection <int>(); const int nrOfParallelOperations = 100; var addRangeActions = new Action[nrOfParallelOperations]; var addedItems = new List <int>(nrOfParallelOperations * 3); for (var i = 0; i < nrOfParallelOperations; i++) { var itemsToAdd = new[] { i, i + 1, i + 2 }; addedItems.AddRange(itemsToAdd); addRangeActions[i] = () => collection.AddRange(itemsToAdd); } Parallel.Invoke(addRangeActions); AssertCollectionContainsExactlyUnordered(collection, addedItems); }
public void TryRemoveShouldAllowParallelCalls() { const int nrOfParallelOperations = 100; var items = Enumerable.Range(0, nrOfParallelOperations).ToArray(); var collection = new CopyOnWriteCollection <int>(); collection.AddRange(items); var tryRemoveActions = new Action[nrOfParallelOperations]; for (var i = 0; i < nrOfParallelOperations; i++) { var item = i; tryRemoveActions[i] = () => collection.TryRemove(item); } Parallel.Invoke(tryRemoveActions); Assert.Equal(0, collection.Count); }
public void ShouldStartEmpty() { var collection = new CopyOnWriteCollection <int>(); Assert.Equal(new int[0], collection.Snapshot); }