public async Task ShouldReturnNotFoundWhenPassedNull_GetModulesByYear()
        {
            var mockRepo = new Mock <IDataRepository>();
            ModulesController controller = new ModulesController(mockRepo.Object);
            var result = await controller.GetModulesByYear(null);

            Assert.IsInstanceOfType(result.Result, typeof(NotFoundResult));
        }
        public async Task ShouldReturnBadRequestWhenPassedInvalidYear_GetModulesByYear()
        {
            string futureYear = "badyear";
            var    mockRepo   = new Mock <IDataRepository>();

            ModulesController controller = new ModulesController(mockRepo.Object);

            var result = await controller.GetModulesByYear(futureYear);

            Assert.IsInstanceOfType(result.Result, typeof(BadRequestResult));
        }
        public async Task ShouldReturnOkWithEmptyListIfNoModulesForGivenYear_GetModulesByYear()
        {
            string        futureYear  = "2040";
            List <Module> emptyResult = new List <Module>();
            var           mockRepo    = new Mock <IDataRepository>();

            mockRepo.Setup(repo => repo.ModulesByYearListAsync(futureYear)).
            ReturnsAsync(emptyResult);

            ModulesController controller = new ModulesController(mockRepo.Object);

            var result = await controller.GetModulesByYear(futureYear);

            Assert.IsInstanceOfType(result.Result, typeof(OkObjectResult));

            var okResult = result.Result as OkObjectResult;
            var modules  = okResult.Value as List <Module>;

            Assert.AreEqual(0, modules.Count);
        }
        public async Task ShouldGetModulesForValidYear_GetModulesByYear()
        {
            string year     = "2020";
            var    mockRepo = new Mock <IDataRepository>();

            mockRepo.Setup(repo => repo.ModulesByYearListAsync(year)).
            ReturnsAsync(ModulesInYear2020());

            ModulesController controller = new ModulesController(mockRepo.Object);
            var result = await controller.GetModulesByYear(year);

            Assert.IsInstanceOfType(result.Result, typeof(OkObjectResult));

            var okResult = result.Result as OkObjectResult;
            var modules  = okResult.Value as List <Module>;

            Assert.AreEqual(2, modules.Count);

            foreach (Module m in modules)
            {
                Assert.AreEqual("2020", m.Year);
            }
        }