Esempio n. 1
0
        public async Task SendSalesReportEmailAsync_OrdersIsEmpty_ShouldNotSendSalesReport()
        {
            // Arrange
            Mock <IOrderService> mockOrderService = new Mock <IOrderService>();

            mockOrderService
            .Setup(os => os.Get(It.IsAny <OrderSearchCriteria>()))
            .Returns(new Collection <Order>());

            Mock <IUserService> mockUserService = new Mock <IUserService>();

            Mock <ISalesReportBuilder> mockSalesReportBuilder = new Mock <ISalesReportBuilder>();

            IOrderService       orderService       = mockOrderService.Object;
            IUserService        userService        = mockUserService.Object;
            ISalesReportBuilder salesReportBuilder = mockSalesReportBuilder.Object;

            Mock <IMessageClient> mockMessageClient = new Mock <IMessageClient>();

            mockMessageClient
            .Setup(mc => mc.SendAsync(It.IsAny <TestApp.Mocking.User>(), It.IsAny <TestApp.Mocking.User>(), It.IsAny <SalesReport>())).Verifiable();


            IMessageClient messageClient = mockMessageClient.Object;

            ReportService reportService = new ReportService(orderService, userService, salesReportBuilder, messageClient);

            // Act
            await reportService.SendSalesReportEmailAsync(DateTime.Now);

            // Assert
            mockMessageClient.Verify(mc => mc.SendAsync(It.IsAny <Mocking.User>(), It.IsAny <Mocking.User>(), It.IsAny <SalesReport>()), Times.Never);
        }
Esempio n. 2
0
 public ReportService(IOrderService orderService,
                      ISalesReportBuilder salesReportBuilder,
                      IUserService userService)
 {
     this.orderService       = orderService;
     this.salesReportBuilder = salesReportBuilder;
     this.userService        = userService;
 }
Esempio n. 3
0
 public ReportService(
     IOrderService orderService,
     IUserService userService,
     ISalesReportBuilder salesReportBuilder,
     IMessageClient client)
 {
     this.orderService       = orderService;
     this.userService        = userService;
     this.salesReportBuilder = salesReportBuilder;
     this.client             = client;
 }
Esempio n. 4
0
 public ReportService(
     IOrderService orderService,
     ISendGridClient sendGridClient,
     IUserService userService,
     ILogger logger,
     ISalesReportBuilder salesReportBuilder)
 {
     this.orderService       = orderService;
     this.client             = sendGridClient;
     this.userService        = userService;
     this.logger             = logger;
     this.salesReportBuilder = salesReportBuilder;
 }
Esempio n. 5
0
        public async void SendSalesReportEmailAsync_OrdersIsNotEmpty_ShouldSendSalesReport()
        {
            // Arrange
            Mock <IOrderService> mockOrderService = new Mock <IOrderService>();

            mockOrderService
            .Setup(os => os.Get(It.IsAny <OrderSearchCriteria>()))
            .Returns(new Collection <Order> {
                new Order {
                    OrderedDate = DateTime.Now.AddDays(-3)
                }
            });

            Mock <IUserService> mockUserService = new Mock <IUserService>();

            mockUserService.Setup(us => us.GetBossesRecipients())
            .Returns(new List <Mocking.User>()
            {
                new Mocking.Employee()
            });

            mockUserService.Setup(us => us.GetBot())
            .Returns(new Mocking.Bot());

            Mock <ISalesReportBuilder> mockSalesReportBuilder = new Mock <ISalesReportBuilder>();

            IOrderService       orderService       = mockOrderService.Object;
            IUserService        userService        = mockUserService.Object;
            ISalesReportBuilder salesReportBuilder = mockSalesReportBuilder.Object;

            Mock <IMessageClient> mockMessageClient = new Mock <IMessageClient>();

            mockMessageClient
            .Setup(mc => mc.SendAsync(It.IsAny <TestApp.Mocking.User>(), It.IsAny <TestApp.Mocking.User>(), It.IsAny <SalesReport>())).Verifiable();


            IMessageClient messageClient = mockMessageClient.Object;

            ReportService reportService = new ReportService(orderService, userService, salesReportBuilder, messageClient);

            // Act
            await reportService.SendSalesReportEmailAsync(DateTime.Now);

            // Assert
            mockMessageClient.Verify(mc => mc.SendAsync(It.IsAny <Mocking.User>(), It.IsAny <Mocking.User>(), It.IsAny <SalesReport>()), Times.AtLeast(1));
        }