Beispiel #1
0
        public void WithdrawlDeadlockSafetyTest()
        {
            // Arrange
            var subject = new TestCard(123);

            subject.TopUp(123, 500);

            // Act
            // lock it first
            Monitor.Enter(subject.SyncRoot);
            try
            {
                // now let another thread try to get the monitor
                var result = Task.Run(() => subject.Withdraw(123, 100)).Result;

                // Assert
                Assert.That(result.HasError, Is.EqualTo(true));
                Assert.That(result.Error, Is.EqualTo("Unable to withdraw. Please try later."));
            }
            finally
            {
                Monitor.Exit(subject.SyncRoot);
            }
        }