public void CanGetProfessorsInLinguisticsDepartment()
        {
            AdministratorController admin = new AdministratorController();
            Team55LMSContext        db    = MakeProfessors();

            admin.UseLMSContext(db);

            var     professors = admin.GetProfessors("LING") as JsonResult;
            dynamic result     = professors.Value;

            var lingProfessors = from pro in db.Professors
                                 where pro.Department == "LING"
                                 select pro;

            Assert.Equal("{ lname = Eggert, fname = Randall, uid = u0000002 }", result[0].ToString());
            Assert.Equal("{ lname = Paul Vooge, fname = Nathan, uid = u0000003 }", result[1].ToString());
            Assert.Equal(2, lingProfessors.Count());
        }
        public void GetAllAdministratorReturnsAdminsInLogic()
        {
            var administrators = new List <Administrator> {
                AdministratorModel.ToEntity()
            };
            var administratorsModel = administrators.Select(adm => new AdministratorBasicInfoModel(adm));

            var administratorLogicMock = new Mock <IAdministratorLogic>(MockBehavior.Strict);

            administratorLogicMock.Setup(m => m.GetAll()).Returns(administrators);

            var administratorController = new AdministratorController(administratorLogicMock.Object);
            var result  = administratorController.Get() as OkObjectResult;
            var content = result.Value as List <AdministratorBasicInfoModel>;

            Assert.IsTrue(content.SequenceEqual(administratorsModel));
            administratorLogicMock.VerifyAll();
        }
        public void CanGetMultipleDepartmentsForHistoryDepartment()
        {
            AdministratorController admin = new AdministratorController();
            Team55LMSContext        db    = MakeCourses();

            admin.UseLMSContext(db);

            var     courses = admin.GetCourses("HIST") as JsonResult;
            dynamic results = courses.Value;

            var spanishCourses = from co in db.Courses
                                 where co.SubjectAbbr == "HIST"
                                 select co;

            Assert.Equal(2, spanishCourses.Count());
            Assert.Equal("{ number = 1700, name = American History }", results[0].ToString());
            Assert.Equal("{ number = 1500, name = History of Economy }", results[1].ToString());
        }
        public void CannotCreateClassDifferentClassesSameLocationThatViolateTimeRange()
        {
            AdministratorController admin = new AdministratorController();
            Team55LMSContext        db    = ConfigureDatabaseNoData();

            admin.UseLMSContext(db);

            DateTime start       = new DateTime(2020, 8, 24, 14, 00, 00);
            DateTime end         = new DateTime(2020, 8, 24, 15, 20, 00);
            DateTime secondStart = new DateTime(2020, 8, 24, 13, 45, 0);
            DateTime secondEnd   = new DateTime(2020, 8, 24, 14, 45, 0);

            admin.CreateClass("CS", 2420, "Spring", 2020, start, end, "WEB L104", "Swaroop Joshi");
            var     createClass = admin.CreateClass("BIOL", 2420, "Spring", 2020, secondStart, secondEnd, "WEB L104", "SomeCool BioInstructor") as JsonResult;
            dynamic result      = createClass.Value;

            Assert.Equal("{ success = False }", result.ToString());
        }
        public void CanGetMultipleCoursesForSpanishDepartment()
        {
            AdministratorController admin = new AdministratorController();
            Team55LMSContext        db    = MakeCourses();

            admin.UseLMSContext(db);

            var     courses = admin.GetCourses("SPAN") as JsonResult;
            dynamic results = courses.Value;

            var spanishCourses = from co in db.Courses
                                 where co.SubjectAbbr == "SPAN"
                                 select co;

            Assert.Equal(2, spanishCourses.Count());
            Assert.Equal("{ number = 1010, name = Beginner Spanish I }", results[0].ToString());
            Assert.Equal("{ number = 1020, name = Beginner Spanish II }", results[1].ToString());
        }
        public void CanGetOneCourse()
        {
            AdministratorController admin = new AdministratorController();
            Team55LMSContext        db    = ConfigureDatabaseNoData();

            admin.UseLMSContext(db);
            admin.CreateCourse("RUSS", 1010, "Beginner Russian I");

            var     courses = admin.GetCourses("RUSS") as JsonResult;
            dynamic result  = courses.Value;

            var query = from co in db.Courses
                        where co.SubjectAbbr == "RUSS"
                        select co;

            Assert.True(query.ToArray().Length == 1);
            Assert.Equal("{ number = 1010, name = Beginner Russian I }", result[0].ToString());
        }
Beispiel #7
0
        public void AdminController_QuestionsStatistic_Should_Render_Default_View_With_Correct_Model()
        {
            //Arrange
            List <Question> questions  = new List <Question>();
            var             mockedRepo = new Mock <IEfRepository <Question> >();

            mockedRepo.Setup(r => r.GetAll()).Returns(questions.AsQueryable());
            var mockedProvider = new Mock <IEfSociumDataProvider>();

            mockedProvider.Setup(p => p.Questions).Returns(mockedRepo.Object);
            var mockedService = new Mock <IAdminService>();

            mockedService.Setup(s => s.GetProvider).Returns(mockedProvider.Object);
            AdministratorController controller = new AdministratorController(mockedService.Object);

            //Act & Assert
            controller.WithCallTo(c => c.QuestionsStatistic(1, 0)).ShouldRenderDefaultView().WithModel <IPagedList <Question> >();
        }
        public void CannotCreateClassesOfSameOffering()
        {
            AdministratorController admin = new AdministratorController();
            Team55LMSContext        db    = ConfigureDatabaseNoData();

            admin.UseLMSContext(db);

            DateTime start = new DateTime(2020, 8, 24, 14, 00, 00);
            DateTime end   = new DateTime(2020, 8, 24, 15, 20, 00);

            admin.CreateClass("CS", 2420, "Spring", 2020, start, end, "WEB L104", "Swaroop Joshi");
            var     createClass = admin.CreateClass("CS", 2420, "Spring", 2020, start, end, "WEB L104", "Swaroop Joshi") as JsonResult;
            dynamic result      = createClass.Value;

            var classes = from cla in db.Classes
                          select cla;

            Assert.Equal("{ success = False }", result.ToString());
        }
        public void CanGetMultipleDepartmentsForCSDepartment()
        {
            AdministratorController admin = new AdministratorController();
            Team55LMSContext        db    = MakeCourses();

            admin.UseLMSContext(db);

            var     courses = admin.GetCourses("CS") as JsonResult;
            dynamic results = courses.Value;

            var spanishCourses = from co in db.Courses
                                 where co.SubjectAbbr == "CS"
                                 select co;

            Assert.Equal(3, spanishCourses.Count());
            Assert.Equal("{ number = 4400, name = Computer Systems }", results[0].ToString());
            Assert.Equal("{ number = 5955, name = Deep Learning }", results[1].ToString());
            Assert.Equal("{ number = 3520, name = Programming Languages }", results[2].ToString());
        }
        public void CanGetProfessorsInMathematicsDepartment()
        {
            AdministratorController admin = new AdministratorController();
            Team55LMSContext        db    = MakeProfessors();

            admin.UseLMSContext(db);

            var     professors = admin.GetProfessors("MATH") as JsonResult;
            dynamic result     = professors.Value;

            var mathProfessors = from pro in db.Professors
                                 where pro.Department == "MATH"
                                 select pro;

            Assert.Equal("{ lname = McArthur, fname = Kelly, uid = u0000004 }", result[0].ToString());
            Assert.Equal("{ lname = Cecil, fname = Matthew, uid = u0000005 }", result[1].ToString());
            Assert.Equal("{ lname = Rowland, fname = Ashley, uid = u0000006 }", result[2].ToString());
            Assert.Equal(3, mathProfessors.Count());
        }
Beispiel #11
0
        public void DeleteAdminTest()
        {
            Administrator administrator = new Administrator()
            {
                Email    = "*****@*****.**",
                Password = "******"
            };
            string token             = "token";
            var    mockAdministrator = new Mock <IAdministratorLogic>(MockBehavior.Strict);

            mockAdministrator.Setup(p => p.Delete(It.IsAny <Administrator>())).Returns(administrator);
            mockAdministrator.Setup(p => p.GetById(It.IsAny <int>())).Returns(administrator);
            var mockSession = new Mock <ISessionLogic>(MockBehavior.Strict);
            var controller  = new AdministratorController(mockAdministrator.Object, mockSession.Object);

            controller.Delete(1);

            mockAdministrator.VerifyAll();
        }
        public void TestAddClassStartConflict()
        {
            var db = AddClasses();

            AdministratorController controller = new AdministratorController();

            controller.UseLMSContext(db);

            var result = controller.CreateClass("CS", 1, "Spring", 2019, new DateTime(2009, 05, 30, 7, 25, 49),
                                                new DateTime(2009, 05, 30, 9, 25, 49), "MEB 3232", "u0000000") as JsonResult;

            dynamic jdata = result.Value;

            var query = from c in db.Classes
                        select c;

            //Assert.Equal(true, jdata.ToString().Contains("False"));
            //Assert.Equal(1, query.Count());
        }
Beispiel #13
0
        private void button10_Click(object sender, EventArgs e)
        {
            Medication m = new Medication();

            if (lastMedicationId != -1)
            {
                m = AdministratorController.GetMedication(lastMedicationId);
            }
            else
            {
                m.Ingredients = textBox7.Text;
            }

            IngredientsView form = new IngredientsView(m.Ingredients);

            form.ShowDialog();

            textBox7.Text = form.ingredients;
        }
        public async Task Test_Post_SaveToFile(string filename, int?yearStart, int?yearEnd, string name)
        {
            // Arrange
            var language = new SaveLanguageModel
            {
                GeoJson   = System.IO.File.ReadAllText($"{polygonPath}/{filename}"),
                YearStart = yearStart,
                YearEnd   = yearEnd,
                Name      = name
            };

            var controller = new AdministratorController(this.loggerMock.Object, this.contextFactory, this.helperMock.Object);

            // Act
            var result = await controller.SaveToFile(language);

            // Assert
            var viewResult = Assert.IsType <OkResult>(result);
        }
Beispiel #15
0
        public void TestLoginOK()
        {
            Administrator administrator = new Administrator()
            {
                Email    = "*****@*****.**",
                Password = "******"
            };
            string token             = "token";
            var    mockAdministrator = new Mock <IAdministratorLogic>(MockBehavior.Strict);

            mockAdministrator.Setup(p => p.GetByEmailAndPassword(It.IsAny <string>(), It.IsAny <string>())).Returns(administrator);
            var mockSession = new Mock <ISessionLogic>(MockBehavior.Strict);

            mockSession.Setup(p => p.GenerateToken(It.IsAny <Administrator>())).Returns(token);
            var controller = new AdministratorController(mockAdministrator.Object, mockSession.Object);

            var result = controller.Login("admin", "123") as OkObjectResult;

            mockAdministrator.VerifyAll();
            Assert.AreEqual(200, result.StatusCode);
        }
Beispiel #16
0
        public void AdminController_UsersStatistic_Should_Return_View_Result()
        {
            //Arrange
            List <ApplicationUser> users = new List <ApplicationUser>();
            var mockedRepo = new Mock <IEfRepository <ApplicationUser> >();

            mockedRepo.Setup(r => r.GetAll()).Returns(users.AsQueryable());
            var mockedProvider = new Mock <IEfSociumDataProvider>();

            mockedProvider.Setup(p => p.Users).Returns(mockedRepo.Object);
            var mockedService = new Mock <IAdminService>();

            mockedService.Setup(s => s.GetProvider).Returns(mockedProvider.Object);
            AdministratorController controller = new AdministratorController(mockedService.Object);

            //Act
            var result = controller.UsersStatistic(1, 0);

            //Assert
            Assert.IsInstanceOf <ViewResult>(result);
        }
        public void TestCreateCourseAddExistingCourse()
        {
            var db = mockDB();

            AdministratorController controller = new AdministratorController();

            controller.UseLMSContext(db);

            var result = controller.CreateCourse("HF", 1550, "Classical Mythology") as JsonResult;

            dynamic jdata = result.Value;

            Assert.Equal(true, jdata.ToString().Contains("True"));

            // Return false if course already exists
            var result2 = controller.CreateCourse("HF", 1550, "Classical Mythology") as JsonResult;

            dynamic jdata2 = result2.Value;

            Assert.Equal(true, jdata2.ToString().Contains("False"));
        }
Beispiel #18
0
        public void GetAllTest()
        {
            Administrator admin = new Administrator()
            {
                Email    = "*****@*****.**",
                Password = "******"
            };
            List <Administrator> expected = new List <Administrator>()
            {
                admin
            };
            var mockAdministrator = new Mock <IAdministratorLogic>(MockBehavior.Strict);

            mockAdministrator.Setup(p => p.GetAll()).Returns(expected);
            var mockSession = new Mock <ISessionLogic>(MockBehavior.Strict);
            var controller  = new AdministratorController(mockAdministrator.Object, mockSession.Object);

            var result = controller.Get() as OkObjectResult;

            mockAdministrator.VerifyAll();
            Assert.AreEqual(200, result.StatusCode);
        }
Beispiel #19
0
        private void RefreshTab2Fields()
        {
            if (lastUserId != -1)
            {
                //update
                var user = AdministratorController.GetUser(lastUserId);

                textBox9.Text  = user.Id.ToString();
                textBox10.Text = user.Username;
                textBox11.Text = user.Name;
                textBox12.Text = user.Password;
            }
            else
            {
                //new

                textBox9.Text  = "";
                textBox10.Text = "";
                textBox11.Text = "";
                textBox12.Text = "";
            }
        }
Beispiel #20
0
        protected Team63LMSContext AddClasses2()
        {
            Team63LMSContext db = mockDB();

            AdministratorController controller = new AdministratorController();

            controller.UseLMSContext(db);

            // Create Professor to teach class
            Professors p = new Professors();

            p.FName   = "Danny";
            p.LName   = "Kopta";
            p.UId     = uIDGen(db);
            p.WorksIn = "CS";

            db.Professors.Add(p);
            db.SaveChanges();

            controller.CreateCourse("CS", 5530, "Database Systems");

            return(db);
        }
Beispiel #21
0
        public void AdminController_UsersStatistic_Should_Call_RepoUsers_GetAll()
        {
            //Arrange
            List <ApplicationUser> users = new List <ApplicationUser>();
            var mockedRepo = new Mock <IEfRepository <ApplicationUser> >();

            mockedRepo.Setup(r => r.GetAll()).Returns(users.AsQueryable());
            var mockedProvider = new Mock <IEfSociumDataProvider>();

            mockedProvider.Setup(p => p.Users).Returns(mockedRepo.Object);
            var mockedService = new Mock <IAdminService>();

            mockedService.Setup(s => s.GetProvider).Returns(mockedProvider.Object);
            AdministratorController controller = new AdministratorController(mockedService.Object);

            //Act
            controller.UsersStatistic(1, 0);
            controller.UsersStatistic(1, 1);
            controller.UsersStatistic(1, 2);

            //Assert
            mockedRepo.Verify(r => r.GetAll(), Times.Exactly(6));
        }
Beispiel #22
0
        public void Setup()
        {
            courseCategoriesDataService     = A.Fake <ICourseCategoriesDataService>();
            userDataService                 = A.Fake <IUserDataService>();
            centreContractAdminUsageService = A.Fake <ICentreContractAdminUsageService>();
            userService = A.Fake <IUserService>();
            searchSortFilterPaginateService = A.Fake <ISearchSortFilterPaginateService>();

            httpRequest  = A.Fake <HttpRequest>();
            httpResponse = A.Fake <HttpResponse>();
            const string cookieValue = "Role|IsCentreAdmin|true";

            administratorController = new AdministratorController(
                userDataService,
                courseCategoriesDataService,
                centreContractAdminUsageService,
                userService,
                searchSortFilterPaginateService
                )
                                      .WithMockHttpContext(httpRequest, CookieName, cookieValue, httpResponse)
                                      .WithMockUser(true)
                                      .WithMockServices()
                                      .WithMockTempData();
        }
Beispiel #23
0
        public void CreateAdminTest()
        {
            Administrator administrator = new Administrator()
            {
                Email    = "*****@*****.**",
                Password = "******"
            };
            AdministratorModelIn administratorModelIn = new AdministratorModelIn()
            {
                Email    = administrator.Email,
                Password = administrator.Password
            };
            string token             = "token";
            var    mockAdministrator = new Mock <IAdministratorLogic>(MockBehavior.Strict);

            mockAdministrator.Setup(p => p.AddAdministrator(It.IsAny <Administrator>())).Returns(administrator);
            var mockSession = new Mock <ISessionLogic>(MockBehavior.Strict);
            var controller  = new AdministratorController(mockAdministrator.Object, mockSession.Object);

            var result = controller.CreateAdmin(administratorModelIn) as OkObjectResult;

            mockAdministrator.VerifyAll();
            Assert.AreEqual(200, result.StatusCode);
        }
        public void TestGetProfessors()
        {
            var db = AddProfessor();

            AdministratorController controller = new AdministratorController();

            controller.UseLMSContext(db);

            var result = controller.GetProfessors("CS") as JsonResult;

            dynamic jdata = result.Value;

            Assert.Equal(1, jdata.Length);


            var query = from p in db.Professors
                        select p;

            Assert.Equal("John", query.ToArray()[0].FName);
            Assert.Equal("Doe", query.ToArray()[0].LName);
            Assert.Equal("u0000000", query.ToArray()[0].UId);
            Assert.Equal("CS", query.ToArray()[0].WorksIn);
            Assert.Contains("10/23/1997", query.ToArray()[0].Dob.ToString());
        }
Beispiel #25
0
 private void button9_Click(object sender, EventArgs e)
 {
     AdministratorController.ExportMedication();
     Process.Start("explorer.exe", "/select," + Path.GetFullPath("medication.xml"));
 }
Beispiel #26
0
 private void button7_Click(object sender, EventArgs e)
 {
     AdministratorController.GenerateReport(radioButton1.Checked ? "CSV" : "PDF");
     Process.Start("explorer.exe", "/select," + Path.GetFullPath(radioButton1.Checked ? "report.csv" : "report.pdf"));
     MessageBox.Show("Success!");
 }
Beispiel #27
0
        protected Team63LMSContext AddStudentstoMultipleClasses()
        {
            Team63LMSContext        db         = mockDB();
            AdministratorController controller = new AdministratorController();

            controller.UseLMSContext(db);

            StudentController sController = new StudentController();

            sController.UseLMSContext(db);

            // Create Professor to teach class
            Professors p = new Professors();

            p.FName   = "Danny";
            p.LName   = "Kopta";
            p.UId     = uIDGen(db);
            p.WorksIn = "CS";

            db.Professors.Add(p);
            db.SaveChanges();

            controller.CreateCourse("CS", 5530, "Database Systems");
            controller.CreateCourse("CS", 4400, "Computer Systems");
            controller.CreateCourse("CS", 3500, "Software Practice I");

            controller.CreateClass("CS", 1, "Spring", 2019, new DateTime(2009, 05, 30, 7, 9, 16),
                                   new DateTime(2009, 05, 30, 9, 16, 25), "WEB 1250", "u0000000");

            controller.CreateClass("CS", 4400, "Spring", 2019, new DateTime(2009, 05, 30, 7, 9, 16),
                                   new DateTime(2009, 05, 30, 9, 16, 25), "WEB 2000", "u0000000");

            controller.CreateClass("CS", 3500, "Spring", 2019, new DateTime(2009, 05, 30, 7, 9, 16),
                                   new DateTime(2009, 05, 30, 9, 16, 25), "WEB 1999", "u0000000");

            //Add student to class
            Students s = new Students();

            s.UId   = "u0000001";
            s.FName = "Steen";
            s.LName = "Sia";
            s.Dob   = new DateTime(2000, 07, 01);
            s.Major = "Electrical Engineering";

            Students s2 = new Students();

            s.UId   = "u0000002";
            s.FName = "Benjamin";
            s.LName = "Button";
            s.Dob   = new DateTime(2000, 07, 01);
            s.Major = "Electrical Engineering";

            Students s3 = new Students();

            s.UId   = "u0000003";
            s.FName = "J";
            s.LName = "Fish";
            s.Dob   = new DateTime(2000, 07, 01);
            s.Major = "Computer Science";

            db.Students.Add(s);
            db.Students.Add(s2);
            db.Students.Add(s3);
            db.SaveChanges();

            sController.Enroll("CS", 5530, "Spring", 2019, "u0000001");
            sController.Enroll("CS", 5530, "Spring", 2019, "u0000002");
            sController.Enroll("CS", 4400, "Spring", 2019, "u0000001");
            sController.Enroll("CS", 4400, "Spring", 2019, "u0000002");
            sController.Enroll("CS", 3500, "Spring", 2019, "u0000003");
            sController.Enroll("CS", 3500, "Spring", 2019, "u0000001");

            return(db);
        }