コード例 #1
0
        public void RunProcessingShouldSendMultipleCorrectEmailBodies()
        {
            Action <string>              log          = m => { };
            Func <string, string>        createReport = customer => customer + " done";
            Func <IEnumerable <string> > getCustomers = () => new[] { "ellie", "bob" };

            // closure
            var actualBodyList = new List <string>();
            Action <string, string> sendEmail = (toAddress, body) => actualBodyList.Add(body);

            Functional2.RunProcessing(log, getCustomers, createReport, sendEmail);

            Assert.Equal("ellie done", actualBodyList[0]);
            Assert.Equal("bob done", actualBodyList[1]);
        }
コード例 #2
0
        public void RunProcessingShouldGetCustomerEllieAndSendCorrectEmailBody()
        {
            // mocking out RunProcessing's 4 dependencies
            // Action is a delegate which doesn't return a value
            // Passing in an anonymous function which does nothing
            Action <string> log = x => { };

            // Func input of a string, delegating to anonymous function,
            // returning ellie done!
            Func <string, string> createReport = x => "ellie done";

            // Func with no input, delegating to an anonymous function,
            // returning an array of 1 string - ellie
            IEnumerable <string>         actualCustomers = new List <string>();
            Func <IEnumerable <string> > getCustomers    = () =>
            {
                var customers = new[] { "ellie" };
                actualCustomers = customers;
                return(customers);
            };

            // Action is a delegate - doesn't return anything
            // we're going to test whether RunProcessing calls createReport
            // which sets the body to "ellie done"

            // actualBody is a clousre
            var actualBody = "";
            Action <string, string> sendEmail = (toAddress, body) => actualBody = body;

            // compose.  Action is a delegate - doesn't return anything
            Action runProcessing = () => Functional2.RunProcessing(log, getCustomers, createReport, sendEmail);

            runProcessing();

            // Testing if RunProcessing getsCustomer
            Assert.Equal("ellie", actualCustomers.ToList()[0]);
            // then runs the sendEmail function properly
            Assert.Equal("ellie done", actualBody);
        }
コード例 #3
0
        public void RunProcessingShouldLog()
        {
            var listOfLogEntries = new List <string>();
            // Action is a delegate - doesn't return.
            Action <string> log = m => listOfLogEntries.Add(m);

            // Func input of a string, returns string..
            Func <string, string> createReport = x => x + " report test";

            // Func with no input, delegating to an anonymous function,
            // returning an array of 1 string
            Func <IEnumerable <string> > getCustomers = () => new[] { "ellie" };

            Action <string, string> sendEmail = (toAddress, body) => { };

            Functional2.RunProcessing(log, getCustomers, createReport, sendEmail);

            // assert logging in working
            Assert.Equal(3, listOfLogEntries.Count);
            Assert.Equal("test", listOfLogEntries[0]);
            Assert.Equal("ellie", listOfLogEntries[1]);
            Assert.Equal("ellie report test", listOfLogEntries[2]);
        }