public ActionResult Register([Bind(Include = "Id,Email,Password,FirstName,LastName,Username,Gender,CityId,PhoneNumber,Birthdate,LastLogin,IsActive,IsBlocked,RoleId,IsComplete,IsDeleted,ModifiedDate,ModifiedUserId,DeletionDate,DeletionUserId,CreatedDate,CreatedUserId,RetypePassword")] UserViewModel userViewModel) { try { UpdateList(); if (ModelState.IsValid) { userViewModel.Id = Guid.NewGuid(); userViewModel.Role = listRole[0]; userViewModel.RoleId = listRole[0].Id; userViewModel.Password = UserViewModel.Encrypt(userViewModel.Password); AccountController.SendEmail("Welcome to Showvey!", "Hello " + userViewModel.Username + ", thank you for registration in Showvey. For completing the registration, please click link below: http://localhost:13177?id=" + userViewModel.Id, userViewModel.Email); userViewModel.AddUser(userViewModel); return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(listCity, "Id", "Name", userViewModel.CityId); ViewBag.RoleId = new SelectList(listRole, "Id", "Name", userViewModel.RoleId); return(View(userViewModel)); } catch { return(View()); } }
public IActionResult Checkout(UserViewModel u) { var user = _uservm.AddUser(); user.Name = _uservm.Name; var o = new OrderFactory(); var order = o.Create(); order.Pizzas = _uservm.CurrentOrder.Pizzas; order.Name = "Order"; //generic name order.DateOrdered = _uservm.CurrentOrder.DateOrdered; user.UserOrders.Add(order); _store = _storevm.AddStore(); _store.Name = _storevm.Store; _store.StoreOrders = user.UserOrders; _pr.CreateUser(user); _pr.CreateStore(_store); foreach (var p in order.Pizzas) { _pr.CreatePizza(p); } _uservm.CurrentOrder = null; _uservm.CurrentOrder = new OrderViewModel(); return(Redirect("/user/index")); }
public void LoginTest() { // given: mocks var lastAuthMock = new Mock <ILastAuth>(MockBehavior.Strict); bool isSubscriber = true; string username = "******"; string token = "TestToken"; lastAuthMock.Setup(l => l.UserSession).Returns(new LastUserSession() { IsSubscriber = isSubscriber, Token = token, Username = username }); lastAuthMock.Setup(l => l.LoadSession(It.IsAny <LastUserSession>())).Returns(true); lastAuthMock.Setup(l => l.Authenticated).Returns(true); var userApiMock = new Mock <IUserApi>(MockBehavior.Strict); userApiMock.Setup(u => u.GetRecentScrobbles(It.IsAny <string>(), It.IsAny <DateTimeOffset?>(), It.IsAny <DateTimeOffset?>(), It.IsAny <bool>(), 1, It.IsAny <int>())) .Returns(() => Task.Run(() => PageResponse <LastTrack> .CreateSuccessResponse())); userApiMock.Setup(u => u.GetRecentScrobbles(It.IsAny <string>(), It.IsAny <DateTimeOffset?>(), It.IsAny <DateTimeOffset?>(), It.IsAny <bool>(), 2, It.IsAny <int>())) .Returns(() => Task.Run(() => PageResponse <LastTrack> .CreateSuccessResponse())); userApiMock.Setup(u => u.GetRecentScrobbles(It.IsAny <string>(), It.IsAny <DateTimeOffset?>(), It.IsAny <DateTimeOffset?>(), It.IsAny <bool>(), 3, It.IsAny <int>())) .Returns(() => Task.Run(() => PageResponse <LastTrack> .CreateSuccessResponse())); var messageBoxServiceMock = new Mock <IMessageBoxService>(MockBehavior.Strict); messageBoxServiceMock.Setup(m => m.ShowDialog(It.IsAny <string>())).Returns(IMessageBoxServiceResult.OK); var windowManagerMock = new Mock <IExtendedWindowManager>(MockBehavior.Strict); windowManagerMock.Setup(w => w.ShowDialog(It.IsAny <LoginViewModel>(), It.IsAny <object>(), It.IsAny <IDictionary <string, object> >())).Returns(true); windowManagerMock.SetupGet(w => w.MessageBoxService).Returns(messageBoxServiceMock.Object); var fileOperatorMock = new Mock <IFileOperator>(MockBehavior.Strict); var directoryOperatorMock = new Mock <IDirectoryOperator>(MockBehavior.Strict); directoryOperatorMock.Setup(d => d.Exists(It.IsAny <string>())).Returns(true); directoryOperatorMock.Setup(d => d.GetFiles(It.IsAny <string>())).Returns(Array.Empty <string>()); var userSerializerMock = new Mock <ISerializer>(MockBehavior.Strict); userSerializerMock.Setup(u => u.Serialize(It.IsAny <User>(), It.IsAny <string>(), It.IsAny <IEnumerable <Type> >())); UserViewModel vm = new UserViewModel(windowManagerMock.Object, lastAuthMock.Object, userApiMock.Object, fileOperatorMock.Object, directoryOperatorMock.Object, userSerializerMock.Object); vm.AddUser(); vm.SelectedUser = vm.AvailableUsers.First(); // when: logging the user in vm.LoginUser(); // then: active user changed Assert.That(vm.ActiveUser, Is.SameAs(vm.SelectedUser)); }
private void AddUserViewController_AddUserHandler(object sender, Utils.CustomEventArgs.UserInfoEventArgs e) { userViewModel.AddUser(e.UserInfo); UserTableView.ReloadData(); if (addUserViewController != null) { addUserViewController.DismissViewController(true, null); } }
public void RemoveUserTest() { // given: mocks var lastAuthMock = new Mock <ILastAuth>(); lastAuthMock.Setup(l => l.Authenticated).Returns(true); bool isSubscriber = true; string username = "******"; string token = "TestToken"; lastAuthMock.Setup(l => l.UserSession).Returns(new LastUserSession() { IsSubscriber = isSubscriber, Token = token, Username = username }); var userApiMock = new Mock <IUserApi>(MockBehavior.Strict); var messageBoxServiceMock = new Mock <IMessageBoxService>(MockBehavior.Strict); var windowManagerMock = new Mock <IExtendedWindowManager>(MockBehavior.Strict); windowManagerMock.Setup(w => w.ShowDialog(It.IsAny <LoginViewModel>(), It.IsAny <object>(), It.IsAny <IDictionary <string, object> >())).Returns(true); windowManagerMock.SetupGet(w => w.MessageBoxService).Returns(messageBoxServiceMock.Object); var fileOperatorMock = new Mock <IFileOperator>(MockBehavior.Strict); fileOperatorMock.Setup(f => f.Delete(It.IsAny <string>())); var directoryOperatorMock = new Mock <IDirectoryOperator>(MockBehavior.Strict); directoryOperatorMock.Setup(d => d.Exists(It.IsAny <string>())).Returns(true); directoryOperatorMock.Setup(d => d.GetFiles(It.IsAny <string>())).Returns(new string[0]); var userSerializerMock = new Mock <ISerializer>(MockBehavior.Strict); userSerializerMock.Setup(u => u.Serialize(It.IsAny <User>(), It.IsAny <string>(), It.IsAny <IEnumerable <Type> >())); var vm = new UserViewModel(windowManagerMock.Object, lastAuthMock.Object, userApiMock.Object, fileOperatorMock.Object, directoryOperatorMock.Object, userSerializerMock.Object); vm.AddUser(); vm.SelectedUser = vm.AvailableUsers.First(); // when: removing the selected user vm.RemoveUser(); // then: ActiveUser is null and was removed Assert.That(vm.ActiveUser, Is.Null); CollectionAssert.IsEmpty(vm.AvailableUsers); Assert.That(() => fileOperatorMock.Verify(f => f.Delete(It.IsAny <string>()), Times.Once), Throws.Nothing); }
public void AddUserTest() { // given: mocks var lastAuthMock = new Mock <ILastAuth>(); lastAuthMock.Setup(l => l.Authenticated).Returns(true); bool isSubscriber = true; string username = "******"; string token = "TestToken"; lastAuthMock.Setup(l => l.UserSession).Returns(new LastUserSession() { IsSubscriber = isSubscriber, Token = token, Username = username }); var userApiMock = new Mock <IUserApi>(MockBehavior.Strict); var messageBoxServiceMock = new Mock <IMessageBoxService>(MockBehavior.Strict); var windowManagerMock = new Mock <IExtendedWindowManager>(MockBehavior.Strict); windowManagerMock.Setup(w => w.ShowDialog(It.IsAny <LoginViewModel>(), It.IsAny <object>(), It.IsAny <IDictionary <string, object> >())).Returns(true); windowManagerMock.SetupGet(w => w.MessageBoxService).Returns(messageBoxServiceMock.Object); var directoryOperatorMock = new Mock <IDirectoryOperator>(MockBehavior.Strict); directoryOperatorMock.Setup(d => d.Exists(It.IsAny <string>())).Returns(true); directoryOperatorMock.Setup(d => d.GetFiles(It.IsAny <string>())).Returns(new string[0]); var userSerializerMock = new Mock <ISerializer>(MockBehavior.Strict); userSerializerMock.Setup(u => u.Serialize(It.IsAny <User>(), It.IsAny <string>(), It.IsAny <IEnumerable <Type> >())); var vm = new UserViewModel(windowManagerMock.Object, lastAuthMock.Object, userApiMock.Object, null, directoryOperatorMock.Object, userSerializerMock.Object); // when: adding the user vm.AddUser(); // user added to list Assert.That(vm.AvailableUsers.Count, Is.EqualTo(1)); // then: user with the values added Assert.That(vm.AvailableUsers.First().IsSubscriber, Is.EqualTo(isSubscriber)); Assert.That(vm.AvailableUsers.First().Token, Is.SameAs(token)); Assert.That(vm.AvailableUsers.First().Username, Is.SameAs(username)); // then: added user is active Assert.That(vm.ActiveUser, Is.SameAs(vm.AvailableUsers.First())); Assert.That(vm.Username, Is.SameAs(vm.AvailableUsers.First().Username)); // serialize was called Assert.That(() => userSerializerMock.Verify(u => u.Serialize(vm.ActiveUser, It.IsAny <string>())), Throws.Nothing); }
public ActionResult Create([Bind(Include = "Id,Email,Password,RetypePassword,FirstName,LastName,Username,Gender,CityId,PhoneNumber,Birthdate,RoleId")] UserViewModel userViewModel) { if (ModelState.IsValid) { userViewModel.Id = Guid.NewGuid(); userViewModel.Password = UserViewModel.Encrypt(userViewModel.Password); userViewModel.AddUser(userViewModel); return(RedirectToAction("Index")); } UpdateList(); ViewBag.CityId = new SelectList(listCity, "Id", "Name", userViewModel.CityId); ViewBag.RoleId = new SelectList(listRole, "Id", "Name", userViewModel.RoleId); return(View(userViewModel)); }
public void LoginTest() { // given: mocks Mock <ILastAuth> lastAuthMock = new Mock <ILastAuth>(MockBehavior.Strict); bool isSubscriber = true; string username = "******"; string token = "TestToken"; lastAuthMock.Setup(l => l.UserSession).Returns(new LastUserSession() { IsSubscriber = isSubscriber, Token = token, Username = username }); lastAuthMock.Setup(l => l.LoadSession(It.IsAny <LastUserSession>())).Returns(true); lastAuthMock.Setup(l => l.Authenticated).Returns(true); Mock <IMessageBoxService> messageBoxServiceMock = new Mock <IMessageBoxService>(MockBehavior.Strict); messageBoxServiceMock.Setup(m => m.ShowDialog(It.IsAny <string>())).Returns(IMessageBoxServiceResult.OK); Mock <IExtendedWindowManager> windowManagerMock = new Mock <IExtendedWindowManager>(MockBehavior.Strict); windowManagerMock.Setup(w => w.ShowDialog(It.IsAny <LoginViewModel>(), It.IsAny <object>(), It.IsAny <IDictionary <string, object> >())).Returns(true); windowManagerMock.SetupGet(w => w.MessageBoxService).Returns(messageBoxServiceMock.Object); Mock <IFileOperator> fileOperatorMock = new Mock <IFileOperator>(MockBehavior.Strict); Mock <IDirectoryOperator> directoryOperatorMock = new Mock <IDirectoryOperator>(MockBehavior.Strict); directoryOperatorMock.Setup(d => d.Exists(It.IsAny <string>())).Returns(true); directoryOperatorMock.Setup(d => d.GetFiles(It.IsAny <string>())).Returns(new string[0]); Mock <ISerializer> userSerializerMock = new Mock <ISerializer>(MockBehavior.Strict); userSerializerMock.Setup(u => u.Serialize(It.IsAny <User>(), It.IsAny <string>(), It.IsAny <IEnumerable <Type> >())); UserViewModel vm = new UserViewModel(windowManagerMock.Object, lastAuthMock.Object, fileOperatorMock.Object, directoryOperatorMock.Object, userSerializerMock.Object); vm.AddUser(); vm.SelectedUser = vm.AvailableUsers.First(); // when: logging the user in vm.LoginUser(); // then: active user changed Assert.That(vm.ActiveUser, Is.SameAs(vm.SelectedUser)); }
private void AddUser() { UserInfo newUser = new UserInfo(); newUser.UserName = Txt_userName.Text; newUser.UserPwd = Txt_pwd.Text; newUser.UserRoleType = Convert.ToUInt32(userRoleCom.SelectedIndex + 1); newUser.RightMask = 777; newUser.other = Txt_userOther.Text; // 如果添加成功 新用户的句柄 会在 service层获得并写到 对象里 if (m_vm.AddUser(newUser)) { if (AddFinished != null) { AddFinished((object)newUser, null); } this.Close(); } else { errorLabel.Text = "添加失败" + ":" + newUser.other; } }
/// <summary> /// Handles the Click event of the btnFinish control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param> private void btnFinish_Click(object sender, System.Windows.RoutedEventArgs e) { if (ApplicationViewModel.Instance.DemoMode) { DemoMode dm = new DemoMode(); dm.Show(); return; } Storyboard2.Begin(); tbStep1.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0)); rectStep1.Fill = new SolidColorBrush(Color.FromArgb(255, 38, 198, 48)); tbStep2.Foreground = new SolidColorBrush(Color.FromArgb(255, 122, 122, 122)); rectStep2.Fill = new SolidColorBrush(Color.FromArgb(255, 122, 122, 122)); //userDto = userDtoCopy; //this.SelectedUserDto = new UserDTO(); if (this.SelectedUserDto == null) { this.SelectedUserDto = new UserDTO(); } this.SelectedUserDto.FirstName = tbFirstName.Text; this.SelectedUserDto.LastName = tbLastName.Text; if (ApplicationViewModel.Instance.AuthenticationMode.ToString().ToLower() == "windows") { this.SelectedUserDto.Email = tbEmailAddress.Text.ToString().ToLower(); this.SelectedUserDto.UserName = tbUserID.Text.ToString().ToLower(); } else { this.SelectedUserDto.Email = autoEmail.Text.ToString().ToLower(); this.SelectedUserDto.UserName = autoEmail.Text.ToLower(); } this.SelectedUserDto.Phone = tbPhone.Text; //this.SelectedUserDto.RoleValue = Convert.ToInt32(Enum.Parse(typeof(RolesEnum), ((ComboBoxItem)cmbRole.SelectedValue).Content.ToString(), false)); this.SelectedUserDto.UserRoleInOrganization = ((ComboBoxItem)cmbRole.SelectedItem).Content.ToString(); // cmbRole.SelectedValue.ToString(); //this.SelectedUserDto.OrganizationID = User.Instance.UserDto.OrganizationID; this.SelectedUserDto.DatasourceList = ReadDatasourceList(this.SelectedUserDto.UserRoleInOrganization); UserOrganizationDto dto = new UserOrganizationDto(); dto.Organization = new OrganizationDto(); dto.Organization.Active = this.SelectedOrg.Active; dto.Organization.AdminCount = this.SelectedOrg.AdminCount; dto.Organization.AnalystCount = this.SelectedOrg.AnalystCount; dto.Organization.DatasourceCount = this.SelectedOrg.DatasourceCount; dto.Organization.DatasourcesCount = this.SelectedOrg.DatasourcesCount; dto.Organization.Description = ""; dto.Organization.Id = this.SelectedOrg.Id; dto.Organization.Name = this.SelectedOrg.Name; dto.Organization.SuperAdminCount = this.SelectedOrg.SuperAdminCount; dto.Organization.TotalUserCount = this.SelectedOrg.TotalUserCount; dto.RoleId = Convert.ToInt32(Enum.Parse(typeof(RolesEnum), ((ComboBoxItem)cmbRole.SelectedValue).Content.ToString(), false)); dto.Active = (cmbActive.SelectionBoxItem.ToString() == "Yes") ? true : false; switch (Mode) { case ModeType.Add: dto.User = this.SelectedUserDto; uvm.AddUser(dto); uvm.UserAdded += new EventHandler(uvm_UserAdded); uvm.UserAddedFailed += new EventHandler(uvm_UserAddedFailed); break; case ModeType.Edit: this.SelectedUserDto.UserID = this.SelectedUserDto.UserID; this.SelectedUserDto.PasswordHash = this.SelectedUserDto.PasswordHash; this.SelectedUserDto.UserEditType = UserEditType.EditingUserInfo; dto.User = this.SelectedUserDto; uvm.UpdateUser(dto); uvm.UserUpdated += new EventHandler(uvm_UserUpdated); break; default: break; } btnFinish.IsEnabled = false; this.DialogResult = true; }