public void FunctionalLifeSpanTest_ShouldProduceDesiredResults()
        {
            // Arrange.
            var disposableObjectCount = 30;
            var disposableObjects     = new SimulatedInstrument[disposableObjectCount];
            var target = new ReferenceManager();

            for (var i = 0; i < disposableObjectCount; i++)
            {
                // Arrange.
                var disposableObject = new SimulatedInstrument(ConcurrencyControlMode.Unconstrained);
                disposableObject.StoreIntegerValue(i);
                disposableObjects[i] = disposableObject;

                // Act.
                target.AddObject(disposableObject);
                target.AddObject(new Object());
                target.AddObject((Object)null);

                // Assert.
                target.ObjectCount.Should().Be((i + 1) * 3);
            }

            // Act.
            target.Dispose();

            // Assert.
            target.ObjectCount.Should().Be(0);

            foreach (var disposableObject in disposableObjects)
            {
                // Assert.
                disposableObject.NullableIntegerValue.Should().BeNull();
            }
        }
Пример #2
0
        public void StateControl_ShouldProduceDesiredResults_ForSingleThreadConcurrencyControl()
        {
            // Arrange.
            var stateControlMode = ConcurrencyControlMode.SingleThreadLock;
            var taskCount        = 7;
            var tasks            = new Task[taskCount];
            var target           = (SimulatedInstrument)null;

            // Act.
            var action = new Action(() =>
            {
                using (target = new SimulatedInstrument(stateControlMode))
                {
                    for (var i = 0; i < taskCount; i++)
                    {
                        var task = new Task(() => target.SimulateThreadSafeOperation());
                        tasks[i] = task;
                        task.Start();
                    }

                    Task.WaitAll(tasks);

                    // Assert.
                    tasks.Count(task => task.Status == TaskStatus.RanToCompletion).Should().Be(taskCount);
                    target.StateIsVolatile.Should().BeFalse();
                }
            });

            // Assert.
            action.Should().NotThrow();
        }
Пример #3
0
        public void FunctionalLifeSpanTest_ShouldProduceDesiredResults()
        {
            // Arrange.
            var stateControlMode = ConcurrencyControlMode.SingleThreadLock;
            var target           = (SimulatedInstrument)null;
            var integerValue     = 3;

            using (target = new SimulatedInstrument(stateControlMode))
            {
                // Act.
                target.StoreIntegerValue(integerValue);

                // Assert.
                target.NullableIntegerValue.Should().Be(integerValue);
            }

            // Assert.
            target.NullableIntegerValue.Should().Be(null);
        }
Пример #4
0
        public void RejectIfDisposed_ShouldRaiseObjectDisposedException_ForDisposedTarget()
        {
            // Arrange.
            var stateControlMode = ConcurrencyControlMode.SingleThreadLock;
            var target           = (SimulatedInstrument)null;
            var integerValue     = 3;

            using (target = new SimulatedInstrument(stateControlMode))
            {
                target.StoreIntegerValue(integerValue);
            }

            // Act.
            var action = new Action(() =>
            {
                target.StoreIntegerValue(integerValue);
            });

            // Assert.
            action.Should().Throw <ObjectDisposedException>();
        }