Esempio n. 1
0
        public async Task GetLessonsByGroup_Test()
        {
            var mock = new Mock <IRepository <Lesson> >();

            int groupId = 2;
            var lessons = new List <Lesson>
            {
                new Lesson {
                    Id = 1, LessonGroups = new List <LessonGroup> {
                        new LessonGroup {
                            GroupId = groupId
                        }
                    }
                }
            };

            mock.Setup(foo => foo.GetAsync(It.IsAny <Expression <Func <Lesson, bool> > >()))
            .ReturnsAsync(() => lessons);

            var obj        = mock.Object;
            var service    = new LessonsService(obj);
            var mockResult = await service.GetLessonsByGroupAsync(groupId);

            Assert.AreEqual(groupId, lessons.First().LessonGroups.First().GroupId);
        }
Esempio n. 2
0
        public async Task Create_LessonIsValid_ShouldCreateNewLesson()
        {
            // arrange
            var fixture          = new Fixture();
            var expectedLessonId = fixture.Create <int>();
            var newLesson        = fixture.Create <Lesson>();

            var lessonsRepositoryMock = new Mock <ILessonsRepository>();
            var service = new LessonsService(lessonsRepositoryMock.Object);

            lessonsRepositoryMock
            .Setup(x => x.Add(newLesson))
            .ReturnsAsync(expectedLessonId);

            lessonsRepositoryMock
            .Setup(x => x.Get(newLesson.YouTubeBroadcastId))
            .ReturnsAsync(() => null);

            // act
            var createdLessonId = await service.Create(newLesson);

            // assert
            createdLessonId.Should().Be(expectedLessonId);

            lessonsRepositoryMock.Verify(x => x.Add(newLesson), Times.Once);
            lessonsRepositoryMock.Verify(x => x.Get(newLesson.YouTubeBroadcastId), Times.Once);
        }
Esempio n. 3
0
        public async Task DeleteLessonTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var lessonsRepository = new EfDeletableEntityRepository <Lesson>(new ApplicationDbContext(options.Options));

            foreach (var item in this.GetLessonData())
            {
                await lessonsRepository.AddAsync(item);

                await lessonsRepository.SaveChangesAsync();
            }

            var mockUserLessonRepository = new Mock <IRepository <UserLesson> >();
            var courseRepository         = new EfDeletableEntityRepository <Course>(new ApplicationDbContext(options.Options));

            foreach (var item in this.GetCourseData())
            {
                await courseRepository.AddAsync(item);

                await courseRepository.SaveChangesAsync();
            }

            var service = new LessonsService(lessonsRepository, mockUserLessonRepository.Object, courseRepository);
            await service.DeleteLesson("1", "User1");

            await service.DeleteLesson("3", "User2");

            var lessons = lessonsRepository.All();

            Assert.Equal(3, lessons.Count());
        }
Esempio n. 4
0
        public async Task GetCompletedLessonsTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var lessonRepository = new EfDeletableEntityRepository <Lesson>(new ApplicationDbContext(options.Options));

            foreach (var lesson in this.GetLessonData())
            {
                await lessonRepository.AddAsync(lesson);

                await lessonRepository.SaveChangesAsync();
            }

            var mockCourseRepository = new Mock <IDeletableEntityRepository <Course> >();
            var userLessonRepository = new EfRepository <UserLesson>(new ApplicationDbContext(options.Options));
            var service = new LessonsService(lessonRepository, userLessonRepository, mockCourseRepository.Object);
            await service.CreateUserLesson("User1", "1");

            await service.CreateUserLesson("User1", "2");

            await service.CreateUserLesson("User2", "2");

            var lessonsPassed = service.GetCompletedLessons("course1", "User1");

            Assert.Equal(2, lessonsPassed);
        }
Esempio n. 5
0
        public virtual JsonResult CanDelete(long id)
        {
            var lesson = LessonsService.GetById(id);

            if (lesson.UserId == System.Web.HttpContext.Current.User.Identity.GetUserId())
            {
                return(Json(true, JsonRequestBehavior.AllowGet));
            }
            return(Json(false, JsonRequestBehavior.AllowGet));
        }
Esempio n. 6
0
        public virtual ActionResult CreateLesson(LessonDTO lesson)
        {
            var entity = Mapper.Map <Lesson>(lesson);

            if (lesson.start >= DateTime.Now)
            {
                LessonsService.Add(entity, System.Web.HttpContext.Current.User.Identity.GetUserId());
                return(Json(true));
            }
            return(Json(false));
        }
Esempio n. 7
0
        public async Task CreateUserLessonTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var mockLessonRepository = new Mock <IDeletableEntityRepository <Lesson> >();
            var mockCourseRepository = new Mock <IDeletableEntityRepository <Course> >();
            var userLessonRepository = new EfRepository <UserLesson>(new ApplicationDbContext(options.Options));
            var service = new LessonsService(mockLessonRepository.Object, userLessonRepository, mockCourseRepository.Object);
            await service.CreateUserLesson("User1", "1");

            await service.CreateUserLesson("User2", "2");

            var userLessons = userLessonRepository.All();

            Assert.Equal(2, userLessons.Count());
        }
Esempio n. 8
0
        public async Task CreateLessonTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var lessonsRepository = new EfDeletableEntityRepository <Lesson>(new ApplicationDbContext(options.Options));

            var mockUserLessonRepository = new Mock <IRepository <UserLesson> >();
            var mockCourseRepository     = new Mock <IDeletableEntityRepository <Course> >();

            var service = new LessonsService(lessonsRepository, mockUserLessonRepository.Object, mockCourseRepository.Object);
            await service.CreateLessonAsync("Lesson1", "Descriptionnnnnnn", "1");

            await service.CreateLessonAsync("Lesson2", "Descriptionn234nnnnn", "1");

            await service.CreateLessonAsync("Lesson3", "Descript234onnnnnnn", "2");

            var lessons = lessonsRepository.All();

            Assert.Equal(3, lessons.Count());
        }
Esempio n. 9
0
        public async Task GetLessonNameTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var lessonsRepository = new EfDeletableEntityRepository <Lesson>(new ApplicationDbContext(options.Options));

            foreach (var item in this.GetLessonData())
            {
                await lessonsRepository.AddAsync(item);

                await lessonsRepository.SaveChangesAsync();
            }

            var mockUserLessonRepository = new Mock <IRepository <UserLesson> >();
            var mockCourseRepository     = new Mock <IDeletableEntityRepository <Course> >();
            var service     = new LessonsService(lessonsRepository, mockUserLessonRepository.Object, mockCourseRepository.Object);
            var lessonName  = service.GetLessonName("1");
            var lessonName2 = service.GetLessonName("2");

            Assert.Equal("Lesson 1", lessonName);
            Assert.Equal("Lesson 2", lessonName2);
        }
Esempio n. 10
0
        public async Task GetLessonsGenericTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var lessonsRepository = new EfDeletableEntityRepository <Lesson>(new ApplicationDbContext(options.Options));

            foreach (var lesson in this.GetLessonData())
            {
                await lessonsRepository.AddAsync(lesson);

                await lessonsRepository.SaveChangesAsync();
            }

            var mockUserLessonRepository = new Mock <IRepository <UserLesson> >();
            var mockCourseRepository     = new Mock <IDeletableEntityRepository <Course> >();

            AutoMapperConfig.RegisterMappings(typeof(StudyLessonViewModel).Assembly);
            var service = new LessonsService(lessonsRepository, mockUserLessonRepository.Object, mockCourseRepository.Object);
            var lessons = service.GetLessons <StudyLessonViewModel>("course1");

            Assert.Equal(2, lessons.Count());
        }
Esempio n. 11
0
        public async Task GetLessons_Test()
        {
            var mock = new Mock <IRepository <Lesson> >();

            var lessons = new List <Lesson>
            {
                new Lesson {
                    Id = 1
                },
                new Lesson {
                    Id = 2
                }
            };

            mock.Setup(foo => foo.GetAllAsync()).ReturnsAsync(() => lessons);

            var obj        = mock.Object;
            var service    = new LessonsService(obj);
            var mockResult = await service.GetLessonsAsync();

            Assert.AreEqual(lessons, mockResult);
        }
Esempio n. 12
0
        public virtual JsonResult GetEvents()
        {
            var lessonsResponse = new List <LessonResponse>();
            var lessons         = LessonsService.GetList();

            foreach (var item in lessons)
            {
                var user     = UserService.Get(item.UserId);
                var userName = $"{user.FirstName} {user.LastName}";
                var color    = user.Color;
                lessonsResponse.Add(new LessonResponse
                {
                    id       = item.Id,
                    editable = false,
                    title    = $"{userName} - {item.Title}",
                    start    = item.Start.ToString("s"),
                    end      = item.End.Value.ToString("s"),
                    color    = color
                });
            }
            return(Json(lessonsResponse, JsonRequestBehavior.AllowGet));
        }
Esempio n. 13
0
        public async Task EditLessonTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var lessonsRepository = new EfDeletableEntityRepository <Lesson>(new ApplicationDbContext(options.Options));

            foreach (var item in this.GetLessonData())
            {
                await lessonsRepository.AddAsync(item);

                await lessonsRepository.SaveChangesAsync();
            }

            var mockUserLessonRepository = new Mock <IRepository <UserLesson> >();
            var courseRepository         = new EfDeletableEntityRepository <Course>(new ApplicationDbContext(options.Options));

            foreach (var item in this.GetCourseData())
            {
                await courseRepository.AddAsync(item);

                await courseRepository.SaveChangesAsync();
            }

            var service = new LessonsService(lessonsRepository, mockUserLessonRepository.Object, courseRepository);
            await service.EditLesson("1", "New Name", "New Description", "User1");

            await service.EditLesson("3", "New Name2", "New Description2", "User2");

            var lesson1 = lessonsRepository.All().FirstOrDefault(x => x.Id == "1");
            var lesson3 = lessonsRepository.All().FirstOrDefault(x => x.Id == "3");

            Assert.Equal("New Name", lesson1.Name);
            Assert.Equal("New Description", lesson1.Description);
            Assert.Equal("Lesson 3", lesson3.Name);
            Assert.Equal("Description3", lesson3.Description);
        }
Esempio n. 14
0
        public virtual JsonResult GetEvents()
        {
            var lessonsResponse = new List <LessonResponse>();
            var lessons         = LessonsService.GetList();

            foreach (var item in lessons)
            {
                var usercount = LessonsService.GetLessonUsersCount(item.Id);
                var user      = UserService.Get(item.UserId);
                var userName  = $"{user.FirstName} {user.LastName}";
                var color     = user.Color;
                lessonsResponse.Add(new LessonResponse
                {
                    id          = item.Id,
                    editable    = false,
                    title       = $"{item.Title}",
                    description = $"Na zajęcia zapisało się {usercount} osób. \n Zajęcia prowadzi Trener: {userName}",
                    start       = item.Start.ToString("s"),
                    end         = item.End.Value.ToString("s"),
                    color       = color,
                });
            }
            return(Json(lessonsResponse, JsonRequestBehavior.AllowGet));
        }
Esempio n. 15
0
        public virtual ActionResult UserJoinedToLesson(long lessonId)
        {
            var joined = LessonsService.JoinedToLesson(lessonId, User.Identity.GetUserId());

            return(Json(new { msg = joined }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 16
0
 public LessonsController(LessonsService lessonsService)
 {
     this.lessonsService = lessonsService;
 }
Esempio n. 17
0
 public LessonsServiceXTests()
 {
     _fixture = new Fixture();
     _lessonsRepositoryMock = new Mock <ILessonsRepository>();
     _service = new LessonsService(_lessonsRepositoryMock.Object);
 }
Esempio n. 18
0
        public virtual JsonResult Delete(long id)
        {
            LessonsService.Delete(id);

            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Esempio n. 19
0
 public virtual ActionResult JoinLesson(long lessonId)
 {
     LessonsService.JoinToLesson(lessonId, User.Identity.GetUserId());
     return(Json(true, JsonRequestBehavior.AllowGet));
 }
Esempio n. 20
0
 public LessonDTOesController(AppdbContext context)
 {
     //_context = context;
     _lessonsService = new LessonsService(context);
 }
Esempio n. 21
0
 public HomeController(LessonsService lessonsService)
 {
     _lessonsService = lessonsService;
 }