Example #1
0
        public async Task GetAllCoursesTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var courseRepository = new EfDeletableEntityRepository <Course>(new ApplicationDbContext(options.Options));

            var coursesToAdd = this.GetCourseData();

            foreach (var course in coursesToAdd)
            {
                await courseRepository.AddAsync(course);

                await courseRepository.SaveChangesAsync();
            }

            var mockUserCourseRepository = new Mock <IRepository <UserCourse> >();
            var mockConfiguration        = new Mock <IConfiguration>();
            var mockCategoryService      = new Mock <ICategoriesService>();
            var store           = new Mock <IUserStore <ApplicationUser> >();
            var mockUserManager = new Mock <UserManager <ApplicationUser> >(store.Object, null, null, null, null, null, null, null, null);

            var service = new CoursesService(courseRepository, mockUserCourseRepository.Object, mockConfiguration.Object, mockCategoryService.Object, mockUserManager.Object);

            AutoMapperConfig.RegisterMappings(typeof(AdminCourseViewModel).Assembly);

            var courses = service.GetAllCourses <AdminCourseViewModel>();

            Assert.Equal(4, courses.Count());
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         CoursesService coursesService = new CoursesService();
         repeaterCourses.DataSource = coursesService.GetAllCourses();
         repeaterCourses.DataBind();
     }
 }
Example #3
0
        public IActionResult Index(CoursesSortOrder?order, int page = 1)
        {
            var courses = coursesService.GetAllCourses();

            if (order.HasValue)
            {
                coursesService.SortCourses(ref courses, order.Value);
            }
            var viewData = new CoursesViewData
            {
                UserCoursesIds = coursesService.GetUserAssignedCourses(userManager.GetUserId(User)).Select(userCourse => userCourse.CourseID).ToList(),
                PagingInfo     = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = pageSize,
                    TotalItems   = courses.Count()
                }
            };

            viewData.Courses = courses.Skip(pageSize * (page - 1)).Take(pageSize).ToList();
            return(View(viewData));
        }
Example #4
0
        public IActionResult Announcements(
            [Bind(nameof(AdminAnnouncementsViewData.CourseType),
                  nameof(AdminAnnouncementsViewData.AuthorIdToDisplay),
                  nameof(AdminAnnouncementsViewData.CourseToDisplay),
                  nameof(AdminAnnouncementsViewData.Order))] AdminAnnouncementsViewData model,
            int page = 1)
        {
            var result        = model;
            var announcements = announcementsService.GetAllAnnouncements();

            result.UsersWithAnnouncements = announcementsService.GetUsersWithAnnouncements();
            result.Courses = coursesService.GetAllCourses();


            if (model.AuthorIdToDisplay != null)
            {
                announcementsService.FilterByAuthor(ref announcements, model.AuthorIdToDisplay);
            }
            if (model.CourseType.HasValue)
            {
                announcementsService.FilterByCourseType(ref announcements, model.CourseType.Value);
            }
            if (!string.IsNullOrEmpty(model.CourseToDisplay))
            {
                announcementsService.FilterByCourseName(ref announcements, model.CourseToDisplay);
            }
            announcementsService.SortAnnouncements(ref announcements, model.Order);

            result.Announcements = announcements;
            result.PagingInfo    = new PagingInfo
            {
                CurrentPage  = page,
                ItemsPerPage = pageSize,
                TotalItems   = result.Announcements.Count()
            };
            result.Announcements = result.Announcements.Skip((page - 1) * pageSize).Take(pageSize).ToList();
            return(View(result));
        }
Example #5
0
        public ActionResult Index()
        {
            string[] coursesNames = _coursesService.GetAllCourses();

            Course[] aggregatedCourses = _coursesService.GetAggregatedCourses();
            string[] teachers          = _teachersService.GetAllTeachers();

            Teacher[] aggregatedTeachers = _teachersService.GetAggregatedTeachers();

            var model = new BoardModel
            {
                Courses            = coursesNames,
                AggregatedCourses  = aggregatedCourses,
                Teachers           = teachers,
                AggregatedTeachers = aggregatedTeachers
            };

            return(View(model));
        }
Example #6
0
        public void GetAllCourses_ShouldReturn_EmptyCollection_IfIsEmpty()
        {
            var courses = new List <Course>().AsQueryable();

            var courseRepoMock = new Mock <IRepository <Course> >();

            courseRepoMock.Setup(d => d.All())
            .Returns(courses).Verifiable();

            var sut = new CoursesService(null, courseRepoMock.Object, null, Mapper);

            var actual   = sut.GetAllCourses();
            var expected = new List <CourseViewModel>().AsQueryable();

            Assert.Equal(expected, actual, new CourseViewModelComparer());

            courseRepoMock.Verify();
            courseRepoMock.Verify(d => d.AddAsync(It.IsAny <Course>()), Times.Never);
            courseRepoMock.Verify(d => d.SaveChangesAsync(), Times.Never);
        }
Example #7
0
        // GET: CourseManagement
        public ActionResult Index()
        {
            var allusers = _coursesService.GetAllCourses();

            return(View(allusers));
        }
Example #8
0
        public void GetAllCourses_ShouldReturn_All_CourseViewModels()
        {
            var coursesRepoBuilder = new CoursesRepositoryBuilder();
            var courseRepo         = coursesRepoBuilder
                                     .WithAll()
                                     .Build();

            var sut = new CoursesService(null, courseRepo, null, Mapper);

            var actual   = sut.GetAllCourses();
            var expected = new List <CourseViewModel>
            {
                new CourseViewModel
                {
                    Id                   = "1",
                    Image                = new byte[0],
                    Title                = "Drun",
                    Description          = "Drunnnnnnnnnnnnnnnnnn",
                    MaxCountParticipants = 4,
                    StartDate            = DateTime.Now.AddDays(3),
                    DurationOfDays       = 3,
                    Status               = Status.Practically,
                    Category             = Category.Climbing
                },
                new CourseViewModel
                {
                    Id                   = "2",
                    Image                = new byte[0],
                    Title                = "Brum",
                    Description          = "Brummmmmmmmmmmmm",
                    MaxCountParticipants = 10,
                    StartDate            = DateTime.Now.AddDays(2),
                    DurationOfDays       = 5,
                    Status               = Status.Theoretical,
                    Category             = Category.Cycling
                },
                new CourseViewModel
                {
                    Id                   = "3",
                    Image                = new byte[0],
                    Title                = "Mrun",
                    Description          = "Mrunnnnnnnnnnnnnnnnn",
                    MaxCountParticipants = 11,
                    StartDate            = DateTime.Now.AddDays(1),
                    DurationOfDays       = 7,
                    Status               = Status.Practically,
                    Category             = Category.Skiing
                },
                new CourseViewModel
                {
                    Id                   = "4",
                    Image                = new byte[0],
                    Title                = "Drun",
                    Description          = "Drunnnnnnnnnnnnnnnnnn",
                    MaxCountParticipants = 4,
                    StartDate            = DateTime.Now.AddDays(-3),
                    DurationOfDays       = 3,
                    CreatorId            = "7",
                    Status               = Status.Practically,
                    Category             = Category.Climbing
                }
            }.AsQueryable();

            Assert.Equal(expected, actual, new CourseViewModelComparer());

            coursesRepoBuilder.CoursesRepoMock.Verify();
            coursesRepoBuilder.CoursesRepoMock.Verify(d => d.AddAsync(It.IsAny <Course>()), Times.Never);
            coursesRepoBuilder.CoursesRepoMock.Verify(d => d.SaveChangesAsync(), Times.Never);
        }
Example #9
0
        public ActionResult Index()
        {
            var model = _coursesService.GetAllCourses();

            return(View(model));
        }
        public IHttpActionResult Get()
        {
            var allCourses = coursesService.GetAllCourses();

            return(this.Ok(allCourses));
        }