public void OperationResult() { var operation = Operation.Create <int>(_methods.ReturnInt); Assert.AreEqual(operation.Result, 1); Assert.IsTrue(operation.Succeeded); }
public static Operation <V> SelectMany <T, U, V>(this Operation <T> operation, Func <T, Operation <U> > process, Func <T, U, V> projection) { if (operation.Succeeded) { var op2 = process(operation.Result); if (op2.Succeeded) { return(Operation.Create(() => projection(operation.Result, op2.Result))); } else { return(new Operation <V>(op2.GetException()) { Succeeded = false, Message = op2.Message, Result = default(V) }); } } return(new Operation <V>(operation.GetException()) { Succeeded = false, Result = default(V), Message = operation.Message, }); }
public static Operation Next(this Operation operation, Action process) { if (operation.Succeeded) { return(Operation.Create(process)); } return(operation); }
public void OperationCreationFailure() { var operation = Operation.Create(() => { throw new Exception("The Error"); }); Assert.IsFalse(operation.Succeeded); Assert.AreEqual(operation.Message, "The Error"); }
public static Operation Next <T>(this Operation <T> operation, Action <T> process) { if (operation.Succeeded) { return(Operation.Create(() => process(operation.Result))); } return(new Operation() { Message = operation.Message, Succeeded = operation.Succeeded, }); }
public static Operation <U> Next <T, U>(this Operation <T> operation, Func <T, U> process) { if (operation.Succeeded) { return(Operation.Create(() => process(operation.Result))); } return(new Operation <U>(operation.GetException()) { Succeeded = false, Result = default(U), Message = operation.Message }); }
public static Operation <T> Next <T>(this Operation operation, Func <T> process) { if (operation.Succeeded) { return(Operation.Create(process)); } return(new Operation <T>(operation.GetException()) { Succeeded = false, Result = default(T), Message = operation.Message, }); }
public static Operation <IEnumerable <V> > SelectMany <T, U, V>(this Operation <T> operation, Func <T, IEnumerable <U> > process, Func <T, U, V> projection) { if (operation.Succeeded) { var op2 = Operation.Create(() => process(operation.Result)); return(op2.Next((enumerable) => enumerable.Select(x => projection(operation.Result, x)))); } return(new Operation <IEnumerable <V> >(operation.GetException()) { Succeeded = false, Result = default(IEnumerable <V>), Message = operation.Message }); }
public void OperationResultFailure() { var cond = true; var operation = Operation.Create(() => { if (cond) { throw new Exception("The Error"); } return(1); }); Assert.IsFalse(operation.Succeeded); Assert.AreEqual(operation.Message, "The Error"); Assert.AreEqual(operation.Result, default(int)); }
public void OperationCreationSuccess() { var operation = Operation.Create(_methods.Print); Assert.IsTrue(operation.Succeeded); }
public void CreateSuccess() { var operation = Operation.Create(_methods.Void); Assert.IsTrue(operation.Succeeded); }