public void Download_WhenDownloadDataReturnsNullNoCsvFileGenerated()
        {
            ReportingBusiness.Setup(x => x.GetDownloadStream(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(new DownloadReport()));

            var generateReport = (StatusCodeResult)EnrichedEventController.Download(It.IsAny <string>(), It.IsAny <string>()).Result;

            AreEqual(generateReport.StatusCode, 500);
        }
Exemple #2
0
        public void Valid_Input_Data()
        {
            ReportController controller = new ReportController(new MonthReportGenerator());
            int year  = 2017;
            int month = 1;

            IActionResult result = controller.Download(year, month);

            Assert.IsTrue(result is FileContentResult);
        }
Exemple #3
0
        public void Unvalid_Input_Data()
        {
            ReportController controller = new ReportController(new MonthReportGenerator());
            int year1  = -1;
            int month1 = -1;

            IActionResult result1 = controller.Download(year1, month1);

            int year2  = DateTime.UtcNow.Year + 1;
            int month2 = 13;

            IActionResult result2 = controller.Download(year2, month2);

            Assert.IsTrue(result1 is ContentResult);
            Assert.IsTrue(((ContentResult)result1).Content == "Неверные входные данные");

            Assert.IsTrue(result2 is ContentResult);
            Assert.IsTrue(((ContentResult)result2).Content == "Неверные входные данные");
        }
Exemple #4
0
        public async Task TestDownload()
        {
            var dbDataLoader = new MockDBDataLoader();
            var controller   = new ReportController(dbDataLoader);
            var result       = await controller.Download(2017, 1);

            var content = result as FileContentResult;

            Assert.NotNull(result);
            Assert.NotNull(content);
            Assert.Equal("application/octet-stream", content.ContentType);
            Assert.Equal("report.txt", content.FileDownloadName);
            Assert.NotNull(content.FileContents);
            Assert.Equal(1122, content.FileContents.Length);

            var data         = Encoding.UTF8.GetString(content.FileContents, 0, content.FileContents.Length);
            var expectedData = "Январь 2017\r\n--------------------------------------------\r\nФинОтдел\r\nАндрей Сергеевич Бубнов         70000р\r\nГригорий Евсеевич Зиновьев         65000р\r\nЯков Михайлович Свердлов         80000р\r\nАлексей Иванович Рыков         90000р\r\nВсего по отделу 305000р\r\n--------------------------------------------\r\nБухгалтерия\r\nВасилий Васильевич Кузнецов         50000р\r\nДемьян Сергеевич Коротченко         55000р\r\nМихаил Андреевич Суслов         35000р\r\nВсего по отделу 140000р\r\n--------------------------------------------\r\nИТ\r\nФрол Романович Козлов         90000р\r\nДмитрий Степанович Полянски         120000р\r\nАндрей Павлович Кириленко         110000р\r\nАрвид Янович Пельше         120000р\r\nВсего по отделу 440000р\r\n--------------------------------------------\r\nВсего по предприятию 885000р";

            Assert.Equal(expectedData, data);
        }
Exemple #5
0
        public async void Download_WithNotValidDate_ReturnBadRequestTest()
        {
            int notValidYear  = 10000;
            int notValidMonth = 15;

            var mockLogg = Mock.Of <ILogger <ReportController> >();

            var mockEmployeeService = new Mock <IEmployeeService>();

            mockEmployeeService.Setup(s => s.GetEmployeesWithSalaryAsync(notValidYear, notValidMonth))
            .Returns(Task.FromResult(GetTestEmployeesWithSalary()));

            var mockReportService = new Mock <ReportHelperService>(mockEmployeeService.Object).Object;

            var controller = new ReportController(mockReportService, mockLogg);

            var result = await controller.Download(notValidYear, notValidMonth);

            Assert.IsType <BadRequestResult>(result);
        }
Exemple #6
0
        public async void Download_WithValidDate_ReturnFileTest()
        {
            int validYear  = 2018;
            int validMonth = 2;

            var mockLogg = Mock.Of <ILogger <ReportController> >();

            var mockEmployeeService = new Mock <IEmployeeService>();

            mockEmployeeService.Setup(s => s.GetEmployeesWithSalaryAsync(validYear, validMonth))
            .Returns(Task.FromResult(GetTestEmployeesWithSalary()));

            var mockReportService = new Mock <ReportHelperService>(mockEmployeeService.Object).Object;

            var controller = new ReportController(mockReportService, mockLogg);

            var result = await controller.Download(validYear, validMonth);

            Assert.IsType <FileContentResult>(result);
            Assert.True(((FileContentResult)result).FileContents.Length > 0);
        }