public void testUpdateHomeworkEditQuestionSuccess()
        {
            Assert.Null(serv.GetByDetails(hwTitl, hwDesc));
            // Arrange
            int count = serv.All().Count();

            serv.Add(entity);
            entity.Questions.Add(new Question("test question"));
            Assert.True(serv.Update(entity) is MichtavaSuccess);

            Guid id = serv.GetByDetails(hwTitl, hwDesc).Id;

            Assert.AreEqual(count + 1, serv.All().Count());

            // Act
            var quest = serv.All().Include(x => x.Questions).FirstOrDefault(y => y.Id == id).Questions.ElementAt(0);

            quest.Content = "edited question";
            MichtavaResult res = serv.Update(entity);

            // Assert
            Assert.True(res is MichtavaSuccess);
            var quests = serv.All().Include(x => x.Questions).FirstOrDefault(y => y.Id == id).Questions.ToList();

            Assert.NotNull(quests);
            Assert.True(quests.Count() != 0);
            Assert.True(quests.ElementAt(0).Content == "edited question");
            Assert.True(serv.HardDelete(entity) is MichtavaSuccess);
        }
Exemple #2
0
        public void testAddDefinitions()
        {
            Assert.Null(serv.GetByWord(word));
            // Arrange
            int count = serv.All().Count();

            serv.Add(entity);

            Assert.Null(serv.GetByWord("harambe"));


            Assert.AreEqual(count + 1, serv.All().Count());
            entity.addDefinitions(new List <string>()
            {
                "1rerer is good      ", "babuba"
            });


            // Act
            MichtavaResult res = serv.Update(entity);

            // Assert
            Assert.True(res is MichtavaSuccess);
            Assert.NotNull(serv.GetByWord(word));
            Assert.True(serv.HardDelete(entity) is MichtavaSuccess);
        }
        public void testHardDeleteSuccessAdministrator()
        {
            Assert.Null(serv.GetByUserName(USERNAME));
            // Arrange
            var result = this.userManager.Create(adminUser, "testpassword");

            if (result.Succeeded)
            {
                this.userManager.AddToRole(adminUser.Id, GlobalConstants.AdministratorRoleName);
            }
            MichtavaResult res2  = serv.Add(entity);
            int            count = serv.All().Count();

            Guid id = serv.GetByUserName(USERNAME).Id;

            // Act
            MichtavaResult res = serv.HardDelete(entity);

            this.userManager.Delete(adminUser);
            Assert.Null(serv.GetByUserName(USERNAME));

            // Assert
            Assert.True(res is MichtavaSuccess);
            Assert.Null(serv.GetByUserName(USERNAME));
            Assert.True(serv.All().Count() == count - 1);
        }
Exemple #4
0
        public void testDeleteTeacherSuccess()
        {
            Assert.Null(serv.GetByUserName(USERNAME));
            // Arrange
            var result = this.userManager.Create(teacherUser, "testpassword");

            if (result.Succeeded)
            {
                this.userManager.AddToRole(teacherUser.Id, GlobalConstants.TeacherRoleName);
            }
            serv.Add(entity);
            int count = serv.All().Count();

            Teacher study = serv.GetByUserName(USERNAME);
            Guid    id    = study.Id;

            // Act
            MichtavaResult res  = serv.Delete(entity);
            var            res2 = this.userManager.Delete(teacherUser);

            // Assert
            Assert.True(res2.Succeeded);
            Assert.True(res is MichtavaSuccess);
            Assert.Null(serv.GetByUserName(USERNAME));
            Assert.True(serv.All().Count() == count - 1);
            Assert.True(serv.GetById(id).IsDeleted);

            Assert.True(serv.HardDelete(entity) is MichtavaSuccess);
            Assert.Null(serv.GetByUserName(USERNAME));
        }
        public void testUpdateAdministratorSuccess()
        {
            Assert.Null(serv.GetByUserName(USERNAME));
            // Arrange
            int count = serv.All().Count();

            var result = this.userManager.Create(adminUser, "testpassword");

            if (result.Succeeded)
            {
                this.userManager.AddToRole(adminUser.Id, GlobalConstants.AdministratorRoleName);
            }
            serv.Add(entity);

            Assert.Null(serv.GetByUserName("ichangedusername"));


            Assert.AreEqual(count + 1, serv.All().Count());


            // Act
            entity.ApplicationUser.UserName = "******";
            MichtavaResult res = serv.Update(entity);

            // Assert
            Assert.True(res is MichtavaSuccess);
            Assert.NotNull(serv.GetByUserName("ichangedusername"));
            Assert.True(serv.HardDelete(entity) is MichtavaSuccess);
            this.userManager.Delete(adminUser);
            Assert.Null(serv.GetByUserName(USERNAME));
        }
Exemple #6
0
        public void testUpdateSchoolClassAddTeacher()
        {
            // Arrange
            int         count  = serv.All().Count();
            SchoolClass c      = serv.All().Include(x => x.Teachers).FirstOrDefault();
            int         count1 = c.Teachers.Count();
            Teacher     t      = ctx.Set <Teacher>().Include(x => x.SchoolClasses).ToList().FirstOrDefault(x => !x.SchoolClasses.Contains(c));
            int         count2 = t.SchoolClasses.Count();


            // Act
            MichtavaResult res = serv.AddTeacherToClass(t, c);


            // Assert
            Assert.True(res is MichtavaSuccess);

            SchoolClass pc = serv.All().Include(y => y.Teachers).FirstOrDefault(x => x.Id == c.Id);
            Teacher     pt = ctx.Set <Teacher>().Include(x => x.SchoolClasses).FirstOrDefault(x => x.Id == t.Id);

            Assert.True(pt.SchoolClasses.Contains(pc));
            Assert.True(pc.Teachers.Contains(pt));
            Assert.AreEqual(count1 + 1, pc.Teachers.Count);
            Assert.AreEqual(count2 + 1, pt.SchoolClasses.Count);
        }
Exemple #7
0
        public void testDeleteSchoolClassIsStudentUpdated()
        {
            this.oneTimeSetUp();


            Assert.Null(serv.GetByDetails(23, "ע"));
            // Arrange
            int count = serv.All().Count();


            //SchoolClass c = serv.All().Include(x => x.Students).FirstOrDefault(y => y.Students.Count > 0);//DOES NOT WORK

            SchoolClass        c  = null;
            List <SchoolClass> cs = serv.All().Include(y => y.Students).ToList();//check

            foreach (SchoolClass sc in cs)
            {
                if (sc.Students.Count > 0)
                {
                    c = sc;
                    break;
                }
            }

            Assert.NotNull(c);

            ICollection <Student> studentsFromSchoolClass = c.Students;



            // Act
            MichtavaResult res = serv.Delete(c);



            // Assert

            List <Student> ss = this.ctx.Set <Student>().Include(x => x.SchoolClass).ToList();//check
            List <Student> persistantStudentsFromSchoolClass = new List <Student>();

            foreach (Student s in ss)
            {
                if (containsId(studentsFromSchoolClass.Cast <HasId>().ToList(), s.Id))
                {
                    persistantStudentsFromSchoolClass.Add(s);
                }
            }
            Guid id = c.Id;

            Assert.True(res is MichtavaSuccess);
            Assert.True(serv.All().Count() == count - 1);
            Assert.True(serv.GetById(id).IsDeleted);



            foreach (Student s in persistantStudentsFromSchoolClass)
            {
                Assert.True(s.SchoolClass == null);
            }
        }
Exemple #8
0
        public void testUpdateSchoolClassTransferStudent()
        {
            // Arrange
            int         count    = serv.All().Count();
            SchoolClass c        = serv.All().Include(x => x.Students).FirstOrDefault();
            int         count1   = c.Students.Count();
            Student     s        = ctx.Set <Student>().ToList().ElementAt(6);
            SchoolClass hisClass = serv.All().Include(y => y.Students).FirstOrDefault(x => x.Id == s.SchoolClass.Id);
            int         count2   = hisClass.Students.Count();


            // Act
            MichtavaResult res = serv.TransferStudentToClass(hisClass, s, c);


            // Assert
            Assert.True(res is MichtavaSuccess);

            SchoolClass pc        = serv.All().Include(y => y.Students).FirstOrDefault(x => x.Id == c.Id);
            SchoolClass phisClass = serv.All().Include(y => y.Students).FirstOrDefault(x => x.Id == hisClass.Id);
            Student     ps        = ctx.Set <Student>().Include(x => x.SchoolClass).FirstOrDefault(x => x.Id == s.Id);


            Assert.AreEqual(pc.Id, ps.SchoolClass.Id);
            Assert.AreEqual(count2 - 1, phisClass.Students.Count);
            Assert.AreEqual(count1 + 1, pc.Students.Count);
        }
Exemple #9
0
        public void testUpdateSchoolClassRemoveTeacher()
        {
            // Arrange
            int         count  = serv.All().Count();
            SchoolClass c      = serv.All().Include(x => x.Teachers).ToList().FirstOrDefault(x => x.Teachers.Count() != 0);
            int         count1 = c.Teachers.Count();
            Teacher     t      = c.Teachers.ToList().ElementAt(0);
            int         count2 = t.SchoolClasses.Count();


            // Act
            MichtavaResult res = serv.RemoveTeacherFromClass(t, c);


            // Assert
            Assert.True(res is MichtavaSuccess);

            SchoolClass pc = serv.All().Include(y => y.Teachers).FirstOrDefault(x => x.Id == c.Id);
            Teacher     pt = ctx.Set <Teacher>().Include(x => x.SchoolClasses).FirstOrDefault(x => x.Id == t.Id);


            Assert.True(!pt.SchoolClasses.Contains(pc));
            Assert.True(!pc.Teachers.Contains(pt));
            Assert.AreEqual(count1 - 1, pc.Teachers.Count);
            Assert.AreEqual(count2 - 1, t.SchoolClasses.Count);
        }
        public ActionResult AddTeacherToClass(AddTeacherToClassViewModel model)
        {
            string url = Request.Url.ToString();

            string[] slashes = url.Split('/');
            string   id      = "";

            foreach (string str in slashes)
            {
                if (str.Contains('-'))
                {
                    id = str;
                }
            }

            string  username = model.userName;
            Teacher t        = this.teacherService.GetByUserName(username);

            if (t == null)
            {
                ModelState.AddModelError(string.Empty, "user name does not exist");
                return(RedirectToAction("Teachers", "SchoolClasses", new { id = id }));
            }
            MichtavaResult res = this.schoolClassService.AddTeacherToClass(t, this.schoolClassService.GetById(new Guid(id)));

            if (res is MichtavaFailure)
            {
                ModelState.AddModelError(string.Empty, res.Message);
            }

            return(RedirectToAction("Teachers", "SchoolClasses", new { id = id }));
        }
        public void testUpdateHomeworkRemoveKSTFromQuestionSuccess()
        {
            Assert.Null(serv.GetByDetails(hwTitl, hwDesc));
            // Arrange
            int count = serv.All().Count();

            serv.Add(entity);
            Question         q  = new Question("test question");
            SuggestedOpening so = new SuggestedOpening("TSO");

            q.Suggested_Openings.Add(so);
            entity.Questions.Add(q);
            Assert.True(serv.Update(entity) is MichtavaSuccess);

            Guid id = serv.GetByDetails(hwTitl, hwDesc).Id;

            Assert.AreEqual(count + 1, serv.All().Count());

            // Act
            var quest = serv.All().Include(x => x.Questions).FirstOrDefault(y => y.Id == id).Questions.ElementAt(0);

            quest.Suggested_Openings.Remove(so);
            MichtavaResult res = serv.Update(entity);

            // Assert
            Assert.True(res is MichtavaSuccess);
            var quests = serv.All().Include(x => x.Questions).FirstOrDefault(y => y.Id == id).Questions.ToList();

            Assert.NotNull(quests);
            Assert.True(quests.Count() != 0);
            Assert.True(quests.ElementAt(0).Suggested_Openings.Count() == 0);

            Assert.True(serv.HardDelete(entity) is MichtavaSuccess);
        }
Exemple #12
0
        public void testUpdateTeacherNonExistant()
        {
            Assert.Null(serv.GetByUserName(USERNAME));
            // Arrange
            int count = serv.All().Count();

            // Act
            MichtavaResult res = serv.Update(new Teacher(null, "דג"));

            // Assert
            Assert.True(res is MichtavaFailure);
        }
Exemple #13
0
        public void testAddSchoolClassExistingId()
        {
            Assert.Null(serv.GetByDetails(23, "ע"));
            // Arrange
            int         count    = serv.All().Count();
            SchoolClass existing = serv.All().FirstOrDefault();

            // Act
            MichtavaResult res = serv.Add(existing);

            // Assert
            Assert.True(res is MichtavaFailure);
        }
Exemple #14
0
        public void testAddExistingIdAnswer()
        {
            Assert.Null(serv.GetByDetails(this.hwId, this.studentId));
            // Arrange
            int    count    = serv.All().Count();
            Answer existing = serv.All().FirstOrDefault();

            // Act
            MichtavaResult res = serv.Add(existing);

            // Assert
            Assert.True(res is MichtavaFailure);
        }
        public ActionResult RemoveTeacherFromClass(Guid id, string username)
        {
            Teacher        t   = this.teacherService.GetByUserName(username);
            SchoolClass    sc  = schoolClassService.GetById(id);
            MichtavaResult res = this.schoolClassService.RemoveTeacherFromClass(t, sc);

            if (res is MichtavaFailure)
            {
                ModelState.AddModelError(string.Empty, res.Message);
            }

            return(RedirectToAction("Teachers", "SchoolClasses", new { id = sc.Id }));
        }
        public void testAddExistingIdSubject()
        {
            Assert.Null(serv.GetByName(n));
            // Arrange
            int     count    = serv.All().Count();
            Subject existing = serv.All().FirstOrDefault();

            // Act
            MichtavaResult res = serv.Add(existing);

            // Assert
            Assert.True(res is MichtavaFailure);
        }
Exemple #17
0
        public void testAddExistingIdWordDefinition()
        {
            Assert.Null(serv.GetByWord(word));
            // Arrange
            int            count    = serv.All().Count();
            WordDefinition existing = serv.All().FirstOrDefault();

            // Act
            MichtavaResult res = serv.Add(existing);

            // Assert
            Assert.True(res is MichtavaFailure);
        }
        public void testAddExistingIdHomework()
        {
            Assert.Null(serv.GetByDetails(hwTitl, hwDesc));
            // Arrange
            int      count    = serv.All().Count();
            Homework existing = serv.All().FirstOrDefault();

            // Act
            MichtavaResult res = serv.Add(existing);

            // Assert
            Assert.True(res is MichtavaFailure);
        }
Exemple #19
0
        public void testDeleteSchoolClassIsTeacherUpdated()
        {
            this.oneTimeSetUp();

            Assert.Null(serv.GetByDetails(23, "ע"));
            // Arrange
            int                count = serv.All().Count();
            SchoolClass        c     = null;
            List <SchoolClass> cs    = serv.All().Include(y => y.Teachers).ToList();

            foreach (SchoolClass sc in cs)
            {
                if (sc.Teachers.Count > 0)
                {
                    c = sc;
                    break;
                }
            }

            Assert.NotNull(c);

            ICollection <Teacher> teachersFromSchoolClass = c.Teachers;

            List <Teacher> ts = this.ctx.Set <Teacher>().Include(y => y.SchoolClasses).ToList();//check
            List <Teacher> persistantTeachersFromSchoolClass = new List <Teacher>();

            foreach (Teacher t in ts)
            {
                if (containsId(teachersFromSchoolClass.Cast <HasId>().ToList(), t.Id))
                {
                    persistantTeachersFromSchoolClass.Add(t);
                }
            }
            Guid id = c.Id;

            // Act
            MichtavaResult res = serv.Delete(c);

            // Assert
            Assert.True(res is MichtavaSuccess);
            Assert.True(serv.All().Count() == count - 1);
            Assert.True(serv.GetById(id).IsDeleted);

            foreach (Teacher t in persistantTeachersFromSchoolClass)
            {
                Assert.False(containsId(t.SchoolClasses.Cast <HasId>().ToList(), id));
            }

            this.oneTimeSetUp();
        }
Exemple #20
0
        public void testAddExistingSchoolClassDetails()
        {
            Assert.Null(serv.GetByDetails(23, "ע"));
            // Arrange
            int         count    = serv.All().Count();
            SchoolClass existing = serv.All().FirstOrDefault();
            SchoolClass c        = new SchoolClass(existing.ClassNumber, existing.ClassLetter);
            // Act

            MichtavaResult res = serv.Add(c);

            // Assert
            Assert.True(res is MichtavaFailure);
        }
Exemple #21
0
        public void testUpdateWordDefinitionNonExistant()
        {
            Assert.Null(serv.GetByWord(word));
            // Arrange
            int count = serv.All().Count();

            Assert.Null(serv.GetByWord("harambe"));

            // Act
            MichtavaResult res = serv.Update(new WordDefinition("harambe", "some definition"));

            // Assert
            Assert.True(res is MichtavaFailure);
        }
Exemple #22
0
        public void testAddTextExistingDetails()
        {
            Assert.Null(serv.GetByName(n));
            // Arrange
            int  count    = serv.All().Count();
            Text existing = serv.All().FirstOrDefault();

            Text c = new Text(existing.Name, this.ctx.Set <Subject>().FirstOrDefault());
            // Act

            MichtavaResult res = serv.Add(c);

            // Assert
            Assert.True(res is MichtavaFailure);
        }
        public void testUpdateAdministratorNonExistant()
        {
            Assert.Null(serv.GetByUserName(USERNAME));
            // Arrange
            int count = serv.All().Count();

            // Act
            MichtavaResult res = serv.Update(new Administrator()
            {
                FirstName = "גדע", LastName = "dsad"
            });

            // Assert
            Assert.True(res is MichtavaFailure);
        }
Exemple #24
0
        public void testAddExistingWordDefinitionDetails()
        {
            Assert.Null(serv.GetByWord(word));
            // Arrange
            int            count    = serv.All().Count();
            WordDefinition existing = serv.All().FirstOrDefault();

            WordDefinition c = new WordDefinition(existing.Word, "some definition");
            // Act

            MichtavaResult res = serv.Add(c);

            // Assert
            Assert.True(res is MichtavaFailure);
        }
        public async Task <ActionResult> Register(StudentRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    UserName = model.UserName,
                    Email    = model.Email,

                    PhoneNumber = model.PhoneNumber,
                };

                IdentityResult result = await UserManager.CreateAsync(user, model.Password);//create the applicationUser through userManager

                if (result.Succeeded)
                {
                    this.UserManager.AddToRole(user.Id, GlobalConstants.StudentRoleName);//assign role of student to newly registered user

                    Student student = new Student();
                    student.ApplicationUserId = user.Id;
                    student.Name = model.Name;
                    //student.ApplicationUser = user;

                    //Mapper.Map<RegisterViewModel, Student>(model, student);//dump the model into the student (in this case, all it does is student.Name = model.Name but in other cases it will apare us a lot of lines of code)
                    //the map is created in frontend/automapperconfig/organizationprofile.cs, here it is just applied.

                    MichtavaResult res = this.studentService.Add(student);//add student to DB through service


                    if (res is MichtavaSuccess)
                    {
                        return(RedirectToAction("Index", "Students", new { area = "Administration" }));//TODO make this work
                    }
                    // return RedirectToAction("Index", "Home", new { area = string.Empty });//getting 404 here
                    else
                    {
                        ModelState.AddModelError(string.Empty, res.Message);
                    }
                }
                else
                {
                    this.AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public void testAddSubjectStandalone()
        {
            Assert.Null(serv.GetByName(n));
            // Arrange
            int count = serv.All().Count();


            // Act
            MichtavaResult res = serv.Add(entity);

            // Assert
            Assert.AreEqual(count + 1, serv.All().Count());
            Assert.NotNull(serv.GetByName(n));
            Assert.True(res is MichtavaSuccess);
            Assert.True(serv.HardDelete(entity) is MichtavaSuccess);
        }
        public void testDeleteSubjectNonExistant()
        {
            Assert.Null(serv.GetByName(n));
            // Arrange
            int count = serv.All().Count();

            entity.setId(Guid.NewGuid());
            Assert.Null(serv.GetById(entity.Id));

            // Act
            MichtavaResult res = serv.Delete(entity);


            // Assert
            Assert.True(res is MichtavaFailure);
        }
        public void testDeleteNonExistantAdministrator()
        {
            Assert.Null(serv.GetByUserName(USERNAME));
            // Arrange
            int count = serv.All().Count();

            entity.setId(Guid.NewGuid());
            Assert.Null(serv.GetById(entity.Id));

            // Act
            MichtavaResult res = serv.Delete(entity);


            // Assert
            Assert.True(res is MichtavaFailure);
        }
Exemple #29
0
        public void testDeleteNonExistantSchoolClass()
        {
            Assert.Null(serv.GetByDetails(23, "ע"));
            // Arrange
            int count = serv.All().Count();

            entity.setId(Guid.NewGuid());
            Assert.Null(serv.GetById(entity.Id));

            // Act
            MichtavaResult res = serv.Delete(entity);


            // Assert
            Assert.True(res is MichtavaFailure);
        }
        public void testAddStandaloneHomework()
        {
            Assert.Null(serv.GetByDetails(hwTitl, hwDesc));
            // Arrange
            int count = serv.All().Count();


            // Act
            MichtavaResult res = serv.Add(entity);

            // Assert
            Assert.AreEqual(count + 1, serv.All().Count());
            Assert.NotNull(serv.GetByDetails(hwTitl, hwDesc));
            Assert.True(res is MichtavaSuccess);
            Assert.True(serv.HardDelete(entity) is MichtavaSuccess);
        }