Ejemplo n.º 1
0
 public void EditCourse(Course courseModel, List<int> wordSuitesId)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         var course = uow.CourseRepository.GetById(courseModel.Id);
         course.Name = courseModel.Name;
         var wordSuites = course.WordSuites.
             Where(ws => (!wordSuitesId.Contains(ws.Id) && ws.PrototypeId == null)).Select(ws => ws.Id).ToList();
         RemoveWordSuitesFromCourse(course.Id, wordSuites);
         wordSuitesId.RemoveAll(x => course.WordSuites.Select(ws => ws.Id).Contains(x));
         AddWordSuitesToCourse(course.Id, wordSuitesId);
         uow.Save();
     }
     //using (var context = new WorldOfWordsDatabaseContext())
     //{
     //    var course = context.Courses.First(x => x.Id == courseModel.Id);
     //    course.Name = courseModel.Name;
     //    var wordSuites = course.WordSuites.
     //        Where(ws => (!wordSuitesId.Contains(ws.Id) && ws.PrototypeId == null)).ToList();
     //    RemoveWordSuitesFromCourse(course.Id, wordSuites);
     //    wordSuitesId.RemoveAll(x => course.WordSuites.Select(ws => ws.Id).Contains(x));
     //    AddWordSuitesToCourse(course.Id, wordSuitesId);
     //    context.SaveChanges();
     //}
 }
 public CourseForListOfUsersModel Map(Course course)
 {
     return new CourseForListOfUsersModel()
     {
         Id = course.Id,
         Name = course.Name
     };
 }
Ejemplo n.º 3
0
 public int Add(Course course, List<int> wordSuitesId)
 {
     using (var context = new WorldOfWordsDatabaseContext())
     {
         context.Courses.Add(course);
         context.SaveChanges();
         AddWordSuitesToCourse(course.Id, wordSuitesId);
         context.SaveChanges();
         return course.Id;
     }
 }
Ejemplo n.º 4
0
 public CourseModel Map(Course course)
 {
     if (course == null)
     {
         throw new ArgumentNullException("course");
     }
     CourseModel courseModel = new CourseModel();
     courseModel.Id = course.Id;
     courseModel.Name = course.Name;
     courseModel.Language = _languageMapper.ToApiModel(course.Language);
     courseModel.WordSuites = _mapper.Map(course.WordSuites.ToList());
     return courseModel;
 }
Ejemplo n.º 5
0
 public void EditCourse(Course courseModel, List<int> wordSuitesId)
 {
     using (var context = new WorldOfWordsDatabaseContext())
     {
         var course = context.Courses.First(x => x.Id == courseModel.Id);
         course.Name = courseModel.Name;
         var wordSuites = course.WordSuites.
             Where(ws => (!wordSuitesId.Contains(ws.Id) && ws.PrototypeId == null)).ToList();
         RemoveWordSuitesFromCourse(course.Id, wordSuites);
         wordSuitesId.RemoveAll(x => course.WordSuites.Select(ws => ws.Id).Contains(x));
         AddWordSuitesToCourse(course.Id, wordSuitesId);
         context.SaveChanges();
     }
 }
        public void Setup()
        {
            unitOfWorkFactory.Setup(x => x.GetUnitOfWork()).Returns(unitOfWork.Object);
            unitOfWork.Setup(x => x.GroupRepository).Returns(groupRepository.Object);
           
            groupService = new GroupService(unitOfWorkFactory.Object);

            var course1 = new Course { Id = 555 };
            var course2 = new Course { Id = 1 };

            groups = (new List<Group> { 
            new Group { Id = 111, OwnerId = 555, Course = course1, CourseId = 555, Name = "Name1" },
            new Group { Id = 222, OwnerId = 1, Course = course2, CourseId = 1, Name = "Name2" }}).AsQueryable();
        }
Ejemplo n.º 7
0
 public int Add(Course course, List<int> wordSuitesId)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         uow.CourseRepository.Add(course);
         uow.Save();
         AddWordSuitesToCourse(course.Id, wordSuitesId);
         uow.Save();
         return course.Id;
     }
     //using (var context = new WorldOfWordsDatabaseContext())
     //{
     //    context.Courses.Add(course);
     //    context.SaveChanges();
     //    AddWordSuitesToCourse(course.Id, wordSuitesId);
     //    context.SaveChanges();
     //    return course.Id;
     //}
 }
Ejemplo n.º 8
0
 public CourseForGroupModel Map(Course course)
 {
     return new CourseForGroupModel() { Id = course.Id, Name = course.Name };
 }
        public void EditCourse()
        {   
            //Arrange
            List<int> wordSuiteId = new List<int>()
            {
                1,2,3,4
            };

            List<WordSuite> wordsuite = new List<WordSuite>
            {
                new WordSuite
                {
                  Id = 8,
                  PrototypeId = null
                },
                new WordSuite
                {
                    Id = 500,
                    PrototypeId = 100 
                }
            };
            Course courseModel = new Course
            {
                Name = "eke",
                Id = 1
            };
            Course course = new Course
            {
                WordSuites = wordsuite,
                Id = 322
            };
            Mock<IRepository<WorldOfWords.Domain.Models.Course>> repo = new Mock<IRepository<Course>>();
            _uow.Setup(x => x.CourseRepository).Returns(repo.Object);
            //  Mock<IRepository<Course>> _repCourse = new Mock<IRepository<Course>>();
            _uow.Setup(x => x.Save()).Verifiable();
            repo.Setup(x => x.GetById(It.IsAny<int>())).Returns(course);
            Mock<IWordSuiteRepository> suiteRepo = new Mock<IWordSuiteRepository>();
            _uow.Setup(x => x.WordSuiteRepository).Returns(suiteRepo.Object);
            suiteRepo.Setup(x => x.GetById(It.IsAny<int>())).Returns(It.IsAny<WordSuite>());

            //Act
            _service.EditCourse(courseModel, wordSuiteId);
            
            //Assert
            _uow.VerifyAll();
            _uow.Verify(x=>x.Save(),Times.Exactly(3));
            _factory.Verify(x=>x.GetUnitOfWork(),Times.Exactly(3));
            _uow.Verify(x => x.CourseRepository, Times.Exactly(3));
            repo.Verify(x => x.GetById(It.IsAny<int>()), Times.Exactly(3));
            _uow.Verify(x => x.WordSuiteRepository, Times.AtLeastOnce());
            suiteRepo.Verify(x => x.GetById(It.IsAny<int>()), Times.AtLeastOnce());
            _uow.VerifyAll();
        }
        public void GetProgress_ReturnProgress()
        {
            // Arrange
            double expected = 600;
            int userId = 10;
            int id = 8;
            Course course = new Course
            {
                WordSuites = new List<WordSuite>()
                    { 
                        new WordSuite
                        {
                            
                            OwnerId = userId,
                            WordProgresses = new List<WordProgress>
                            {
                                new WordProgress
                                {
                                    Progress = 10

                                }
                            },
                            Threshold = 1,
                            PrototypeId = 2
                        },
                        new WordSuite
                        {
                            OwnerId = 10,
                            PrototypeId = 10,
                            WordProgresses = new List<WordProgress>
                            {
                                new WordProgress
                                {
                                    Progress = 2
                                }
                            },
                            Threshold = 1
                        },
                    },
                Language = new Language(),
                Groups = new List<Group>(),
                Id = 8
            };
            IQueryable<Course> courses = new List<Course>
            {
                course
            }.AsQueryable<Course>();
            Mock<IRepository<WorldOfWords.Domain.Models.Course>> repo = new Mock<IRepository<Course>>();
            _uow.Setup(x => x.CourseRepository).Returns(repo.Object);
            repo.Setup(x => x.GetAll()).Returns(courses);
            
        
            // Act
            double actual = _service.GetProgress(id, userId);

            // Assert
            _factory.Verify(x => x.GetUnitOfWork(), Times.Once);
            _uow.Verify(x => x.CourseRepository, Times.Once);
            repo.Verify(x => x.GetAll(), Times.Once);
            Assert.AreEqual(expected, actual);
        }
        public void GetById_ReturnCourse_Overloaded()
        {
            // Arrange
            int id = 21;
            int userId =8;
            Course expected = new Course
            {
                WordSuites = new List<WordSuite>()
                    { 
                        new WordSuite
                        {
                            OwnerId = userId,
                            PrototypeId = 8
                        },
                        new WordSuite
                        {
                            OwnerId = 1,
                            PrototypeId = 2
                        }
                    },
                Language = new Language(),
                Id = id
            };
            IQueryable<Course> courses = new List<Course>
            {
                expected
            }.AsQueryable<Course>();
            Mock<IRepository<WorldOfWords.Domain.Models.Course>> repo = new Mock<IRepository<Course>>();
            _uow.Setup(x => x.CourseRepository).Returns(repo.Object);
            repo.Setup(x => x.GetAll()).Returns(courses);
            
            // Act
            var actual = _service.GetById(id, userId);

            // Assert 
            _uow.Verify(x => x.CourseRepository, Times.Once);
            _factory.Verify(x => x.GetUnitOfWork(), Times.Once);
            repo.Verify(x => x.GetAll(), Times.Once);
            Assert.AreEqual(expected, actual);
        }
        public void GetById_ReturnCourse_Negative()
        {
            // Arrange 
            int id = 8;
            Course expected = new Course
            {
                
                Id = 322
            };
            IQueryable<Course> courses = new List<Course>
            {
                expected
            }.AsQueryable<Course>();
            Mock<IRepository<WorldOfWords.Domain.Models.Course>> repo = new Mock<IRepository<Course>>();
            _uow.Setup(x => x.CourseRepository).Returns(repo.Object);
            repo.Setup(x => x.GetAll()).Returns(courses);

            //Act
            var actual = _service.GetById(id);

            //Assert
            _uow.Verify(x => x.CourseRepository, Times.Once);
            _factory.Verify(x => x.GetUnitOfWork(), Times.Once);
            repo.Verify(x => x.GetAll(), Times.Once);
            Assert.IsNull(actual);
        }
        public void Add_ReturnsId()
        {

            // Arrange
            int id = 322;
            Course course = new Course
            {
                Id = 322,
                WordSuites = new List<WordSuite>()
            };
            List<int> list = new List<int>()
            {
                1,2,3,4,322
            };
            Mock<IRepository<WorldOfWords.Domain.Models.Course>> repo = new Mock<IRepository<Course>>();
            _uow.Setup(x => x.CourseRepository).Returns(repo.Object);
            _uow.Setup(x => x.CourseRepository.GetById(It.IsAny<int>())).Returns(course);
            Mock<ICollection<WordSuite>> WordSuites = new Mock<ICollection<WordSuite>>();
            Mock<IWordSuiteRepository> wordSuiteRepository = new Mock<IWordSuiteRepository>();
            _uow.Setup(x => x.WordSuiteRepository).Returns(wordSuiteRepository.Object);
            wordSuiteRepository.Setup(x => x.GetById(It.IsAny<int>())).Returns(It.IsAny<WordSuite>());


            // Act
            var actual = _service.Add(course, list);
            
            // Assert
            _factory.Verify(x => x.GetUnitOfWork(), Times.Exactly(2));
            _uow.Verify(x => x.CourseRepository.GetById(course.Id), Times.AtLeastOnce());
            _uow.Verify(x => x.Save(), Times.Exactly(3));
            _uow.Verify(x => x.CourseRepository, Times.Exactly(2));
            _uow.Verify(x => x.CourseRepository.Add(course), Times.Once);
            //WordSuites.Verify(x=>x.Add(),Times.AtLeastOnce);
            Assert.AreEqual(id, actual);
            
        }
        public void GetTeacherCourses_ReturnCourses()
        {
            // Arrange
            int userId = 8;
            Course expected = new Course
            {
                OwnerId = userId,
                WordSuites = new List<WordSuite>()
                    { 
                        new WordSuite
                        {

                            PrototypeId = null
                        }
                    },
                Language = new Language(),
               
            };
            IQueryable<Course> courses = new List<Course>
            {
                expected
            }.AsQueryable<Course>();
            Mock<IRepository<WorldOfWords.Domain.Models.Course>> repo = new Mock<IRepository<Course>>();
            _uow.Setup(x => x.CourseRepository).Returns(repo.Object);
            repo.Setup(x => x.GetAll()).Returns(courses);
            
            //Act
            var actual = _service.GetTeacherCourses(userId);

            //Assert
            _uow.Verify(x => x.CourseRepository, Times.Once);
            _factory.Verify(x => x.GetUnitOfWork(), Times.Once);
            repo.Verify(x => x.GetAll(), Times.Once);
            Assert.AreEqual(courses.ToList<Course>(), actual);
        }