private List <AccountDetail> GetData() { using (AccountsController controller = new AccountsController()) { return(controller.GetAccountDetailAll()); } }
public void TestTransactionPost_NullID() { #region ASSIGN TestRepository tRepo = new TestRepository(); AccountsController tController = null; CustomerAccountTransactionsVM tVM = tRepo.GetAllTransactions(0, 0); tController = new AccountsController(tRepo) { ControllerContext = UtilityFunctions.GenerateMockControllerContext("UserA"), }; #endregion #region ACT var tResult = tController.Transactions(null, tVM); #endregion #region ASSERT Assert.IsTrue(tResult is RedirectToActionResult); Assert.AreEqual((tResult as RedirectToActionResult).ActionName, "Index"); #endregion }
public void TestCreateGet() { #region ASSIGN TestRepository tRepo = new TestRepository(); AccountsController tController = null; tController = new AccountsController(tRepo) { ControllerContext = UtilityFunctions.GenerateMockControllerContext("UserA"), }; #endregion #region ACT var tResult = tController.Create(); #endregion #region ASSERT Assert.IsTrue(tResult is ViewResult); Assert.AreEqual(((tResult as ViewResult).ViewData["AccountTypeID"] as SelectList).Where(t => t.Value == "0").FirstOrDefault().Text, "Checking"); #endregion }
public void TestCreatePost_ValidData() { #region ASSIGN TestRepository tRepo = new TestRepository(); AccountsController tController = null; Account tAccount = new Account() { AccountBalance = 100.0, }; tController = new AccountsController(tRepo) { ControllerContext = UtilityFunctions.GenerateMockControllerContext("UserA"), }; #endregion #region ACT var tResult = tController.Create(tAccount); #endregion #region ASSERT Assert.IsTrue(tResult is RedirectToActionResult); Assert.AreEqual((tResult as RedirectToActionResult).ActionName, "Details"); Assert.AreEqual((tResult as RedirectToActionResult).RouteValues["id"], 4); #endregion }
private void RegisterAccountClick(object sender, RoutedEventArgs e) { var cert = new X509Certificate2(); cert.Import(PathTextBox2.Text); if (!ValidateController.ValidateCertificates(cert)) { MessageBox.Show("Certificate is revoked or signed with different CA!"); return; } var account = AccountsController.GetInstance().AddAccount(new Account(Program.ReadName(cert), PasswordBox2.Password, PathTextBox2.Text)); if (account) { AccountsController.GetInstance().SerializeNow(); MessageBox.Show("You successfully have made an account. Now you can login!"); Task.Delay(2000); Hide(); _previousWindow.Show(); } else { MessageBox.Show("Please type all data in text boxes!"); } ; }
public void Inactivate_Test() { #region === ARRANGE === Mock <IApplicationServicesFactory> mockApplicationServicesFactory = new Mock <IApplicationServicesFactory>(); Mock <IUserCommandsService> mockUserCommandsService = new Mock <IUserCommandsService>(); Mock <ILogger <AccountsController> > mockLoger = new Mock <ILogger <AccountsController> >(); AccountsController usersController = new AccountsController(mockLoger.Object, mockApplicationServicesFactory.Object); mockApplicationServicesFactory.Setup(x => x.CreateUserCommandsService()).Returns(mockUserCommandsService.Object); #endregion #region === ACT === usersController.Inactivate(55); #endregion #region === ASSERT === mockUserCommandsService.Verify(mock => mock.Inactivate(It.IsAny <InactivateUser>()), Times.Once()); #endregion }
public void UpdateAccount_WithValidModel_Returns_OkResult() { // Arrange var accountServiceMock = new Mock <IAccountService>(); accountServiceMock.Setup(service => service .GetAccountByEmailAsync(It.IsAny <string>())) .Returns(Task.FromResult(GetAccount())); accountServiceMock.Setup(service => service .UpdateAccountAsync(It.IsAny <AccountDTO>())) .Returns(Task.FromResult(true)); var loggerMock = new Mock <ILogger>(); loggerMock.Setup(c => c.Information(It.IsAny <string>())); var controller = new AccountsController(accountServiceMock.Object, loggerMock.Object); var accountDTO = GetAccount(); // Act var result = controller.UpdateAccount(accountDTO).GetAwaiter().GetResult(); // Assert var okResult = Assert.IsType <OkObjectResult>(result); Assert.IsAssignableFrom <AccountDTO>(okResult.Value); }
public async Task 効な認証コードを用いてパスワード設定画面を表示() { // Arrange var accountsUseCase = new Mock <IAccountsUseCase>(); var authorizationUseCase = new Mock <IAuthorizationUseCase>(); accountsUseCase .Setup(o => o.GetAuthorizationLinkByCode("abcdef123456")) .ReturnsAsync(new AuthorizationLink("C12345", DateTime.Now)) .Verifiable(); var userManager = MockMaker.MakeMoqUserManager(); var signInManager = MockMaker.MakeMockSignInManager(); var controller = new AccountsController( accountsUseCase: accountsUseCase.Object, authorizationUseCase: authorizationUseCase.Object, userManager: userManager.Object, signInManager: signInManager.Object, loggerFactory: new Mock <ILoggerFactory>().Object, optionsAccessor: new Mock <IOptions <UrlSettings> >().Object); // Act var result = await controller.SetupPassword("abcdef123456", null); // Assert accountsUseCase.Verify(); accountsUseCase.VerifyNoOtherCalls(); Assert.IsType <ViewResult>(result); }
public void Login_WithValidModel_Returns_AcceptedResult() { // Arrange var accountServiceMock = new Mock <IAccountService>(); accountServiceMock.Setup(service => service .LoginAsync(It.IsAny <LoginDTO>())) .Returns(Task.FromResult(GetToken())); var loggerMock = new Mock <ILogger>(); loggerMock.Setup(c => c.Information(It.IsAny <string>())); var controller = new AccountsController(accountServiceMock.Object, loggerMock.Object); var loginDTO = GetLoginData(); controller.ControllerContext = GetFakeContext(); // Act var result = controller.Login(loginDTO).GetAwaiter().GetResult(); // Assert var acceptedResult = Assert.IsType <AcceptedResult>(result); Assert.IsAssignableFrom <TokenDTO>(acceptedResult.Value); }
public void UpdateAccount_WithUpdateError_Returns_ConflictResult() { // Arrange var accountServiceMock = new Mock <IAccountService>(); accountServiceMock.Setup(service => service .GetAccountByEmailAsync(It.IsAny <string>())) .Returns(Task.FromResult(GetAccount())); accountServiceMock.Setup(service => service .UpdateAccountAsync(It.IsAny <AccountDTO>())) .Returns(Task.FromResult(false)); var loggerMock = new Mock <ILogger>(); loggerMock.Setup(c => c.Warning(It.IsAny <string>())); var controller = new AccountsController(accountServiceMock.Object, loggerMock.Object); var accountDTO = GetAccount(); // Act var result = controller.UpdateAccount(accountDTO).GetAwaiter().GetResult(); // Assert var conflictResult = Assert.IsType <ConflictResult>(result); }
public void RegisterShouldCallRegisterUserAndRedirectToHomePage(Database db, [Content] DbItem item, Item profileItem, RegistrationInfo registrationInfo, [Frozen] IAccountRepository repo, [Frozen] INotificationService notifyService, [Frozen] IAccountsSettingsService accountsSettingsService, [Frozen] IUserProfileService userProfileService) { accountsSettingsService.GetPageLinkOrDefault(Arg.Any <Item>(), Arg.Any <ID>(), Arg.Any <Item>()).Returns("/redirect"); repo.Exists(Arg.Any <string>()).Returns(false); userProfileService.GetUserDefaultProfileId().Returns(profileItem.ID.ToString()); var controller = new AccountsController(repo, notifyService, accountsSettingsService, userProfileService, null); var fakeSite = new FakeSiteContext(new StringDictionary { { "rootPath", "/sitecore/content" }, { "startItem", item.Name } }) as SiteContext; fakeSite.Database = db; Language.Current = Language.Invariant; using (new SiteContextSwitcher(fakeSite)) { var result = controller.Register(registrationInfo); result.Should().BeOfType <RedirectResult>().Which.Url.Should().Be("/redirect"); repo.Received(1).RegisterUser(registrationInfo.Email, registrationInfo.Password, Arg.Any <string>()); } }
public void RegisterShouldReturnErrorIfRegistrationThrowsMembershipException(Database db, [Content] DbItem item, Item profileItem, RegistrationInfo registrationInfo, MembershipCreateUserException exception, [Frozen] IAccountRepository repo, [Frozen] INotificationService notifyService, [Frozen] IAccountsSettingsService accountsSettingsService, [Frozen] IUserProfileService userProfileService) { repo.When(x => x.RegisterUser(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>())).Do(x => { throw new MembershipCreateUserException(); }); userProfileService.GetUserDefaultProfileId().Returns(profileItem.ID.ToString()); var controller = new AccountsController(repo, notifyService, accountsSettingsService, userProfileService, null); var fakeSite = new FakeSiteContext(new StringDictionary { { "rootPath", "/sitecore/content" }, { "startItem", item.Name } }) as SiteContext; fakeSite.Database = db; Language.Current = Language.Invariant; using (new SiteContextSwitcher(fakeSite)) { var result = controller.Register(registrationInfo); result.Should().BeOfType <ViewResult>().Which.Model.Should().Be(registrationInfo); result.Should().BeOfType <ViewResult>().Which.ViewData.ModelState.Should().ContainKey(nameof(registrationInfo.Email)) .WhichValue.Errors.Should().Contain(x => x.ErrorMessage == exception.Message); } }
public void LoginShouldAddModelStateErrorIfNotLoggedIn(Database db, [Content] DbItem item, [Frozen] IAccountRepository repo, LoginInfo info, INotificationService service, [Frozen] IAccountsSettingsService accountSetting) { accountSetting.GetPageLinkOrDefault(Arg.Any <Item>(), Arg.Any <ID>(), Arg.Any <Item>()).Returns("/"); var fakeSite = new FakeSiteContext(new StringDictionary { { "rootPath", "/sitecore/content" }, { "startItem", item.Name } }) as SiteContext; fakeSite.Database = db; Language.Current = Language.Invariant; using (new SiteContextSwitcher(fakeSite)) { info.ReturnUrl = null; info.Email = null; info.Password = null; var controller = new AccountsController(repo, service, accountSetting, null, null); repo.Login(string.Empty, string.Empty).ReturnsForAnyArgs(x => true); var result = controller.Login(info); result.Should().BeOfType <RedirectResult>().Which.Url.Should().Be("/"); } }
private void Save_Click(object sender, RoutedEventArgs e) { AccountsController.UpsertAccount(selectedAccount); var messageQueue = SnackBar2.MessageQueue; Task.Factory.StartNew(() => messageQueue.Enqueue("Saved")); }
public void DeleteAccount_Returns_OkResult() { // Arrange var accountServiceMock = new Mock <IAccountService>(); accountServiceMock.Setup(service => service .GetAccountByIdAsync(It.IsAny <Guid>())) .Returns(Task.FromResult(GetAccount())); accountServiceMock.Setup(service => service .DeleteAccountByIdAsync(It.IsAny <Guid>())) .Returns(Task.FromResult(true)); var loggerMock = new Mock <ILogger>(); var controller = new AccountsController(accountServiceMock.Object, loggerMock.Object); var id = new Guid(); // Act var result = controller.DeleteAccount(id).GetAwaiter().GetResult(); // Assert var okObjectResult = Assert.IsType <OkObjectResult>(result); Assert.IsAssignableFrom <Guid>(okObjectResult.Value); }
public async Task 認証コードとメール確認トークンをアクションパラメーターに持つ() { // Arrange var accountsUseCase = new Mock <IAccountsUseCase>(); var authorizationUseCase = new Mock <IAuthorizationUseCase>(); accountsUseCase .Setup(o => o.GetAuthorizationLinkByCode("abcdef123456")) .ReturnsAsync(new AuthorizationLink("C12345", DateTime.Now)) .Verifiable(); var userManager = MockMaker.MakeMoqUserManager(); var signInManager = MockMaker.MakeMockSignInManager(); var controller = new AccountsController( accountsUseCase: accountsUseCase.Object, authorizationUseCase: authorizationUseCase.Object, userManager: userManager.Object, signInManager: signInManager.Object, loggerFactory: new Mock <ILoggerFactory>().Object, optionsAccessor: new Mock <IOptions <UrlSettings> >().Object); // Act var result = await controller.SetupPassword("abcdef123456", "abcdefghijklmn"); // Assert accountsUseCase.Verify(); accountsUseCase.VerifyNoOtherCalls(); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <SetupPasswordViewModel>(viewResult.ViewData.Model); Assert.Equal("abcdef123456", model.ActionParameters["authorizationCode"]); Assert.Equal("abcdefghijklmn", model.ActionParameters["token"]); }
public void TestClosePost_Valid() { #region ASSIGN TestRepository tRepo = new TestRepository(); AccountsController tController = null; Account tData = tRepo.GetAccountInformation(0, 0); tData.AccountBalance = 0.0; tController = new AccountsController(tRepo) { ControllerContext = UtilityFunctions.GenerateMockControllerContext("UserA"), }; #endregion #region ACT var tResult = tController.Close(0, tData); #endregion #region ASSERT Assert.IsTrue(tResult is RedirectToActionResult); Assert.AreEqual((tResult as RedirectToActionResult).ActionName, "Index"); Assert.AreEqual((tResult as RedirectToActionResult).ControllerName, "Customers"); #endregion }
public MenuWindow(Window previousWindow) { _previousWindow = previousWindow; InitializeComponent(); ImeLabel.Content = ImeLabel.Content + Environment.NewLine + AccountsController.GetInstance().CurrentAccount.Username; }
public void TestCloseGet_UnauthorizedAccountOwner() { #region ASSIGN TestRepository tRepo = new TestRepository(); AccountsController tController = null; tController = new AccountsController(tRepo) { ControllerContext = UtilityFunctions.GenerateMockControllerContext("User"), }; #endregion #region ACT var tResult = tController.Close(0); #endregion #region ASSERT Assert.IsTrue(tResult is RedirectToActionResult); Assert.AreEqual((tResult as RedirectToActionResult).ActionName, "Index"); #endregion }
public void Get_All_test() { #region === ARRANGE === Mock <IApplicationServicesFactory> mockApplicationServicesFactory = new Mock <IApplicationServicesFactory>(); Mock <IUserQueriesService> mockUserQueriesService = new Mock <IUserQueriesService>(); Mock <ILogger <AccountsController> > mockLoger = new Mock <ILogger <AccountsController> >(); AccountsController usersController = new AccountsController(mockLoger.Object, mockApplicationServicesFactory.Object); List <UserAppModel> userAppModels = new List <UserAppModel>(); userAppModels.Add(new UserAppModel() { id = 55, active = true, username = "******" }); mockApplicationServicesFactory.Setup(x => x.CreateUserQueriesService()).Returns(mockUserQueriesService.Object); mockUserQueriesService.Setup(x => x.GetAllUsers()).Returns(userAppModels); #endregion #region === ACT === var result = usersController.Get(); #endregion #region === ASSERT === Assert.AreEqual <int>(userAppModels.Count, result.Count()); #endregion }
public async Task RegisterAndLoginAccount_UpgradeToSellerAccount() { //Arrange AccountsController accountsController = new AccountsController(context, hostEnvironment); AccountViewModel accountViewModel = AccountRegistration(); LoginViewModel loginViewModel = AccountLogin(accountViewModel); SellerAccount sellerAccount = new SellerAccount(); SellerAccountsController sellerAccountsController = new SellerAccountsController(context, hostEnvironment); //Act accountsController.Create(accountViewModel); accountsController.Login(loginViewModel); try { //Assert if (accountsController.ModelState.IsValid) { await sellerAccountsController.Create(sellerAccount); Assert.True(accountsController.ModelState.IsValid && sellerAccountsController.ModelState.IsValid); } else { throw new Exception(); } } catch (Exception) { } }
public void Get_ByUserName_Test() { #region === ARRANGE === Mock <IApplicationServicesFactory> mockApplicationServicesFactory = new Mock <IApplicationServicesFactory>(); Mock <IUserQueriesService> mockUserQueriesService = new Mock <IUserQueriesService>(); Mock <ILogger <AccountsController> > mockLoger = new Mock <ILogger <AccountsController> >(); AccountsController usersController = new AccountsController(mockLoger.Object, mockApplicationServicesFactory.Object); List <UserAppModel> userAppModels = new List <UserAppModel>(); userAppModels.Add(new UserAppModel() { id = 55, active = true, username = "******" }); mockApplicationServicesFactory.Setup(x => x.CreateUserQueriesService()).Returns(mockUserQueriesService.Object); mockUserQueriesService.Setup(x => x.GetUsers(It.IsAny <UserQuery>())).Returns(userAppModels); #endregion #region === ACT === var result = usersController.Get("User"); #endregion #region === ASSERT === Assert.AreEqual <int>(userAppModels[0].id, result.id); Assert.AreEqual <bool>(userAppModels[0].active, result.active); Assert.AreEqual <string>(userAppModels[0].username, result.username); #endregion }
public async Task RegisterAndLoginAccount_DeleteTheAccount() { //Arrange AccountsController accountsController = new AccountsController(context, hostEnvironment); AccountViewModel accountViewModel = AccountRegistration(); LoginViewModel loginViewModel = AccountLogin(accountViewModel); var account = await context.Accounts .FirstOrDefaultAsync(m => m.AccountId == 1); //Act try { //Assert if (accountsController.ModelState.IsValid) { await accountsController.Delete(account.AccountId); Assert.True(accountsController.ModelState.IsValid); } else { throw new Exception(); } } catch (Exception) { } }
public void TestCreatePost_InvalidData() { #region ASSIGN TestRepository tRepo = new TestRepository(); AccountsController tController = null; Account tAccount = new Account() { AccountBalance = -100.0, }; tController = new AccountsController(tRepo) { ControllerContext = UtilityFunctions.GenerateMockControllerContext("UserA"), }; #endregion #region ACT var tResult = tController.Create(tAccount); #endregion #region ASSERT Assert.IsTrue(tResult is ViewResult); Assert.AreEqual(((tResult as ViewResult).Model as Account).AccountBalance, 0); #endregion }
public void RegisterAndLoginAccount_SendASupportTicket() { //Arrange AccountsController accountsController = new AccountsController(context, hostEnvironment); AccountViewModel accountViewModel = AccountRegistration(); LoginViewModel loginViewModel = AccountLogin(accountViewModel); Support support = SupportMessage(); HomeController homeController = new HomeController(logger, context); //Act accountsController.Create(accountViewModel); accountsController.Login(loginViewModel); try { //Assert if (accountsController.ModelState.IsValid) { homeController.SendSupport(support); Assert.True(accountsController.ModelState.IsValid); Assert.True(homeController.ModelState.IsValid); } else { throw new Exception(); } } catch (Exception) { } }
private void Save_Button_Click(object sender, EventArgs e) { List <AccountDetail> saveData = this.AccountDetailData.Where(o => o.Status == ModifyMode.Insert).ToList(); if (saveData?.Count > 0) { if (MessageBoxHelper.ShowConfirmMessage(BSMessage.BSM000038) != System.Windows.Forms.DialogResult.Yes) { return; } using (AccountsController controller = new AccountsController()) { if (controller.SaveAccountDetail(saveData)) { this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } else { MessageBoxHelper.ShowErrorMessage(BSMessage.BSM000002); } } } else { MessageBoxHelper.ShowErrorMessage(BSMessage.BSM000040); } }
public AccountsControllerTests() { _userService = Substitute.For <IUserService>(); _userRepository = Substitute.For <IUserRepository>(); _cipherRepository = Substitute.For <ICipherRepository>(); _folderRepository = Substitute.For <IFolderRepository>(); _organizationService = Substitute.For <IOrganizationService>(); _organizationUserRepository = Substitute.For <IOrganizationUserRepository>(); _providerUserRepository = Substitute.For <IProviderUserRepository>(); _paymentService = Substitute.For <IPaymentService>(); _globalSettings = new GlobalSettings(); _sendRepository = Substitute.For <ISendRepository>(); _sendService = Substitute.For <ISendService>(); _sut = new AccountsController( _globalSettings, _cipherRepository, _folderRepository, _organizationService, _organizationUserRepository, _providerUserRepository, _paymentService, _userRepository, _userService, _sendRepository, _sendService ); }
public void TestTransactionsGet_Valid() { #region ASSIGN TestRepository tRepo = new TestRepository(); AccountsController tController = null; tController = new AccountsController(tRepo) { ControllerContext = UtilityFunctions.GenerateMockControllerContext("UserA"), }; #endregion #region ACT var tResult = tController.Transactions(0); #endregion #region ASSERT Assert.IsTrue(tResult is ViewResult); Assert.AreEqual(((tResult as ViewResult).Model as CustomerAccountTransactionsVM).Customer.ID, 0); Assert.AreEqual(((tResult as ViewResult).Model as CustomerAccountTransactionsVM).Account.ID, 0); Assert.IsTrue(((tResult as ViewResult).Model as CustomerAccountTransactionsVM).AccountTransactions.Count > 0); #endregion }
public void EditProfilePost_ValidData_ShouldUpdateProfile(FakeSiteContext siteContext, string profileItemId, [Substitute] EditProfile editProfile, [Frozen] IUserProfileService userProfileService) { var user = Substitute.For <User>("extranet/John", true); user.Profile.Returns(Substitute.For <UserProfile>()); user.Profile.ProfileItemId = profileItemId; userProfileService.GetUserDefaultProfileId().Returns(profileItemId); userProfileService.ValidateProfile(Arg.Any <EditProfile>(), Arg.Any <ModelStateDictionary>()).Returns(true); using (new SiteContextSwitcher(siteContext)) using (new UserSwitcher(user)) { var accountsController = new AccountsController(null, null, null, null, userProfileService, null); accountsController.ControllerContext = Substitute.For <ControllerContext>(); accountsController.ControllerContext.HttpContext.Returns(Substitute.For <HttpContextBase>()); accountsController.ControllerContext.HttpContext.Session.Returns(Substitute.For <HttpSessionStateBase>()); accountsController.ControllerContext.HttpContext.Request.Returns(Substitute.For <HttpRequestBase>()); accountsController.ControllerContext.HttpContext.Request.RawUrl.Returns("/"); var result = accountsController.EditProfile(editProfile); userProfileService.Received(1).SetProfile(user.Profile, editProfile); accountsController.Session["EditProfileMessage"].Should().BeOfType <InfoMessage>().Which.Type.Should().Be(InfoMessage.MessageType.Info); result.Should().BeOfType <RedirectResult>(); } }
public async Task Create_ReturnsUserAccount_WhenAccountIsCreatedSuccessfully() { var testAccountModel = new UserAccountModel { PhoneNumber = PhoneNumber }; var testUserAccount = CreateTestAccount(); var accountServiceMock = new Mock <IAccountService>(); accountServiceMock.Setup(x => x.New(testAccountModel)) .Returns(Task.FromResult(testUserAccount)) .Verifiable(); var accountController = new AccountsController(accountServiceMock.Object); var result = await accountController.Create(testAccountModel); var createdObjectResult = result as CreatedResult; accountServiceMock.Verify(x => x.New(testAccountModel), Times.Exactly(1)); //TODO: Check for returned Uri Assert.IsNotNull(createdObjectResult); Assert.AreEqual(createdObjectResult.StatusCode, (int)HttpStatusCode.Created); Assert.AreEqual(createdObjectResult.Value, testUserAccount); }
public AccountsControllerTests() { validator = Substitute.For<IAccountValidator>(); service = Substitute.For<IAccountService>(); accountCreate = ObjectFactory.CreateAccountCreateView(); accountEdit = ObjectFactory.CreateAccountEditView(); account = ObjectFactory.CreateAccountView(); controller = Substitute.ForPartsOf<AccountsController>(validator, service); controller.ControllerContext.RouteData = new RouteData(); }