Ejemplo n.º 1
0
        public void RunChainOfResponsibility()
        {
            _approver.Approve(new Purchase(number: 2034, amount: 350.00, purpose: "Assets"));

            _approver.Approve(new Purchase(number: 2035, amount: 32590.10, purpose: "Project X"));

            _approver.Approve(new Purchase(number: 2036, amount: 122100.00, purpose: "Project Y"));

            // Wait for user
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        private void RequestApproval(double amount)
        {
            string approver = null;

            OrderItems.Add(approverChain.Approve(amount, ref approver) ?
                           $"Expense of {amount} € was approved by {approver}" :
                           $"Expense of {amount} € was not approved");
        }
Ejemplo n.º 3
0
 public bool Approve(double amount, ref string approvedBy)
 {
     if (current.Approve(amount, ref approvedBy))
     {
         return(true);
     }
     return(next.Approve(amount, ref approvedBy));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Assert that the serialized <paramref name="subject" /> is equal to it's approved file.
        /// </summary>
        /// <param name="approver">The approver.</param>
        /// <param name="subject">The subject.</param>
        /// <param name="testParameters">The test parameters supplied by parameterized test.</param>
        /// <param name="fileExtension">The file extension (with or without a dot).</param>
        /// <param name="reporter">The reporter.</param>
        /// <param name="fileResolver">The file resolver.</param>
        /// <exception cref="Acklann.Diffa.Exceptions.ResultNotApprovedException">The subject did not match the approved-file.</exception>
        public static void Approve(IApprover approver, object subject, object[] testParameters, string fileExtension = ".txt", IReporter reporter = default, IFileResolver fileResolver = default)
        {
            var contextBuilder = new StackTraceParser();

            if (fileResolver == null)
            {
                fileResolver = new ContextualFileResolver(contextBuilder);
            }

            string resultFile   = fileResolver.GetResultFilePath(fileExtension, testParameters);
            string approvedFile = fileResolver.GetApprovedFilePath(fileExtension, testParameters);

            if (approver.Approve(subject, resultFile, approvedFile, out string reasonWhyItWasNotApproved) == false)
            {
                if (_shouldReport)
                {
                    if (reporter == null)
                    {
                        ReporterAttribute attribute = contextBuilder.Context.ReporterAttribute;
                        if (attribute?.Reporter == null)
                        {
                            reporter = _reporterFactory.GetFirstAvailableReporter(attribute.ShouldInterrupt);
                        }
                        else
                        {
                            reporter = (IReporter)Activator.CreateInstance(attribute.Reporter, args: attribute.ShouldInterrupt);
                        }
                    }

                    if (reporter.Launch(resultFile, approvedFile))
                    {
                        // Checking the results again because the user may have updated the approved file when the reporter was launched.
                        if (approver.Approve(subject, resultFile, approvedFile, out reasonWhyItWasNotApproved))
                        {
                            return;
                        }
                    }
                }

                throw new ResultNotApprovedException(ExceptionMessage.GetResultWasNotApproved(resultFile, approvedFile, reasonWhyItWasNotApproved));
            }
        }
Ejemplo n.º 5
0
        public ApprovalState Approve(decimal ammount)
        {
            var result = _approver.Approve(ammount);

            if (result == ApprovalState.LimitReached)
            {
                return(_next.Approve(ammount));
            }

            return(result);
        }
Ejemplo n.º 6
0
        public static void Main(string[] args)
        {
            var employee = new Employee("Forhad", 7);

            IApprover handler = CreateChain();

            Response response = handler.Approve(employee);

            if (response == Response.Approved)
            {
                Console.WriteLine("Have A nice Journey Mr:{0}", employee.Name);
            }
            else if (response == Response.Denied)
            {
                Console.WriteLine("Sorry Mr:{0} We are busy now", employee.Name);
            }
            Console.ReadLine();
        }
Ejemplo n.º 7
0
        public static void NotifyApprove(this IApprover approver, double amount)
        {
            string _ = "";

            approver.Approve(amount, ref _);
        }