Beispiel #1
0
        public void FunctionalLifeSpanTest_ShouldProduceDesiredResults_ForSynchronousInvocation()
        {
            // Arrange.
            var target = (DataAccessTransaction)null;

            using (target = new SimulatedFooTransaction())
            {
                // Assert.
                target.State.Should().Be(DataAccessTransactionState.Ready);

                // Act.
                target.Begin();

                // Assert.
                target.State.Should().Be(DataAccessTransactionState.InProgress);

                // Act.
                target.Commit();

                // Assert.
                target.State.Should().Be(DataAccessTransactionState.Committed);
            }

            // Assert.
            target.State.Should().Be(DataAccessTransactionState.Unspecified);

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

            // Assert.
            action.Should().Throw <InvalidOperationException>($"because {nameof(target)} is disposed");

            using (target = new SimulatedFooTransaction())
            {
                // Assert.
                target.State.Should().Be(DataAccessTransactionState.Ready);

                // Act.
                target.Begin();

                // Assert.
                target.State.Should().Be(DataAccessTransactionState.InProgress);

                // Act.
                target.Reject();

                // Assert.
                target.State.Should().Be(DataAccessTransactionState.Rejected);
            }
        }
Beispiel #2
0
        public void RejectAsync_ShouldRaiseInvalidOperationException_ForReadyStateTransaction()
        {
            using (var target = new SimulatedFooTransaction())
            {
                // Act.
                var action = new Action(() =>
                {
                    target.RejectAsync().Wait();
                });

                // Assert.
                action.Should().Throw <InvalidOperationException>($"because {nameof(target)} has not yet begun");
            }
        }
Beispiel #3
0
        public void BeginAsync_ShouldRaiseInvalidOperationException_ForInProgressTransaction()
        {
            using (var target = new SimulatedFooTransaction())
            {
                // Arrange.
                target.BeginAsync().Wait();

                // Act.
                var action = new Action(() =>
                {
                    target.BeginAsync().Wait();
                });

                // Assert.
                action.Should().Throw <InvalidOperationException>($"because {nameof(target)} has already begun");
            }
        }
Beispiel #4
0
        public void BeginAsync_ShouldRaiseInvalidOperationException_ForCommittedTransaction()
        {
            using (var target = new SimulatedFooTransaction())
            {
                // Arrange.
                target.BeginAsync().Wait();
                target.CommitAsync().Wait();

                // Act.
                var action = new Action(() =>
                {
                    target.BeginAsync().Wait();
                });

                // Assert.
                action.Should().Throw <InvalidOperationException>($"because {nameof(target)} is committed");
            }
        }
Beispiel #5
0
        public void Reject_ShouldRaiseInvalidOperationException_ForRejectedTransaction()
        {
            using (var target = new SimulatedFooTransaction())
            {
                // Arrange.
                target.Begin();
                target.Reject();

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

                // Assert.
                action.Should().Throw <InvalidOperationException>($"because {nameof(target)} is rejected");
            }
        }