示例#1
0
        public async Task GetRevenueForecast_NotFound()
        {
            // Arrange
            var mockLoggingService = new Mock <IDatabaseAccessService>();

            mockLoggingService.Setup(service => service.GetForecastAsync(It.IsAny <string>()))
            .Throws(new ItemNotFoundException("Entity"));
            var mockRevenueForecastService = new Mock <IRevenueForecastService>();
            var mockExportService          = new Mock <IForecastExportService>();
            var controller = new RevenueForecastController(mockLoggingService.Object, mockRevenueForecastService.Object, _mapper, mockExportService.Object);

            // Act & Assert
            await Assert.ThrowsAsync <ItemNotFoundException>(() => controller.GetForecast("123"));
        }
示例#2
0
        public async void GetRevenueForecast_Ok()
        {
            // Arrange
            var mockLoggingService = new Mock <IDatabaseAccessService>();

            mockLoggingService.Setup(service => service.GetForecastAsync(It.IsAny <string>()))
            .ReturnsAsync(new RevenueForecasts());
            var mockRevenueForecastService = new Mock <IRevenueForecastService>();
            var mockExportService          = new Mock <IForecastExportService>();
            var controller = new RevenueForecastController(mockLoggingService.Object, mockRevenueForecastService.Object, _mapper, mockExportService.Object);

            // Act
            var result = await controller.GetForecast("123");

            // Assert
            if (result is OkObjectResult objectResult)
            {
                Assert.IsType <RevenueForecastViewModel>(objectResult.Value as RevenueForecastViewModel);
            }
            else
            {
                Assert.True(false, "failed to receive revenue forecast as result");
            }
        }