public void UserAdd_Post_ReturnsViewIfUserAddFails() { // Arrange AccountController controller = GetAccountController(); UserAddModel model = new UserAddModel { Email = "*****@*****.**", UserName = "******", FirstName = "goodFName", LastName = "goodLName", Organization = "MPR", AccountType = null, AccountTypeOptions = null, RadioSelectedState = 1, RoleSelections = new List <RoleSelection>(), RadioStateSelections = new List <StateSelection>(), CheckboxStateSelections = new List <StateSelection>() }; // Act ActionResult result = controller.Add(model); // Assert Assert.IsInstanceOf(typeof(ViewResult), result); ViewResult viewResult = (ViewResult)result; Assert.AreEqual(model, viewResult.ViewData.Model); Assert.AreEqual( "Username already exists. Please enter a different user name.", controller.ModelState[string.Empty].Errors[0].ErrorMessage); }
public void UserAdd_Post_ReturnsRedirectOnSuccess() { // Arrange AccountController controller = GetAccountController(); UserAddModel model = new UserAddModel { Email = "goodEmail", UserName = "******", FirstName = "goodFName", LastName = "goodLName", Organization = "MPR", AccountType = null, AccountTypeOptions = null, RadioSelectedState = 1, RoleSelections = new List <RoleSelection>(), RadioStateSelections = new List <StateSelection>(), CheckboxStateSelections = new List <StateSelection>() }; // Act ActionResult result = controller.Add(model); // Assert Assert.IsInstanceOf(typeof(RedirectToRouteResult), result); RedirectToRouteResult redirectResult = (RedirectToRouteResult)result; Assert.AreEqual("Account", redirectResult.RouteValues["controller"]); Assert.AreEqual("Users", redirectResult.RouteValues["action"]); }
public void UserAdd_Post_ReturnsViewIfModelStateIsInvalid() { // Arrange AccountController controller = GetAccountController(); UserAddModel model = new UserAddModel { Email = "goodEmail", UserName = "******", FirstName = "goodFName", LastName = "goodLName", Organization = "MPR", AccountType = null, AccountTypeOptions = null, RadioSelectedState = 1, RoleSelections = new List <RoleSelection>(), RadioStateSelections = new List <StateSelection>(), CheckboxStateSelections = new List <StateSelection>() }; controller.ModelState.AddModelError(string.Empty, "Dummy error message."); // Act ActionResult result = controller.Add(model); // Assert Assert.IsInstanceOf(typeof(ViewResult), result); ViewResult viewResult = (ViewResult)result; Assert.AreEqual(model, viewResult.ViewData.Model); }
Account CreateAndAddTestAccount() { var acc = CreateTestAccount(); accController.Add(acc); return(acc); }
public void Add_HttpGet_ReturnsPartialView() { var target = new AccountController(null); var result = target.Add(); var model = ((PartialViewResult)result).ViewData.Model as AccountAddModel; Assert.IsInstanceOfType(result, typeof(PartialViewResult)); Assert.IsNotNull(model); }
public void UserAdd_Get_ReturnsView() { // Arrange AccountController controller = GetAccountController(); // Act ActionResult result = controller.Add(); // Assert Assert.IsInstanceOf(typeof(ViewResult), result); }
public void AddReturnsPartialView() { AccountController target = new AccountController(null); var result = target.Add(new WebUser()); var model = ((PartialViewResult)result).ViewData.Model as Account; Assert.IsInstanceOfType(result, typeof(PartialViewResult)); Assert.IsNotNull(model); Assert.AreEqual(model.AccountID, 0); Assert.IsNotNull(model); }
public void Should_create_update_delete_account() { // Add var model = new AddUserModel { UserName = $"TestUser{DateTime.Now:yyyyMMddHHmmss}", DisplayName = "Test Testsson", Comment = "Kommentar", Password = "******" }; var addResult = _sut.Add(model) as CreatedNegotiatedContentResult <string>; Assert.AreEqual("User created", addResult?.Content); Assert.AreEqual($"http://localhost/api/external/account/get?username={model.UserName}", addResult?.Location.OriginalString); // Get var getResult = _sut.Get(model.UserName) as OkNegotiatedContentResult <UserModel>; var user2 = getResult?.Content; Assert.AreEqual(model.DisplayName, user2.DisplayName); Assert.AreEqual(model.Comment, user2.Comment); // Update model.DisplayName = "Update Updatesson"; model.Comment = "New comment"; var updateResult = _sut.Update(model) as OkNegotiatedContentResult <string>; Assert.AreEqual("User updated", updateResult?.Content); var changePasswordModel = new ChangePasswordModel() { UserName = model.UserName, NewPassword = "******" }; var changePwdResult = _sut.UpdatePassword(changePasswordModel) as OkNegotiatedContentResult <string>; Assert.AreEqual("Password updated", changePwdResult?.Content); // Get var getResult2 = _sut.Get(model.UserName) as OkNegotiatedContentResult <UserModel>; var user3 = getResult2?.Content; Assert.AreEqual(model.DisplayName, user3.DisplayName); Assert.AreEqual(model.Comment, user3.Comment); // Delete var deleteResult = _sut.Delete(model.UserName) as OkNegotiatedContentResult <string>; Assert.AreEqual("User deleted", deleteResult?.Content); }
public async Task AddModelStateValidReturnsRedirectToIndex() { var accountViewModel = new AccountAddModel() { AccountName = "Acc1" }; var target = new AccountController(_mockAccountService.Object); var result = await target.Add(new WebUser() { Id = "1" }, accountViewModel); Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); }
public void Add_User_Success() { _membershipServiceSub .CreateUser(Arg.Any<MembershipUser>()) .Returns(x => MembershipCreateStatus.Success); var viewModel = new MemberAddViewModel { Comment = "Test" }; var controller = new AccountController(_membershipServiceSub); controller.Add(viewModel); Assert.IsTrue(controller.ModelState.IsValid); }
public async Task AddModelStateValidReturnsRedirectToIndex() { Account account = new Account() { AccountID = 1, AccountName = "Acc1" }; AccountController target = new AccountController(_mockAccountService.Object); var result = await target.Add(new WebUser() { Id = "1" }, account); _mockAccountService.Verify(m => m.CreateAsync(account), Times.Once); Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); }
public void Add_User_Fail() { _membershipServiceSub .CreateUser(Arg.Any <MembershipUser>()) .Returns(x => MembershipCreateStatus.ProviderError); var viewModel = new MemberAddViewModel { Comment = "Test" }; var controller = new AccountController(_membershipServiceSub); controller.Add(viewModel); Assert.IsFalse(controller.ModelState.IsValid); }
public async Task Cannot_Add_Invalid_Account() { var accountViewModel = new AccountAddModel() { AccountName = "Acc1" }; var target = new AccountController(null); target.ModelState.AddModelError("error", "error"); var result = await target.Add(new WebUser() { Id = "1" }, accountViewModel); Assert.IsInstanceOfType(result, typeof(PartialViewResult)); }
public async Task Add() { var accountCoreMoq = new Mock <IAccountCore>(); var controller = new AccountController(accountCoreMoq.Object); var accountToCreateDto = new AccountToCreateDto() { CustomerId = Guid.NewGuid(), InitialCredit = 300.00m, Name = "Savings01" }; accountCoreMoq.Setup(x => x.Add(accountToCreateDto)).Returns(async() => await Task.CompletedTask ); var result = await controller.Add(accountToCreateDto); Assert.NotNull(result); Assert.That((result is OkResult)); }
public async Task Add_InputAccount_RaiseWebUiException() { _mockAccountService.Setup(x => x.CreateAsync(It.IsAny <Account>())).Throws <ServiceException>(); await _target.Add(new WebUser(), new AccountAddModel()); }
public int AddAccount(Account Account) { return(contr.Add(Account)); }