Ejemplo n.º 1
0
        public async Task should_return_exception_when_worksheet_invalid()
        {
            using (var stream = File.OpenRead(Environment.CurrentDirectory + "/Exception.xlsx"))
            {
                var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(Environment.CurrentDirectory + "/Exception.xlsx"));
                var controller = new LearnerController();
                Task Result() => controller.ImportLearners(file);

                await Assert.ThrowsAsync <NullReferenceException>(Result);
            }
        }
Ejemplo n.º 2
0
        public async Task should_import_learners()
        {
            using (var stream = File.OpenRead(Environment.CurrentDirectory + "/Sample.xlsx"))
            {
                var file       = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(Environment.CurrentDirectory + "/Sample.xlsx"));
                var controller = new LearnerController();
                var result     = await controller.ImportLearners(file);

                var returnOkResult = Assert.IsType <OkObjectResult>(result);
                Assert.Equal(9, returnOkResult.Value);
            }
        }
Ejemplo n.º 3
0
        public async Task should_return_bad_request_when_duplicate_column()
        {
            using (var stream = File.OpenRead(Environment.CurrentDirectory + "/Duplicate.xlsx"))
            {
                var file       = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(Environment.CurrentDirectory + "/Duplicate.xlsx"));
                var controller = new LearnerController();
                var result     = await controller.ImportLearners(file);

                var returnBadRequestResult = Assert.IsType <BadRequestObjectResult>(result);
                Assert.Equal("Duplicate column name", returnBadRequestResult.Value);
            }
        }
Ejemplo n.º 4
0
        public async Task should_return_bad_request_when_file_extensions_invalid()
        {
            using (var stream = File.OpenRead(Environment.CurrentDirectory + "/Test.xls"))
            {
                var file = new FormFile(stream, 0, stream.Length, null,
                                        Path.GetFileName(Environment.CurrentDirectory + "/Test.xls"));
                var controller = new LearnerController();
                var result     = await controller.ImportLearners(file);

                var returnBadRequestResult = Assert.IsType <BadRequestObjectResult>(result);
                Assert.Equal("File type not supported, please upload Excel Package", returnBadRequestResult.Value);
            }
        }
Ejemplo n.º 5
0
        public void Nonexisting_user_login()
        {
            using var scope = _factory.Services.CreateScope();
            var controller = new LearnerController(_factory.Services.GetRequiredService <IMapper>(),
                                                   scope.ServiceProvider.GetRequiredService <ILearnerService>());
            var loginSubmission = new LoginDTO {
                StudentIndex = "SA-1-2021"
            };

            var code = ((NotFoundObjectResult)controller.Login(loginSubmission).Result).StatusCode;

            code.ShouldBe(404);
        }
Ejemplo n.º 6
0
        public void Successfully_logins()
        {
            using var scope = _factory.Services.CreateScope();
            var controller = new LearnerController(_factory.Services.GetRequiredService <IMapper>(),
                                                   scope.ServiceProvider.GetRequiredService <ILearnerService>());
            var loginSubmission = new LoginDTO {
                StudentIndex = "SU-1-2021"
            };

            var learner = ((OkObjectResult)controller.Login(loginSubmission).Result).Value as LearnerDTO;

            learner.Id.ShouldBe(1);
        }
Ejemplo n.º 7
0
        public void Arrange()
        {
            var fixture = new Fixture();

            _request = fixture.Create <GetBatchLearnerRequest>();

            _response = fixture.Build <GetLearnerResponse>()
                        .With(r => r.ValidationErrors, new List <string>()).Create();

            _mockApiClient = new Mock <IApiClient>();
            _mockApiClient.Setup(c => c.GetLearner(It.IsAny <GetBatchLearnerRequest>())).ReturnsAsync(_response);

            _learnerController = new LearnerController(Mock.Of <ILogger <LearnerController> >(), Mock.Of <IHeaderInfo>(), _mockApiClient.Object);
        }