Ejemplo 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));
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
 }
Ejemplo n.º 5
0
 public Report CreateCustomerReport(Customer customer)
 {
     return new Report(customer.Email, $"This is the report for {customer.Email}!");
 }
Ejemplo 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));
 }