public async Task NewSaga_CulculateResultShouldBe2_WhenPassAddFunctionTwice() { //Arrange string expectName = "happyTesting"; int expectAmount = 2; int counter = 0; async Task action() => await Task.Run(() => counter ++); IActivity activity = this._saga.NewSaga(expectName) .StepWithoutBackup("test", action) .StepWithoutBackup("test2", action); //Act await activity.End(); //Assert this._saga.Name.Should().Be(expectName); counter.Should().Be(expectAmount); }
public async Task NewSaga_NameAndAmountIsCorrect_WhenPassOneActivity() { //Arrange string expectName = "happyTesting"; int expectAmount = 1; async Task action() => await Task.Run(() => { }); IActivity activity = this._saga.NewSaga("happyTesting") .StepWithoutBackup("test", action); this._saga.Amount.Should().Be(expectAmount); //Act await activity.End(); //Assert this._saga.Name.Should().Be(expectName); this._saga.Amount.Should().Be(0); }
public void NewSaga_CalculateResultIsZero_WhenActivityOccurException() { //Arrange string expectName = "happyTesting"; int expectAmount = 0; int counter = 0; async Task action() => await Task.Run(() => counter ++); async Task compensaction() => await Task.Run(() => counter --); IActivity activity = this._saga.NewSaga("happyTesting") .Step("test", async() => { await action(); throw new Exception(); }) .Undo("reverse-test", compensaction); //Act Func <Task> doIt = async() => await activity.End(); //Assert doIt.Should().ThrowExactly <Exception>(); this._saga.Name.Should().Be(expectName); counter.Should().Be(expectAmount); }