Пример #1
0
        public async Task AddPinThrowsOnDisposedPinContext()
        {
            var context = new Context(Logger);

            using (var taskTracker = new BackgroundTaskTracker(nameof(PinContextTests), context))
            {
                try
                {
                    var pinContext = new PinContext(taskTracker, contentHashes => { });
                    pinContext.AddPin(ContentHash.Random());
                    await pinContext.DisposeAsync();

                    Action addPinAction = () => pinContext.AddPin(ContentHash.Random());
                    addPinAction.Should().Throw <ObjectDisposedException>();
                }
                finally
                {
                    await taskTracker.ShutdownAsync(context);
                }
            }
        }
Пример #2
0
        public async Task AddPinAccumulatesDuplicates()
        {
            var context = new Context(Logger);

            using (var taskTracker = new BackgroundTaskTracker(nameof(PinContextTests), context))
            {
                try
                {
                    ContentHash hash1      = ContentHash.Random();
                    ContentHash hash2      = ContentHash.Random();
                    var         hashCounts = new ConcurrentDictionary <ContentHash, int>
                    {
                        [hash1] = 0,
                        [hash2] = 0
                    };

                    using (var pinContext = new PinContext(taskTracker, pinCounts =>
                    {
                        foreach (var pinCount in pinCounts)
                        {
                            hashCounts[pinCount.Key] = pinCount.Value;
                        }
                    }))
                    {
                        pinContext.AddPin(hash2);
                        pinContext.AddPin(hash1);
                        pinContext.AddPin(hash2);
                    }

                    hashCounts[hash1].Should().Be(1);
                    hashCounts[hash2].Should().Be(2);
                }
                finally
                {
                    await taskTracker.ShutdownAsync(context);
                }
            }
        }