Example #1
0
        public void OperationResult()
        {
            var operation = Operation.Create <int>(_methods.ReturnInt);

            Assert.AreEqual(operation.Result, 1);
            Assert.IsTrue(operation.Succeeded);
        }
Example #2
0
 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,
     });
 }
Example #3
0
 public static Operation Next(this Operation operation, Action process)
 {
     if (operation.Succeeded)
     {
         return(Operation.Create(process));
     }
     return(operation);
 }
Example #4
0
        public void OperationCreationFailure()
        {
            var operation = Operation.Create(() =>
            {
                throw new Exception("The Error");
            });

            Assert.IsFalse(operation.Succeeded);
            Assert.AreEqual(operation.Message, "The Error");
        }
Example #5
0
 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,
     });
 }
Example #6
0
 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
     });
 }
Example #7
0
 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,
     });
 }
Example #8
0
 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
     });
 }
Example #9
0
        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));
        }
Example #10
0
        public void OperationCreationSuccess()
        {
            var operation = Operation.Create(_methods.Print);

            Assert.IsTrue(operation.Succeeded);
        }
Example #11
0
        public void CreateSuccess()
        {
            var operation = Operation.Create(_methods.Void);

            Assert.IsTrue(operation.Succeeded);
        }