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

            Assert.AreEqual(operation.Result, 1);
            Assert.IsTrue(operation.Succeeded);
        }
예제 #2
0
파일: Linq.cs 프로젝트: odytrice/Operation
 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,
     });
 }
예제 #3
0
 public static Operation Next(this Operation operation, Action process)
 {
     if (operation.Succeeded)
     {
         return(Operation.Create(process));
     }
     return(operation);
 }
예제 #4
0
        public void OperationCreationFailure()
        {
            var operation = Operation.Create(() =>
            {
                throw new Exception("The Error");
            });

            Assert.IsFalse(operation.Succeeded);
            Assert.AreEqual(operation.Message, "The Error");
        }
예제 #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,
     });
 }
예제 #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
     });
 }
예제 #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,
     });
 }
예제 #8
0
파일: Linq.cs 프로젝트: odytrice/Operation
 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
     });
 }
예제 #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));
        }
예제 #10
0
        public void OperationCreationSuccess()
        {
            var operation = Operation.Create(_methods.Print);

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

            Assert.IsTrue(operation.Succeeded);
        }