Esempio n. 1
0
        public void ObjectOrientedTest()
        {
            // Arrange
            var customerDataMock = new Mock<ICustomerData>();
            var reportBuilderMock = new Mock<IReportBuilder>();
            var emailerMock = new Mock<IEmailer>();

            var expectedCustomer = new Customer("*****@*****.**");
            var expectedReportBody = "the report body";

            customerDataMock.Setup(x => x.GetCustomersForCustomerReport())
                .Returns(new[] { expectedCustomer });

            reportBuilderMock.Setup(x => x.CreateCustomerReport(expectedCustomer))
                .Returns(new Report(expectedCustomer.Email, expectedReportBody));

            var sut = new ReportingService(
                customerDataMock.Object,
                reportBuilderMock.Object,
                emailerMock.Object);

            // Act
            sut.RunCustomerReportBatch();

            // Assert
            emailerMock.Verify(x => x.Send(expectedCustomer.Email, expectedReportBody));
        }
Esempio n. 2
0
        public void FunctionalTest()
        {
            // arrange
            var expectedCustomer = new Customer("*****@*****.**");
            var expectedReportBody = "the report body";

            // this is creating a closure, as if we are just creating a Function that returns a list of customers
            // not acutally running it.
            // so when this goes out of scope (ie if we return IEnumerable<Customer> from Functional test
            // will exptectedCustomer still be [email protected]?? yes
            // because the variable has been closed over.
            Func<IEnumerable<Customer>> getCustomersForCustomerReport  =
                () => new[] {expectedCustomer};

            Func<Customer, Report> createCustomerReport =
                customer => new Report(expectedCustomer.Email, expectedReportBody);

            var actualToAddress = "";
            var actualBody = "";

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

            // act
            Functional.RunCustomerReportBatch(getCustomersForCustomerReport, createCustomerReport, sendEmail);

            // asserting off sendEmail function
            Assert.Equal(expectedCustomer.Email, actualToAddress);
            Assert.Equal(expectedReportBody, actualBody);
        }
Esempio n. 3
0
        public void FunctionalTest()
        {
            // arrange
            var expectedCustomer = new Customer("*****@*****.**");
            var expectedReportBody = "the report body";

            Func<IEnumerable<Customer>> getCustomersForCustomerReport  =
                () => new[] {expectedCustomer};

            Func<Customer, Report> createCustomerReport =
                customer => new Report(expectedCustomer.Email, expectedReportBody);

            var actualToAddress = "";
            var actualBody = "";

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

            // act
            Functional.RunCustomerReportBatch(getCustomersForCustomerReport, createCustomerReport, sendEmail);

            // assert
            Assert.Equal(expectedCustomer.Email, actualToAddress);
            Assert.Equal(expectedReportBody, actualBody);
        }
Esempio n. 4
0
 public Report CreateCustomerReport(Customer customer)
 {
     // C#6 string interpolation
     //var body = $"This is the report for {customer.Email}!";
     string body = String.Format("This is the report for {0}!", customer.Email);
     return new Report(customer.Email, body);
 }
 public Report CreateCustomerReport(Customer customer)
 {
     return new Report(customer.Email, $"This is the report for {customer.Email}!");
 }
Esempio n. 6
0
 public static Report CreateCustomerReport(Customer customer)
 {
     //return new Report(customer.Email, $"This is the report for {customer.Email}!");
     return new Report(customer.Email, String.Format("This is the report for {0}!", customer.Email));
 }