public async Task testAuthenticateNonExistentUser() { using (var context = new LanguageAPIContext(options)) { //Given UserInfo user = new UserInfo() { username = "******", password = "******" }; //When UserInfoController userInfoController = new UserInfoController(context); IActionResult result = await userInfoController.AuthenticateUser(user); var userExists = await context.UserInfo.Where(u => u.username == user.username ).AnyAsync(); var dbUser = await context.UserInfo.Where(u => u.username == user.username ).FirstOrDefaultAsync(); Assert.IsNull(dbUser); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(BadRequestResult)); Assert.IsTrue(!userExists); context.SaveChanges(); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { dataTable.Columns.Add("Number", typeof(int)); dataTable.Columns.Add("RotationID", typeof(Guid)); dataTable.Columns.Add("RotationName", typeof(string)); dataTable.Columns.Add("OperationName", typeof(string)); dataTable.Columns.Add("TubesBatchName", typeof(string)); dataTable.Columns.Add("TubesBatchID", typeof(string)); dataTable.Columns.Add("State", typeof(string)); dataTable.Columns.Add("PCRTestResult", typeof(string)); dataTable.Columns.Add("Color", typeof(string)); dataTable.Columns.Add("logTitle", typeof(string)).DefaultValue = "查看日志"; dataGrid_view.ItemsSource = dataTable.DefaultView; UserInfoController userInfoController = new UserInfoController(); RoleInfo userRole = userInfoController.GetRoleByUserName(SessionInfo.LoginName); ExperimentsInfo experimentInfo = new WanTai.Controller.HistoryQuery.ExperimentsController().GetExperimentById(experimentId); if (SessionInfo.LoginName == experimentInfo.LoginName || (userRole != null && userRole.RoleLevel > 1)) { btnImportPCRResult.Visibility = System.Windows.Visibility.Visible; } else { btnImportPCRResult.Visibility = System.Windows.Visibility.Hidden; } this.ExperimentName_label.Content = experimentName; initDataGrid(); }
public async Task testAddUserwithNoPassword() { using (var context = new LanguageAPIContext(options)) { //Given UserInfo user = new UserInfo() { username = "******", password = "" }; //When UserInfoController userInfoController = new UserInfoController(context); IActionResult result = await userInfoController.RegisterUser(user); var userExists = await context.UserInfo.Where(u => u.username == user.username ).AnyAsync(); var dbUser = await context.UserInfo.Where(u => u.username == user.username ).FirstOrDefaultAsync(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(UnprocessableEntityResult)); Assert.IsTrue(!userExists); Assert.IsNull(dbUser); context.SaveChanges(); } }
private void dataGrid_view_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e) { DataGridCellInfo Cell = ((System.Windows.Controls.DataGrid)(e.Source)).CurrentCell; if (Cell.Column.Header.ToString() == "检测结果") { if (dataTable.Rows[dataGrid_view.SelectedIndex]["PCRTestItemID"] != null && dataTable.Rows[dataGrid_view.SelectedIndex]["PCRTestItemID"] != DBNull.Value) { UserInfoController userInfoController = new UserInfoController(); RoleInfo userRole = userInfoController.GetRoleByUserName(SessionInfo.LoginName); ExperimentsInfo experimentInfo = new WanTai.Controller.HistoryQuery.ExperimentsController().GetExperimentById(experimentId); if (SessionInfo.LoginName == experimentInfo.LoginName || (userRole != null && userRole.RoleLevel > 1)) { EditPCRTestResult editPCRResult = new EditPCRTestResult(); editPCRResult.SetCurrentData(dataTable.Rows[dataGrid_view.SelectedIndex]); editPCRResult.ExperimentID = experimentId; bool dialogResult = (bool)editPCRResult.ShowDialog(); if (dialogResult) { loadDataGrid(); } } else { ViewPCRTestResult viewPCRResult = new ViewPCRTestResult(); viewPCRResult.SetCurrentData(dataTable.Rows[dataGrid_view.SelectedIndex]); viewPCRResult.ShowDialog(); } } } else { return; } }
public ChangePassword() { InitializeComponent(); userInfoController = new UserInfoController(); txtUserName.Text = SessionInfo.LoginName; }
public async Task testAuthenticateUserWrongPassword() { using (var context = new LanguageAPIContext(options)) { //Given UserInfo user = new UserInfo() { username = "******", password = "******" }; //When UserInfoController userInfoController = new UserInfoController(context); IActionResult result = await userInfoController.AuthenticateUser(user); var userExists = await context.UserInfo.Where(u => u.username == user.username ).AnyAsync(); var dbUser = await context.UserInfo.Where(u => u.username == user.username ).FirstOrDefaultAsync(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(UnauthorizedResult)); Assert.IsTrue(userExists); Assert.AreEqual(dbUser.username, user.username); Assert.AreNotEqual(dbUser.password, user.password); context.SaveChanges(); } }
public UserInfoControllerTest() { ILoggerFactory doesntDoMuch = new Microsoft.Extensions.Logging.Abstractions.NullLoggerFactory(); Logger <UserInfo> _logger = new Logger <UserInfo>(doesntDoMuch); _service = new UserInfoServiceMock(); _controller = new UserInfoController(_service, _logger); }
public override void startWindow() { base.startWindow(); systemController = SystemController.get(); gameObject.SetActive(true); dataController = new UserInfoController(); startWait(); dataController.requestUserInfo(onReceivedUserInfo); }
public void Put() { // Arrange UserInfoController controller = new UserInfoController(); // Act //controller.Put(5, "value"); // Assert }
public void Delete() { // Arrange UserInfoController controller = new UserInfoController(); // Act //controller.Delete(5); // Assert }
public AddUser() { InitializeComponent(); userInfoController = new UserInfoController(); comboRole.ItemsSource = new RoleInfoController().GetAll(); comboRole.DisplayMemberPath = "RoleName"; comboRole.SelectedValuePath = "RoleName"; comboRole.SelectedIndex = 0; }
public void GetById() { // Arrange UserInfoController controller = new UserInfoController(); // Act //string result = controller.Get(5); // Assert //Assert.AreEqual("value", result); }
public void TestUpdateContactById() { //Arrange var testGetContacts = GetAllContacts(); UserInfoController mvcContr = new UserInfoController(); //Act ActionResult result = mvcContr.AddOrEdit(1); //Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(System.Web.Mvc.ViewResult)); }
public void TestContactContact() { //Arrange var testGetContacts = GetAllContacts(); UserInfoController mvcContr = new UserInfoController(); //Act ActionResult result = mvcContr.Delete(1); //Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(System.Web.Mvc.RedirectToRouteResult)); }
public void TestGetContactsWithModelObject() { //Arrange var testGetContacts = GetAllContacts(); UserInfoController mvcContr = new UserInfoController(); mvcUserInfoModel model = new mvcUserInfoModel(); //Act var result = mvcContr.AddOrEdit(model); //Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(System.Web.Mvc.RedirectToRouteResult)); }
public int GetTotalCount(string experimentName, LogInfoLevelEnum logLevel) { int count = 0; try { string connectionString = WanTai.Common.Configuration.GetConnectionString(); ///todo: add control,each role user only can see the specific experiments string commandText = "SELECT count(LogID) FROM LogInfo left join ExperimentsInfo on LogInfo.ExperimentID = ExperimentsInfo.ExperimentID"; commandText = commandText + " WHERE LogInfo.LogLevel = " + (int)logLevel; if (!string.IsNullOrEmpty(experimentName)) { commandText = commandText + " AND ExperimentsInfo.ExperimentName like '%" + experimentName + "%'"; } UserInfoController userInfoController = new UserInfoController(); RoleInfo userRole = userInfoController.GetRoleByUserName(SessionInfo.LoginName); if (userInfoController.GetAuthorize(AccessAuthority.LogInfo) == AccessAuthority.All) { commandText = commandText + @" AND (LogInfo.LoginName IS NULL or LogInfo.LoginName in (SELECT LoginName FROM UserInfo u left join roleinfo r on r.RoleName=u.RoleName WHERE r.RoleLevel<=" + userRole.RoleLevel + " ))"; } else { commandText = commandText + " AND LogInfo.LoginName='" + SessionInfo.LoginName + "'"; } using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); using (SqlCommand cmd = new SqlCommand(commandText, conn)) { using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default)) { if (reader.Read()) { count = (int)reader.GetValue(0); } } } } } catch (Exception e) { string errorMessage = e.Message + System.Environment.NewLine + e.StackTrace; LogInfoController.AddLogInfo(LogInfoLevelEnum.Error, errorMessage, SessionInfo.LoginName, this.GetType().ToString() + "->GetTotalCount", SessionInfo.ExperimentID); throw; } return(count); }
public UserList() { InitializeComponent(); roleInfoController = new RoleInfoController(); userInfoController = new UserInfoController(); comRole.ItemsSource = roleInfoController.GetAll(); dtUsers = new DataTable(); dtUsers.Columns.Add("Index", typeof(int)); dtUsers.Columns.Add("UserID", typeof(Guid)); dtUsers.Columns.Add("LoginName", typeof(string)); dtUsers.Columns.Add("LoginPassWord", typeof(string)); dtUsers.Columns.Add("RoleName", typeof(string)); BindUserInfo(); }
private void Authorize() { RoleInfo userInfo = new UserInfoController().GetRoleByUserName(SessionInfo.LoginName); StringReader reader = new StringReader(userInfo.RoleModules); DataSet dataset = new DataSet(); DataTable dataTable = new DataTable("Menu"); DataColumn column1 = new DataColumn("menuName", typeof(string)); column1.ColumnMapping = MappingType.Attribute; DataColumn column2 = new DataColumn("access", typeof(string)); column2.ColumnMapping = MappingType.Attribute; dataTable.Columns.Add(column1); dataTable.Columns.Add(column2); dataset.Tables.Add(dataTable); dataset.ReadXml(reader, XmlReadMode.Fragment); reader.Close(); for (int i = 0; i < dataTable.Rows.Count; i++) { string menuName = dataTable.Rows[i]["menuName"].ToString(); string access = dataTable.Rows[i]["access"].ToString(); object obj = this.FindName(menuName); if (obj is UIElement) { ((UIElement)obj).Visibility = access == "1" ? Visibility.Visible : Visibility.Collapsed; //if ((obj is RibbonButton) && access != "1") //{ // ((RibbonButton)obj).Width = 0; //} } } //Thread therad = new Thread(new ThreadStart(delegate() //{ // string RotationName=string.Empty; // while (CloseFalg) // { // if (SessionInfo.PraperRotation != null && SessionInfo.PraperRotation.RotationName != RotationName) // { // SessionInfo.PraperRotation.RotationName = RotationName; // ShowText(SessionInfo.PraperRotation.RotationName); // } // Thread.Sleep(1000*10); // } //})); // therad.Start(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { UserInfoController userInfoController = new UserInfoController(); RoleInfo userRole = userInfoController.GetRoleByUserName(SessionInfo.LoginName); ExperimentsInfo experimentInfo = new WanTai.Controller.HistoryQuery.ExperimentsController().GetExperimentById(pCRTestResultDataGridUserControl.ExperimentId); if (SessionInfo.LoginName == experimentInfo.LoginName || (userRole != null && userRole.RoleLevel > 1)) { deleteRotationPCRTest_button.Visibility = System.Windows.Visibility.Visible; } else { deleteRotationPCRTest_button.Visibility = System.Windows.Visibility.Hidden; } }
public void Get() { // Arrange UserInfoController controller = new UserInfoController(); // Act //IEnumerable<string> result = controller.Get(); List <Object> Object_List = controller.Get(); // Assert //Assert.IsNotNull(result); //Assert.AreEqual(2, result.Count()); //Assert.AreEqual("value1", result.ElementAt(0)); //Assert.AreEqual("value2", result.ElementAt(1)); }
private void initDataGrid() { getTotalPageNumber(); if (current_PageNumber > totalPageNumber) { current_PageNumber = 1; } currentPage_textBox.Text = current_PageNumber.ToString(); int startIndex = (current_PageNumber - 1) * PageSetting.RowNumberInEachPage + 1; List <ExperimentsInfo> experimentsList = controller.GetNextExperiments(experimentName_textBox.Text, experimentDate_datePicker.Text, userName_textBox.Text, startIndex, PageSetting.RowNumberInEachPage, sortColumn, sortDirection); UserInfoController userInfoController = new UserInfoController(); RoleInfo userRole = userInfoController.GetRoleByUserName(SessionInfo.LoginName); foreach (ExperimentsInfo experiment in experimentsList) { System.Data.DataRow dRow = dataTable.NewRow(); dRow["Number"] = startIndex; dRow["ExperimentID"] = experiment.ExperimentID; dRow["ExperimentName"] = experiment.ExperimentName; dRow["StartTime"] = experiment.StartTime; dRow["EndTime"] = experiment.EndTime.ToString(); dRow["LoginName"] = experiment.LoginName; dRow["Remark"] = experiment.Remark; dRow["State"] = controller.ConvertEnumStatusToText((ExperimentStatus)experiment.State); if (startIndex % 2 == 0) { dRow["Color"] = WindowCustomizer.alternativeColor; } else { dRow["Color"] = WindowCustomizer.defaultColor; } if (SessionInfo.LoginName == experiment.LoginName || userRole.RoleLevel > 1) { dRow["CanDelete"] = Visibility.Visible.ToString(); } else { dRow["CanDelete"] = Visibility.Hidden.ToString(); } dataTable.Rows.Add(dRow); startIndex++; } }
public void GetUserNameTest() { var userInfoService = new Mock <IUserInfoService>(); userInfoService.Setup(s => s.GetUserNameById(It.IsAny <string>())).Returns("张三---"); userInfoService.Setup(s => s.GetUserName()).Returns("张三"); var controller = new UserInfoController(userInfoService.Object); // var controller = new UserInfoController(new UserInfoService()); var result = controller.GetUserName(); Assert.IsNotNull(result); var result2 = controller.GetUserName("1123"); Assert.IsNotNull(result2); }
private UserInfoController CreateUserInfoController() { var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "abcd") })); var userInfoController = new UserInfoController( _mockUserInfoService.Object) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = user } } }; return(userInfoController); }
public async Task testRegisterExistingUser() { using (var context = new LanguageAPIContext(options)){ //Given UserInfo user = new UserInfo() { username = "******", password = "******" }; //When UserInfoController userInfoController = new UserInfoController(context); IActionResult result = await userInfoController.RegisterUser(user); //Then Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(ConflictResult)); var userList = await context.UserInfo.Where(l => l.username == user.username).ToListAsync(); Assert.AreEqual(1, userList.Count); } }
public override void Init(IModule module) { base.Init(module); var viewScript = InstantiateView <MainPanelView>("GameMain/Prefabs/MainPanel"); _mainControl = new MainPanelController(); _mainControl.view = viewScript; _userInfoController = new UserInfoController(); _userInfoController.View = viewScript.UserInfoView; RegisterController(_mainControl); RegisterController(_userInfoController); RegisterModel <ActivityPopupWindowModel>(); _mainControl.Start(); // if (GuideManager.GetRemoteGuideStep(GuideTypePB.MainGuide) < GuideConst.MainStep_MainStory1_6_Fail) // { // viewScript.ShowAll(false); // } }
public void GetNextLogs(string experimentName, int startRowIndex, int rowNumber, LogInfoLevelEnum logLevel, DataTable dataTable, System.Windows.Media.Color alternativeColor, System.Windows.Media.Color defaultColor) { try { string connectionString = WanTai.Common.Configuration.GetConnectionString(); ///todo: add control,each role user only can see the specific experiments string commandText = "SELECT * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY CreaterTime desc) AS [ROW_NUMBER], [t0].*, ExperimentsInfo.ExperimentName" + " FROM [dbo].[LogInfo] AS [t0] left join ExperimentsInfo on [t0].ExperimentID = ExperimentsInfo.ExperimentID " + " WHERE [t0].LogLevel= " + (int)logLevel + " {0}) AS [t1] WHERE [t1].[ROW_NUMBER] BETWEEN @startIndex AND @endIndex" + " ORDER BY [ROW_NUMBER]"; StringBuilder sbWhere = new StringBuilder(); if (!string.IsNullOrEmpty(experimentName)) { sbWhere.Append(" AND ExperimentsInfo.ExperimentName like '%" + experimentName + "%'"); } UserInfoController userInfoController = new UserInfoController(); RoleInfo userRole = userInfoController.GetRoleByUserName(SessionInfo.LoginName); if (userInfoController.GetAuthorize(AccessAuthority.LogInfo) == AccessAuthority.All) { sbWhere.Append(@" AND ([t0].LoginName IS NULL or [t0].LoginName in (SELECT LoginName FROM UserInfo u left join roleinfo r on r.RoleName=u.RoleName WHERE r.RoleLevel<=" + userRole.RoleLevel + " ))"); } else { sbWhere.Append(" AND [t0].LoginName='" + SessionInfo.LoginName + "'"); } commandText = String.Format(commandText, sbWhere.ToString()); using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); using (SqlCommand cmd = new SqlCommand(commandText, conn)) { cmd.Parameters.AddWithValue("@startIndex", startRowIndex); cmd.Parameters.AddWithValue("@endIndex", startRowIndex + rowNumber - 1); using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default)) { while (reader.Read()) { System.Data.DataRow dRow = dataTable.NewRow(); dRow["Number"] = startRowIndex; dRow["LogContent"] = reader["LogContent"]; dRow["Module"] = reader["Module"]; dRow["CreaterTime"] = reader["CreaterTime"].ToString(); dRow["LoginName"] = reader["LoginName"]; dRow["ExperimentName"] = reader["ExperimentName"]; if (startRowIndex % 2 == 0) { dRow["Color"] = alternativeColor; } else { dRow["Color"] = defaultColor; } dataTable.Rows.Add(dRow); startRowIndex++; } } } } } catch (Exception e) { string errorMessage = e.Message + System.Environment.NewLine + e.StackTrace; LogInfoController.AddLogInfo(LogInfoLevelEnum.Error, errorMessage, SessionInfo.LoginName, this.GetType().ToString() + "->GetNextLogs", SessionInfo.ExperimentID); throw; } }
public UserInfoControllerTest(TestFixture <Startup> testFixture) { _dbContext = testFixture.ServerService.GetService <UserInfoContext>(); _controller = new UserInfoController(_dbContext); _client = testFixture.Client; }