public void Init() { _service = new FaultlessExecutionService(logger: null); _successfulActionCode = () => { _numberOfTimesActionCodeRan++; return(Task.Delay(1)); }; _failActionCode = () => { _numberOfTimesActionCodeRan++; throw new ApplicationException(); }; _ifcodeTrue = (a) => { _numberOfTimesIfCodeRan++; return(true); }; _ifcodeFalse = (a) => { _numberOfTimesIfCodeRan++; return(false); }; }
public void AsyncChainTest(bool actionIsSuccessful) { //************* arrange ****************** int numtimesActionRan = 0; Action a = () => { numtimesActionRan++; if (!actionIsSuccessful) { throw new ApplicationException(); } }; bool exceptionRan = false; bool successRan = false; var service = new FaultlessExecutionService(logger: null); //************* act ****************** service.TryExecuteSyncAsAsync(a) .OnExceptionAsync((e) => exceptionRan = true) .OnSuccessAsync(() => successRan = true) .Wait(); //************* assert ****************** numtimesActionRan.Should().Be(1); if (actionIsSuccessful) { exceptionRan.Should().BeFalse(); successRan.Should().BeTrue(); } else { exceptionRan.Should().BeTrue(); successRan.Should().BeFalse(); } }