Exemplo n.º 1
0
 public void CheckIfSubjectCanBeCreatedWithoutAStandard()
 {
     var subject = new Subject
                             {
                                 SubjectName = "AwesomeSubject",
                                 SubjectCategory = "MyAwesomeSubjectCategory"
                             };
     var result = SubjectRepository.Add(subject);
     Assert.Throws<DbUpdateException>(
                                         () => EfUnitOfWork.Commit());
 }
Exemplo n.º 2
0
 public void CheckSubjectNameLengthfForInValidCases(string subjectName)
 {
     var standard = StandardRepository.Query().FirstOrDefault();
     var subject = new Subject
                             {
                                 SubjectName = subjectName,
                                 SubjectCategory = "MyAwesomeSubjectCategory",
                                 Standard = standard
                             };
     var result = SubjectRepository.Add(subject);
     Assert.Throws<DbEntityValidationException>(() => EfUnitOfWork.Commit());
 }
Exemplo n.º 3
0
 public void Initialize()
 {
     Context = new ParikshaContext();
     EfUoW = new EFUnitOfWork(Context);
     UserRepository = new EFRepository<UserDetail>(EfUoW, Context);
     QuestionRepository = new EFRepository<Question>(EfUoW, Context);
     StandardRepository = new EFRepository<Standard>(EfUoW, Context);
     SubjectRepository = new EFRepository<Subject>(EfUoW, Context);
     User = new UserDetail { UserRole = UserRole.Admin, Password = "******", Name = "ashutosh", DateOfCreation = DateTime.UtcNow };
     Standard = new Standard { StandardName = "First" };
     Subject = new Subject { SubjectName = "Mathematics", SubjectCategory = "Algebra", Standard = Standard };
     UserRepository.Add(User);
     StandardRepository.Add(Standard);
     SubjectRepository.Add(Subject);
     EfUoW.Commit();
 }
Exemplo n.º 4
0
            public void Update()
            {
                SubjectRepository.Query().Any();
                    var standard = StandardRepository.Query().FirstOrDefault();
                    var subject = new Subject { SubjectName = "Algorithms", SubjectCategory = "Advanced", Standard = standard };
                    SubjectRepository.Add(subject);
                    EfUoW.Commit();

                    var result = SubjectRepository.Query().FirstOrDefault(_ => _.SubjectName.Equals("Algorithms"));
                    result.SubjectCategory = "SuperAdvanced";
                    SubjectRepository.Update(result);
                    EfUoW.Commit();

                    Assert.IsNotNull(result);
                    Assert.AreEqual("SuperAdvanced", result.SubjectCategory);
            }
Exemplo n.º 5
0
            public void Delete()
            {
                var standard = StandardRepository.Query().FirstOrDefault();
                    var subject = new Subject { SubjectName = "Algorithms", SubjectCategory = "Beginner", Standard = standard };
                    SubjectRepository.Add(subject);
                    EfUoW.Commit();

                    var initialCount = SubjectRepository.Query().Count();
                    var toDelete = SubjectRepository.Query().Where(_ => _.SubjectCategory.Equals("Beginner")).FirstOrDefault();
                    var result = SubjectRepository.Remove(toDelete);
                    EfUoW.Commit();
                    var finalCount = SubjectRepository.Query().Count();

                    Assert.IsNotNull(result);
                    Assert.AreEqual(initialCount - 1, finalCount);
            }
Exemplo n.º 6
0
            public void Create()
            {
                var initialCount = SubjectRepository.Query().Count();
                    var standard = StandardRepository.Query().FirstOrDefault();
                    var subject = new Subject { SubjectName = "DataStructures", SubjectCategory = "Advanced", Standard = standard };
                    SubjectRepository.Add(subject);
                    EfUoW.Commit();

                    var finalCount = SubjectRepository.Query().Count();
                    var result = SubjectRepository.Query().Where(_ => _.SubjectName.Equals("DataStructures")).FirstOrDefault();

                    Assert.AreEqual(initialCount + 1, finalCount);
                    Assert.IsNotNull(result);
                    Assert.AreEqual("Advanced", result.SubjectCategory);
            }
Exemplo n.º 7
0
            public void Update()
            {
                var standard = StandardRepository.Query().FirstOrDefault();
                    var subject = new Subject { SubjectName = "Mathematics", SubjectCategory = "Addition", Standard = standard };
                    standard.StandardName = "FooBaar";
                    var initialCount = standard.Subjects.Count();
                    standard.Subjects.Add(subject);

                    EfUoW.Commit();

                    var result = StandardRepository.Query().FirstOrDefault();
                    var standardName = result.StandardName;
                    Assert.AreEqual("FooBaar", standardName);
                    Assert.AreEqual(initialCount + 1, result.Subjects.Count());
            }
Exemplo n.º 8
0
        public void Initialize()
        {
            MockRepository = new Mock<IRepository<Test>>();

            var firstQuestion = new Question { QuestionId = 1, Difficulty = Difficulty.Hard, Rating = 5 };
            var secondQuestion = new Question { QuestionId = 2, Difficulty = Difficulty.Hard, Rating = 3 };
            var brief = new Brief { Difficulty = Difficulty.Hard, Rating = 5, QuestionText = "Who let the dog's out ?", Answer = "It wasn't me" };
            var choice = new Choice { Difficulty = Difficulty.Hard, Rating = 5, QuestionText = "Who let the dog's out ?", Choices = "Me,You,All of us all are the culprits", Answers = "Me", IsMultiplechoice = true };

            _questions = new List<Question> { firstQuestion, secondQuestion, brief, choice };
            _user = new UserDetail { Name = "Ashutosh", Password = "******", UserRole = UserRole.Admin, DateOfCreation = DateTime.UtcNow };
            _subject = new Subject { SubjectName = "Mathematics", SubjectCategory = "Advanced" };
            _tests = new List<Test>
                                    {
                                      new Test
                                                {
                                                    TestId = 1,
                                                    DateOfCreation = DateTime.UtcNow,
                                                    Subject = _subject,
                                                    Creator = _user,
                                                    Questions = _questions
                                                },
                                      new Test
                                                {
                                                    TestId = 2,
                                                    DateOfCreation = DateTime.UtcNow,
                                                    Subject = _subject,
                                                    Creator = _user,
                                                    Questions = _questions
                                                }
                                    };
            MockRepository.Setup(_ => _.Query()).Returns(_tests.AsQueryable());
            _test = new Test
                            {
                               TestId = 3,
                               DateOfCreation = DateTime.UtcNow,
                               Subject = _subject,
                               Creator = _user,
                               Questions = _questions
                            };
            MockRepository.Setup(_ => _.Add(_test)).Returns(_test);
            _repository = MockRepository.Object;
            _service = new TestService(_repository, _unitOfWork);
            MockRepository.Setup(_ => _.Query()).Returns(_tests.AsQueryable());
        }
Exemplo n.º 9
0
 public IQueryable<Test> GetTestsBySubject(Subject subject)
 {
     return _testrepository.Query().Where(_ => _.Subject == subject);
 }