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(); } }
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>(); }
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); }