Exemplo n.º 1
0
        public ActionResult Update([Bind(Include =
                                             "Id," +
                                             "Password," +
                                             "SelectedTimeZoneId" +
                                             "")] KioskSettingsModel data)
        {
            if (data == null)
            {
                // Send to Error Page
                return(RedirectToAction("Error", "Home"));
            }

            if (!ModelState.IsValid)
            {
                // Send back for edit
                return(View(data));
            }

            if (string.IsNullOrEmpty(data.Id))
            {
                // Send back for edit
                return(View(data));
            }

            KioskSettingsBackend.Update(data);

            return(RedirectToAction("Settings", "Admin"));
        }
Exemplo n.º 2
0
        public ActionResult Login([Bind(Include =
                                            "Password," +
                                            "")] KioskSettingsModel data)
        {
            if (!ModelState.IsValid)
            {
                // Send back for edit, with Error Message
                return(View(data));
            }

            if (string.IsNullOrEmpty(data.Password))
            {
                ModelState.AddModelError("Password", "Please Enter a Password.");
                return(View(data));
            }

            var myKioskData = DataSourceBackend.Instance.KioskSettingsBackend.GetDefault();

            // GetDefault always returns valid data.

            // If the passwords match, then redirect
            if (data.Password.Equals(myKioskData.Password))
            {
                //Todo, set flag to mark the current token for the kiosk
                return(RedirectToAction("Index", "Kiosk"));
            }

            // Login failed, so send back with error message
            ModelState.AddModelError("Password", "Invalid login attempt.");
            return(View(data));
        }
Exemplo n.º 3
0
        public ActionResult Update([Bind(Include =
                                             "Id," +
                                             "Password," +
                                             "SelectedTimeZoneId" +
                                             "")] KioskSettingsModel data)
        {
            var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext);

            if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.TeacherUser))
            {
                return(RedirectToAction("Login", "Admin"));
            }

            if (!ModelState.IsValid)
            {
                // Send back for edit
                return(View(data));
            }

            if (data == null)
            {
                // Send to Error Page
                return(RedirectToAction("Error", "Home"));
            }

            if (string.IsNullOrEmpty(data.Id))
            {
                // Send back for edit
                return(View(data));
            }

            KioskSettingsBackend.Update(data);

            return(RedirectToAction("Settings", "Admin"));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get the Default data set, and then add it to the current
        /// </summary>
        private void CreateDataSetDefault()
        {
            // Call over to the Settings Model itself to have it set it's default settings
            var Temp = new KioskSettingsModel();

            Temp.SetDefault();
            Create(Temp);
        }
Exemplo n.º 5
0
        public void Models_KioskSettings_Instantiate_Get_Default_Time_Zone_Should_Pass()
        {
            // Arrange
            var myModelNew       = new KioskSettingsModel();
            var expectedTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");

            // Assert
            Assert.AreEqual(expectedTimeZone, myModelNew.TimeZone, TestContext.TestName);
        }
Exemplo n.º 6
0
        public void Models_KioskSettings_Default_Instantiate_Should_Pass()
        {
            // Arrange
            var myModel = new KioskSettingsModel();

            // Act
            var result = myModel;

            // Assert
            Assert.AreEqual(result.Password, new KioskSettingsModel().Password, TestContext.TestName);
        }
Exemplo n.º 7
0
        public void Models_KioskSettings_Instantiate_Get_ID_Should_Pass()
        {
            // Arrange
            var myModelNew = new KioskSettingsModel();
            var expectId   = "GoodId1";

            // Act
            myModelNew.Id = expectId;

            // Assert
            Assert.AreEqual(expectId, myModelNew.Id, TestContext.TestName);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Makes a new KioskSettings
        /// </summary>
        /// <param name="data"></param>
        /// <returns>KioskSettings Passed In</returns>
        public KioskSettingsModel Create(KioskSettingsModel data, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
        {
            // If using the defaul data source, use it, else just do the table operation
            if (dataSourceEnum == DataSourceEnum.Unknown)
            {
                DataList.Add(data);
            }

            // Add to Storage
            var myResult = DataSourceBackendTable.Instance.Create <KioskSettingsModel>(tableName, partitionKey, data.Id, data, dataSourceEnum);

            return(data);
        }
Exemplo n.º 9
0
        public void Models_KioskSettings_Instantiate_Get_LastProcessedDate_Should_Pass()
        {
            // Arrange
            var expected = DateTime.UtcNow;

            // Act
            var result = new KioskSettingsModel
            {
                LastProcessedDate = expected
            };

            // Assert
            Assert.AreEqual(expected, result.LastProcessedDate, TestContext.TestName);
        }
        public void Backend_KioskSettingsDataSourceMock_Update_Invalid_Data_Should_Fail()
        {
            // Arrange
            var backend   = KioskSettingsDataSourceMock.Instance;
            var testModel = new KioskSettingsModel();

            // Act
            var result = backend.Update(testModel);

            //Reset
            backend.Reset();

            // Assert
            Assert.IsNull(result, TestContext.TestName);
        }
Exemplo n.º 11
0
        public void Controller_Kiosk_Login_InValid_Password_Null_Should_Fail()
        {
            // Arrange
            var    controller = new KioskController();
            string Password   = KioskSettingsBackend.Instance.GetDefault().Password;

            var data = new KioskSettingsModel
            {
                Password = null
            };

            ViewResult result = controller.Login(data) as ViewResult;

            // Assert
            Assert.AreEqual(controller.ModelState.IsValid, false, TestContext.TestName);
        }
Exemplo n.º 12
0
        public void Models_KioskSettings_SetDefault_Default_Should_Pass()
        {
            // Arrange
            var myModel = new KioskSettingsModel
            {
                Password = "******"
            };
            var expect = myModel.Password;

            // Act
            myModel.SetDefault();
            var result = myModel.Password;

            // Assert
            Assert.AreNotEqual(expect, result, TestContext.TestName);
        }
Exemplo n.º 13
0
        public void Models_KioskSettings_Instantiate_With_Data_Null_Should_Fail()
        {
            // Null does nothing.

            // Arrange
            var myTemp = new KioskSettingsModel();

            myTemp.SetDefault();
            var expect = myTemp.Password;

            // Act
            var myModel = new KioskSettingsModel(null);
            var result  = myModel.Password;

            // Assert
            Assert.AreEqual(null, result, TestContext.TestName);
        }
        /// <summary>
        /// Update all attributes to be what is passed in
        /// </summary>
        /// <param name="data"></param>
        /// <returns>Null or updated data</returns>
        public KioskSettingsModel Update(KioskSettingsModel data)
        {
            if (data == null)
            {
                return(null);
            }
            var myReturn = KioskSettingsList.Find(n => n.Id == data.Id);

            if (myReturn == null)
            {
                return(null);
            }

            myReturn.Update(data);

            return(myReturn);
        }
Exemplo n.º 15
0
        public void Controller_Kiosk_Login_Valid_Password_Should_Pass()
        {
            // Arrange
            var    controller = new KioskController();
            string Password   = KioskSettingsBackend.Instance.GetDefault().Password;

            var data = new KioskSettingsModel
            {
                Password = Password
            };

            // Act
            var result = (RedirectToRouteResult)controller.Login(data);

            // Assert
            Assert.AreEqual("Index", result.RouteValues["action"], TestContext.TestName);
        }
Exemplo n.º 16
0
        public void Models_KioskSettings_Instantiate_With_Data_Should_Pass()
        {
            // Arrange
            var myModelNew = new KioskSettingsModel
            {
                // Set values to test
                Password = "******",
                Id       = "test"
            };
            var expect = myModelNew.Password;

            // Act
            var myModel = new KioskSettingsModel(myModelNew);
            var result  = myModel.Password;

            // Assert
            Assert.AreEqual(expect, result, TestContext.TestName);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Update all attributes to be what is passed in
        /// </summary>
        /// <param name="data"></param>
        /// <returns>Null or updated data</returns>
        public KioskSettingsModel Update(KioskSettingsModel data)
        {
            if (data == null)
            {
                return(null);
            }

            var myReturn = DataSource.Update(data);

            //Todo: not ready yet, need to work out how to call for Resetting of the Calendar properly
            //if (myReturn != null)
            //{
            //    // Changes to the Update, means a setting on the calendar is different.
            //    // Need to go through the calendar and change things.  That way a change to the dismissal time is reflected if changed etc.
            //    SchoolCalendarBackend.Instance.ResetDefaults();
            //}

            return(myReturn);
        }
Exemplo n.º 18
0
        public void Controller_KioskSettings_Post_Update_Default_Should_Return_Admin_Settings_Page()
        {
            // Arrange
            var controller = new KioskSettingsController();

            // Get default KioskSettingsModel
            KioskSettingsModel kioskSettingsModel = DataSourceBackend.Instance.KioskSettingsBackend.GetDefault();

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            var result = (RedirectToRouteResult)controller.Update(kioskSettingsModel);

            // Assert
            Assert.AreEqual("Settings", result.RouteValues["action"], TestContext.TestName);
            Assert.AreEqual("Admin", result.RouteValues["controller"], TestContext.TestName);
        }
Exemplo n.º 19
0
        public void Controller_KioskSettings_Post_Update_Invalid_Model_Should_Send_Back_For_Edit()
        {
            // Arrange
            var controller          = new KioskSettingsController();
            KioskSettingsModel data = new KioskSettingsModel();

            // Make ModelState Invalid
            controller.ModelState.AddModelError("test", "test");

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            ViewResult result = (ViewResult)controller.Update(data);

            // Assert
            Assert.IsNotNull(result, TestContext.TestName);
        }
Exemplo n.º 20
0
        public void Models_KioskSettings_Update_Default_Should_Pass()
        {
            // Arrange
            var myModel = new KioskSettingsModel();

            myModel.SetDefault();

            // Set values to test
            myModel.Password = "******";
            myModel.Id       = "test";
            var expect = myModel.Password;

            // Act
            myModel.Update(myModel);
            var result = myModel.Password;

            // Assert
            Assert.AreEqual(expect, result, TestContext.TestName);
        }
Exemplo n.º 21
0
        public void Controller_KioskSettings_Post_Update_Empty_Id_Should_Send_Back_For_Edit()
        {
            // Arrange
            var controller = new KioskSettingsController();
            KioskSettingsModel dataEmpty = new KioskSettingsModel
            {
                // Make data.Id empty
                Id = ""
            };

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            var resultEmpty = (ViewResult)controller.Update(dataEmpty);

            // Assert
            Assert.IsNotNull(resultEmpty, TestContext.TestName);
        }
Exemplo n.º 22
0
        public void Controller_Kiosk_Login_InValid_Model_Null_Should_Fail()
        {
            // Arrange
            var    controller = new KioskController();
            string Password   = KioskSettingsBackend.Instance.GetDefault().Password;

            var data = new KioskSettingsModel
            {
                Password = Password
            };

            // Make a model error then try to send it as a KioskSettings
            controller.ModelState.AddModelError("test", "test");

            // Act
            ViewResult result = controller.Login(data) as ViewResult;

            // Assert
            Assert.AreEqual(controller.ModelState.IsValid, false, TestContext.TestName);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Update all attributes to be what is passed in
        /// </summary>
        /// <param name="data"></param>
        /// <returns>Null or updated data</returns>
        public KioskSettingsModel Update(KioskSettingsModel data)
        {
            if (data == null)
            {
                return(null);
            }
            var myReturn = DataList.Find(n => n.Id == data.Id);

            if (myReturn == null)
            {
                return(null);
            }

            myReturn.Update(data);

            // Update Storage
            var myResult = DataSourceBackendTable.Instance.Create <KioskSettingsModel>(tableName, partitionKey, data.Id, data);

            return(data);
        }
 /// <summary>
 /// Makes a new KioskSettings
 /// </summary>
 /// <param name="data"></param>
 /// <returns>KioskSettings Passed In</returns>
 public KioskSettingsModel Create(KioskSettingsModel data, DataSourceEnum dataSourceEnum = DataSourceEnum.Unknown)
 {
     KioskSettingsList.Add(data);
     return(data);
 }