public void TestOrderApprovedAccountManagerEmailPrefs1() { #region Arrange UserIdentity.Expect(a => a.Current).Return("burns"); SetupUsers(); var emailPrefs = new List <EmailPreferences>(); emailPrefs.Add(new EmailPreferences("bender")); emailPrefs.Add(new EmailPreferences("hsimpson")); new FakeEmailPreferences(0, EmailPreferenceRepository, emailPrefs, true); var order = SetupData1("bender", OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.AccountManager)); order.DateCreated = new DateTime(2011, 12, 31, 09, 49, 33); order.GenerateRequestNumber(); var approval = new Approval(); approval.StatusCode = OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.AccountManager); approval.Completed = true; #endregion Arrange #region Act NotificationService.OrderApproved(order, approval); #endregion Act #region Assert Assert.AreEqual(2, order.EmailQueuesV2.Count); Assert.AreEqual(EmailPreferences.NotificationTypes.PerEvent, order.EmailQueuesV2[0].NotificationType); Assert.AreEqual(EmailPreferences.NotificationTypes.PerEvent, order.EmailQueuesV2[1].NotificationType); #endregion Assert }
public void TestOrderEditedEmailPrefs2() { #region Arrange UserIdentity.Expect(a => a.Current).Return("hsimpson"); SetupUsers(); var emailPrefs = new List <EmailPreferences>(); emailPrefs.Add(new EmailPreferences("bender")); emailPrefs[0].NotificationType = EmailPreferences.NotificationTypes.Daily; new FakeEmailPreferences(0, EmailPreferenceRepository, emailPrefs, true); var order = SetupData1("bender", OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Approver)); order.DateCreated = new DateTime(2011, 12, 31, 09, 49, 33); var user = UserRepository.GetNullableById("hsimpson"); #endregion Arrange #region Act NotificationService.OrderEdited(order, user); #endregion Act #region Assert Assert.AreEqual(1, order.EmailQueuesV2.Count); Assert.AreEqual(EmailPreferences.NotificationTypes.Daily, order.EmailQueuesV2[0].NotificationType); #endregion Assert }
public void TestOrderCreatedPrefs1() { #region Arrange UserIdentity.Expect(a => a.Current).Return("bender"); SetupUsers(); var order = SetupData1("bender", OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Approver)); order.DateCreated = new DateTime(2011, 12, 31, 09, 49, 33); var approval = new Approval(); approval.StatusCode = OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Approver); approval.Completed = false; order.AddApproval(approval); var emailPrefs = new List <EmailPreferences>(); emailPrefs.Add(new EmailPreferences("bender")); new FakeEmailPreferences(0, EmailPreferenceRepository, emailPrefs, true); order.GenerateRequestNumber(); new FakeAdminWorkgroups(3, AdminWorkgroupRepository); new FakeWorkgroups(3, WorkgroupRepository); #endregion Arrange #region Act NotificationService.OrderCreated(order); #endregion Act #region Assert Assert.AreEqual(1, order.EmailQueuesV2.Count); Assert.AreEqual(DateTime.UtcNow.ToPacificTime().Date, order.EmailQueuesV2[0].DateTimeCreated.Date); Assert.IsNull(order.EmailQueuesV2[0].DateTimeSent); Assert.AreEqual(EmailPreferences.NotificationTypes.PerEvent, order.EmailQueuesV2[0].NotificationType); Assert.IsTrue(order.EmailQueuesV2[0].Pending); Assert.IsNull(order.EmailQueuesV2[0].Status); Assert.AreEqual("Submitted", order.EmailQueuesV2[0].Action); Assert.AreEqual(null, order.EmailQueuesV2[0].Details); #endregion Assert }
public void TestOrderApprovedKualiEmailPrefs1A() { #region Arrange UserIdentity.Expect(a => a.Current).Return("awong"); SetupUsers(); var emailPrefs = new List <EmailPreferences>(); emailPrefs.Add(new EmailPreferences("bender")); emailPrefs.Add(new EmailPreferences("hsimpson")); emailPrefs.Add(new EmailPreferences("flanders")); emailPrefs.Add(new EmailPreferences("awong")); new FakeEmailPreferences(0, EmailPreferenceRepository, emailPrefs, true); var order = SetupData1("bender", OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Complete)); order.DateCreated = new DateTime(2011, 12, 31, 09, 49, 33); var approval = new Approval(); approval.StatusCode = OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Complete); approval.Completed = true; #endregion Arrange #region Act NotificationService.OrderApproved(order, approval); #endregion Act #region Assert Assert.AreEqual(4, order.EmailQueuesV2.Count); #endregion Assert }
public async Task Given_ValidSubmissionData_When_ChangeEmailAddressPost_Then_SavesEmailsAndPendingViewReturned() { // Arrange var model = new ChangeEmailAddressViewModel(TestUserName, null, null) { NewEmailAddress = "*****@*****.**" }; UserIdentity.Expect(e => e.GetUserId(Arg <Controller> .Is.Anything)).Return(TestUserId); _userManager.Expect(a => a.TryLogOnAsync(Arg <string> .Is.Anything, Arg <string> .Is.Anything)).Return(Task.FromResult(new LogonResult { Success = true })); // Act var result = await _sut.ChangeEmailAddressAsync(model); // Assert AssertViewResultReturned(result, "ChangeEmailAddressPending"); _services.AssertWasCalled(a => a.SendEmail(Arg <string> .Is.Anything, Arg <List <string> > .Is.Anything, Arg <List <string> > .Is.Anything, Arg <List <string> > .Is.Anything, Arg <string> .Is.Anything, Arg <string> .Is.Anything, Arg <bool> .Is.Anything)); Context.AssertWasCalled(a => a.SaveChanges()); var user = Context.User.Include("UserLogs").First(a => a.Id == TestUserId); Assert.IsFalse(string.IsNullOrEmpty(user.NewEmailAddressToken)); Assert.IsNotNull(user.NewEmailAddressRequestExpiryDateUtc); Assert.IsFalse(string.IsNullOrEmpty(user.NewEmailAddress)); }
public void TestRemoveDepartmentalReturnsView() { #region Arrange var users = new List <User>(); users.Add(CreateValidEntities.User(3)); users[0].Organizations.Add(CreateValidEntities.Organization(2)); users[0].Organizations.Add(CreateValidEntities.Organization(3)); users[0].SetIdTo("3"); new FakeUsers(0, UserRepository, users, true); UserIdentity.Expect(a => a.IsUserInRole("3", Role.Codes.DepartmentalAdmin)).Return(true); #endregion Arrange #region Act var results = Controller.RemoveDepartmental("3") .AssertViewRendered() .WithViewData <User>(); #endregion Act #region Assert UserIdentity.AssertWasCalled(a => a.IsUserInRole("3", Role.Codes.DepartmentalAdmin)); Assert.IsNotNull(results); Assert.AreEqual("FirstName3", results.FirstName); Assert.AreEqual(2, results.Organizations.Count()); Assert.AreEqual("Name2", results.Organizations[0].Name); Assert.AreEqual("Name3", results.Organizations[1].Name); #endregion Assert }
public void TestOrderCreatedProcessArrival1() { #region Arrange UserIdentity.Expect(a => a.Current).Return("bender"); SetupUsers(); var order = SetupData1("bender", OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Approver)); order.DateCreated = new DateTime(2011, 12, 31, 09, 49, 33); var approvals = new List <Approval>(); CreateApprovals(approvals, OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Approver), order); foreach (var approval in approvals) { order.AddApproval(approval); } order.GenerateRequestNumber(); new FakeEmailPreferences(0, EmailPreferenceRepository); #endregion Arrange #region Act NotificationService.OrderCreated(order); #endregion Act #region Assert Assert.AreEqual(2, order.EmailQueuesV2.Count()); Assert.AreEqual("Submitted", order.EmailQueuesV2[0].Action); Assert.AreEqual(null, order.EmailQueuesV2[0].Details); Assert.AreEqual("bender", order.EmailQueuesV2[0].User.Id); Assert.AreEqual("Arrived", order.EmailQueuesV2[1].Action); Assert.AreEqual("At your level (Approver) for review from Bender Rodriguez.", order.EmailQueuesV2[1].Details); Assert.AreEqual("hsimpson", order.EmailQueuesV2[1].User.Id); #endregion Assert }
public async Task Given_CorrectInformationProvided_When_ChangePassword_Then_SavesRedirectsAndEmails() { // Arrange var model = new ChangePasswordViewModel { OldPassword = "******", NewPassword = "******", ConfirmPassword = "******" }; _userManager.Expect(a => a.ChangePasswordAsync(Arg <int> .Is.Anything, Arg <string> .Is.Anything, Arg <string> .Is.Anything)) .Return(Task.FromResult(new SeIdentityResult())); UserIdentity.Expect(a => a.GetUserId(Arg <Controller> .Is.Anything)).Return(5); _recaptcha.Expect(a => a.ValidateRecaptcha(Arg <Controller> .Is.Anything)).Return(true); // Act var result = await _sut.ChangePasswordAsync(model); // Assert AssertViewResultReturned(result, "ChangePasswordSuccess"); _services.AssertWasCalled(a => a.SendEmail(Arg <string> .Is.Anything, Arg <List <string> > .Is.Anything, Arg <List <string> > .Is.Anything, Arg <List <string> > .Is.Anything, Arg <string> .Is.Anything, Arg <string> .Is.Anything, Arg <bool> .Is.Anything)); _formsAuth.AssertWasCalled(a => a.SignOut()); Context.AssertWasCalled(a => a.SaveChanges()); _httpCache.AssertWasCalled(a => a.RemoveFromCache(Arg <string> .Is.Equal("MustChangePassword-5"))); }
public async Task Given_PasswordsDontMatch_When_ChangePassword_Then_ViewReturnedWithError() { // Arrange var model = new ChangePasswordViewModel { OldPassword = "******", NewPassword = "******", ConfirmPassword = "******" }; _userManager.Expect(a => a.ChangePasswordAsync(Arg <int> .Is.Anything, Arg <string> .Is.Anything, Arg <string> .Is.Anything)) .Return(Task.FromResult(new SeIdentityResult(new List <string> { "Passwords don't match" }))); UserIdentity.Expect(a => a.GetUserId(Arg <Controller> .Is.Anything)).Return(5); _recaptcha.Expect(a => a.ValidateRecaptcha(Arg <Controller> .Is.Anything)).Return(true); // Act var result = await _sut.ChangePasswordAsync(model); // Assert AssertViewResultReturned(result, "ChangePassword"); Context.AssertWasNotCalled(a => a.SaveChanges()); AssertViewResultWithError(result, "Passwords don't match"); }
public void TestOrderEditedNoEmailPrefs1() { #region Arrange UserIdentity.Expect(a => a.Current).Return("hsimpson"); SetupUsers(); var order = SetupData1("bender", OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Approver)); order.DateCreated = new DateTime(2011, 12, 31, 09, 49, 33); var approval = new Approval(); approval.StatusCode = OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Approver); approval.Completed = true; order.GenerateRequestNumber(); new FakeEmailPreferences(0, EmailPreferenceRepository); #endregion Arrange #region Act NotificationService.OrderEdited(order, UserRepository.GetNullableById("hsimpson")); #endregion Act #region Assert Assert.AreEqual(1, order.EmailQueuesV2.Count); Assert.AreEqual(DateTime.UtcNow.ToPacificTime().Date, order.EmailQueuesV2[0].DateTimeCreated.Date); Assert.IsNull(order.EmailQueuesV2[0].DateTimeSent); Assert.AreEqual(EmailPreferences.NotificationTypes.PerEvent, order.EmailQueuesV2[0].NotificationType); Assert.IsTrue(order.EmailQueuesV2[0].Pending); Assert.IsNull(order.EmailQueuesV2[0].Status); Assert.AreEqual("Changed", order.EmailQueuesV2[0].Action); Assert.AreEqual("By Homer Simpson at Approver review.", order.EmailQueuesV2[0].Details); #endregion Assert }
public void TestOrderApprovedPurchaserEmailPrefs5() { #region Arrange UserIdentity.Expect(a => a.Current).Return("awong"); SetupUsers(); var emailPrefs = new List <EmailPreferences>(); emailPrefs.Add(new EmailPreferences("bender")); emailPrefs.Add(new EmailPreferences("hsimpson")); emailPrefs.Add(new EmailPreferences("flanders")); emailPrefs[1].NotificationType = EmailPreferences.NotificationTypes.Daily; emailPrefs[2].NotificationType = EmailPreferences.NotificationTypes.Weekly; emailPrefs[0].AccountManagerPurchaserProcessed = false; //no effect, this is the requester emailPrefs[1].AccountManagerPurchaserProcessed = false; //no effect, this is the approver emailPrefs[2].AccountManagerPurchaserProcessed = false; new FakeEmailPreferences(0, EmailPreferenceRepository, emailPrefs, true); var order = SetupData1("bender", OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Purchaser)); order.DateCreated = new DateTime(2011, 12, 31, 09, 49, 33); var approval = new Approval(); approval.StatusCode = OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Purchaser); approval.Completed = true; #endregion Arrange #region Act NotificationService.OrderApproved(order, approval); #endregion Act #region Assert Assert.AreEqual(2, order.EmailQueuesV2.Count); Assert.AreEqual(EmailPreferences.NotificationTypes.PerEvent, order.EmailQueuesV2[0].NotificationType); Assert.AreEqual(EmailPreferences.NotificationTypes.Daily, order.EmailQueuesV2[1].NotificationType); #endregion Assert }
public void TestOrderCreatedPrefs5() { #region Arrange UserIdentity.Expect(a => a.Current).Return("bender"); SetupUsers(); var order = SetupData1("bender", OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Approver)); order.DateCreated = new DateTime(2011, 12, 31, 09, 49, 33); var approval = new Approval(); approval.StatusCode = OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Approver); approval.Completed = false; order.AddApproval(approval); var emailPrefs = new List <EmailPreferences>(); emailPrefs.Add(new EmailPreferences("bender")); emailPrefs[0].RequesterOrderSubmission = false; new FakeEmailPreferences(0, EmailPreferenceRepository, emailPrefs, true); new FakeAdminWorkgroups(3, AdminWorkgroupRepository); new FakeWorkgroups(3, WorkgroupRepository); #endregion Arrange #region Act NotificationService.OrderCreated(order); #endregion Act #region Assert Assert.AreEqual(0, order.EmailQueuesV2.Count); #endregion Assert }
public void TestOrderCreatedProcessArrival5() { #region Arrange UserIdentity.Expect(a => a.Current).Return("bender"); SetupUsers(); var order = SetupData1("bender", OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Approver)); order.DateCreated = new DateTime(2011, 12, 31, 09, 49, 33); var approvals = new List <Approval>(); CreateApprovals(approvals, OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Approver), order); var saveLevel = 0; foreach (var approval in approvals) { if (approval.User != null && approval.User.Id == "hsimpson") { saveLevel = approval.StatusCode.Level; approval.User = null; approval.SecondaryUser = null; } order.AddApproval(approval); } order.Workgroup.Permissions = new List <WorkgroupPermission>(); var permission = CreateValidEntities.WorkgroupPermission(1); permission.User = new User("Flarg"); permission.Role = new Role(OrderStatusCode.Codes.Approver); permission.Role.Level = saveLevel; order.Workgroup.Permissions.Add(permission); permission = CreateValidEntities.WorkgroupPermission(2); permission.User = new User("Blarg"); permission.Role = new Role(OrderStatusCode.Codes.Approver); permission.Role.Level = saveLevel; order.Workgroup.Permissions.Add(permission); order.GenerateRequestNumber(); new FakeAdminWorkgroups(3, AdminWorkgroupRepository); new FakeWorkgroups(3, WorkgroupRepository); new FakeEmailPreferences(0, EmailPreferenceRepository); #endregion Arrange #region Act NotificationService.OrderCreated(order); #endregion Act #region Assert Assert.AreEqual(3, order.EmailQueuesV2.Count()); Assert.AreEqual("Submitted", order.EmailQueuesV2[0].Action); Assert.AreEqual(null, order.EmailQueuesV2[0].Details); Assert.AreEqual("bender", order.EmailQueuesV2[0].User.Id); Assert.AreEqual("Arrived", order.EmailQueuesV2[1].Action); Assert.AreEqual("At your level (Approver) for review from Bender Rodriguez.", order.EmailQueuesV2[1].Details); Assert.AreEqual("Flarg".ToLower(), order.EmailQueuesV2[1].User.Id); Assert.AreEqual("Arrived", order.EmailQueuesV2[2].Action); Assert.AreEqual("At your level (Approver) for review from Bender Rodriguez.", order.EmailQueuesV2[2].Details); Assert.AreEqual("Blarg".ToLower(), order.EmailQueuesV2[2].User.Id); #endregion Assert }
public void TestOrderApprovedWhenApprovedFromAccManager03() { #region Arrange UserIdentity.Expect(a => a.Current).Return("flanders"); SetupUsers(); var order = SetupData1("bender", OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.AccountManager)); order.DateCreated = new DateTime(2011, 12, 31, 09, 49, 33); var approval = new Approval(); approval.StatusCode = OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.AccountManager); approval.Completed = true; order.Approvals = ApprovalRepository.Queryable.Where(a => a.Order.Id == order.Id).ToList(); foreach (var approval1 in order.Approvals) { if (approval1.StatusCode.Id == OrderStatusCode.Codes.AccountManager) { approval1.Completed = true; } } order.GenerateRequestNumber(); var emailPrefs = new List <EmailPreferences>(); emailPrefs.Add(new EmailPreferences("awong")); emailPrefs[0].NotificationType = EmailPreferences.NotificationTypes.Daily; emailPrefs[0].PurchaserOrderArrive = false; emailPrefs.Add(new EmailPreferences("hsimpson")); emailPrefs[1].NotificationType = EmailPreferences.NotificationTypes.Daily; emailPrefs[1].ApproverAccountManagerApproved = false; new FakeEmailPreferences(0, EmailPreferenceRepository, emailPrefs, true); #endregion Arrange #region Act NotificationService.OrderApproved(order, approval); #endregion Act #region Assert Assert.AreEqual(1, order.EmailQueuesV2.Count); Assert.AreEqual(DateTime.UtcNow.ToPacificTime().Date, order.EmailQueuesV2[0].DateTimeCreated.Date); Assert.IsNull(order.EmailQueuesV2[0].DateTimeSent); Assert.AreEqual(EmailPreferences.NotificationTypes.PerEvent, order.EmailQueuesV2[0].NotificationType); Assert.IsTrue(order.EmailQueuesV2[0].Pending); Assert.IsNull(order.EmailQueuesV2[0].Status); Assert.AreEqual("Approved", order.EmailQueuesV2[0].Action); Assert.AreEqual("By Ned Flanders at Account Manager review.", order.EmailQueuesV2[0].Details); Assert.AreEqual("bender", order.EmailQueuesV2[0].User.Id); //Assert.AreEqual(string.Format("Order request {0} has been approved by Ned Flanders at Account Manager review.", "#testOrg-FT1P9YR"), order.EmailQueuesV2[1].Text); //Assert.AreEqual("hsimpson", order.EmailQueuesV2[1].User.Id); //Assert.AreEqual(string.Format("Order request {0} has arrived at your level (Purchaser) for review from Ned Flanders.", "#testOrg-FT1P9YR"), order.EmailQueuesV2[2].Text); //Assert.AreEqual("awong", order.EmailQueuesV2[2].User.Id); #endregion Assert }
public void TestCreateApprovalsForNewOrder4() { #region Arrange var order = CreateValidEntities.Order(1); order.SetIdTo(99); order.Splits = new List <Split>(); order.Splits.Add(new Split()); //order.Splits[0].Account = "12345"; order.Splits[0].Order = order; order.Workgroup.SetIdTo(1); var workgroupAccounts = new List <WorkgroupAccount>(); workgroupAccounts.Add(CreateValidEntities.WorkgroupAccount(1)); workgroupAccounts[0].Workgroup = order.Workgroup; workgroupAccounts[0].Account = CreateValidEntities.Account(9); workgroupAccounts[0].Account.SetIdTo("12345"); workgroupAccounts[0].Approver = CreateValidEntities.User(11); workgroupAccounts[0].Approver.SetIdTo("11"); workgroupAccounts[0].AccountManager = CreateValidEntities.User(22); workgroupAccounts[0].Purchaser = CreateValidEntities.User(33); new FakeWorkgroupAccounts(0, WorkgroupAccountRepository, workgroupAccounts); //var accounts = new List<Account>(); //accounts.Add(CreateValidEntities.Account(1)); //accounts[0].SetIdTo("12345"); //accounts[0].AccountManagerId = "TestUser"; new FakeAccounts(3, AccountRepository); SecurityService.Expect(a => a.GetUser("TestUser")).Return(CreateValidEntities.User(55)); UserIdentity.Expect(a => a.Current).Return("22"); //NOT same as approver new FakeAutoApprovals(3, AutoAprovalRepository); #endregion Arrange #region Act OrderService.CreateApprovalsForNewOrder(order, null, "12345", null, null); #endregion Act #region Assert SecurityService.AssertWasNotCalled(a => a.GetUser(Arg <string> .Is.Anything)); // the account was not found in the workgroup or the account table EventService.AssertWasCalled(a => a.OrderApprovalAdded(Arg <Order> .Is.Anything, Arg <Approval> .Is.Anything, Arg <bool> .Is.Anything), x => x.Repeat.Times(3)); EventService.AssertWasNotCalled(a => a.OrderAutoApprovalAdded(Arg <Order> .Is.Anything, Arg <Approval> .Is.Anything)); //var args = (Approval)EventService.GetArgumentsForCallsMadeOn(a => a.OrderAutoApprovalAdded(Arg<Order>.Is.Anything, Arg<Approval>.Is.Anything))[0][1]; //Assert.AreEqual(OrderStatusCode.Codes.Approver, args.StatusCode.Id); EventService.AssertWasCalled(a => a.OrderCreated(order)); Assert.AreEqual(3, order.Approvals.Count); Assert.AreEqual(OrderStatusCode.Codes.AccountManager, order.Approvals[1].StatusCode.Id); Assert.AreEqual(OrderStatusCode.Codes.Purchaser, order.Approvals[2].StatusCode.Id); Assert.AreEqual("LastName11", order.Approvals[0].User.LastName); Assert.IsFalse(order.Approvals[0].Completed); Assert.AreEqual("LastName22", order.Approvals[1].User.LastName); Assert.AreEqual("LastName33", order.Approvals[2].User.LastName); Assert.AreEqual("12345", order.Splits[0].Account); #endregion Assert }
public void TestOrderCreatedProcessArrival3() { #region Arrange UserIdentity.Expect(a => a.Current).Return("bender"); SetupUsers(); var order = SetupData1("bender", OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Approver)); order.DateCreated = new DateTime(2011, 12, 31, 09, 49, 33); var approvals = new List <Approval>(); CreateApprovals(approvals, OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Approver), order); var conditionalApproval = new Approval(); conditionalApproval.Order = new Order(); conditionalApproval.Order.SetIdTo(order.Id); conditionalApproval.StatusCode = OrderStatusCodeRepository.GetNullableById(Role.Codes.Approver); conditionalApproval.User = UserRepository.GetNullableById("zoidberg"); conditionalApproval.SecondaryUser = UserRepository.GetNullableById("flanders"); approvals.Add(conditionalApproval); foreach (var approval in approvals) { if (approval.User != null && approval.User.Id == "hsimpson") { approval.User.IsAway = true; approval.SecondaryUser = UserRepository.Queryable.Single(a => a.Id == "awong"); } order.AddApproval(approval); } order.GenerateRequestNumber(); new FakeEmailPreferences(0, EmailPreferenceRepository); #endregion Arrange #region Act NotificationService.OrderCreated(order); #endregion Act #region Assert Assert.AreEqual(5, order.EmailQueuesV2.Count()); Assert.AreEqual("Submitted", order.EmailQueuesV2[0].Action); Assert.AreEqual(null, order.EmailQueuesV2[0].Details); Assert.AreEqual("bender", order.EmailQueuesV2[0].User.Id); Assert.AreEqual("Arrived", order.EmailQueuesV2[1].Action); Assert.AreEqual("At your level (Approver) for review from Bender Rodriguez.", order.EmailQueuesV2[1].Details); Assert.AreEqual("hsimpson", order.EmailQueuesV2[1].User.Id); Assert.AreEqual("Arrived", order.EmailQueuesV2[2].Action); Assert.AreEqual("At your level (Approver) for review from Bender Rodriguez.", order.EmailQueuesV2[2].Details); Assert.AreEqual("awong", order.EmailQueuesV2[2].User.Id); Assert.AreEqual("Arrived", order.EmailQueuesV2[3].Action); Assert.AreEqual("At your level (Approver) for review from Bender Rodriguez.", order.EmailQueuesV2[3].Details); Assert.AreEqual("zoidberg", order.EmailQueuesV2[3].User.Id); Assert.AreEqual("Arrived", order.EmailQueuesV2[4].Action); Assert.AreEqual("At your level (Approver) for review from Bender Rodriguez.", order.EmailQueuesV2[4].Details); Assert.AreEqual("flanders", order.EmailQueuesV2[4].User.Id); #endregion Assert }
public void Given_UserLoggedOn_When_EditCurrentGet_Then_RedirectToActionForCurrentUserReturned() { // Arrange UserIdentity.Expect(a => a.GetUserId(Arg <Controller> .Is.Anything)).Return(TestUserId); // Act var result = _sut.EditCurrent(); // Assert AssertRedirectToActionReturned(result, TestUserId, "Edit", "User"); }
public void Given_AccountNotFound_When_LandingGet_Then_RedirectToLogon() { // Arrange UserIdentity.Expect(u => u.GetUserId(Arg <Controller> .Is.Anything)).Return(4); // Act var result = _sut.Landing(); // Assert Assert.IsNotNull(result, "No result was returned from controller"); AssertRedirectToActionReturned(result, "Index", "Home"); }
public void TestCreateApprovalsForNewOrder29() { #region Arrange var order = CreateValidEntities.Order(1); order.SetIdTo(99); order.Splits = new List <Split>(); order.Splits.Add(new Split()); order.Splits[0].Account = null; order.Splits[0].Order = order; order.Workgroup.SetIdTo(1); new FakeWorkgroupAccounts(3, WorkgroupAccountRepository); new FakeAccounts(3, AccountRepository); new FakeUsers(6, UserRepository); var conditionalApprovalIds = new[] { 1, 2 }; var conditionalApprovals = new List <ConditionalApproval>(); conditionalApprovals.Add(CreateValidEntities.ConditionalApproval(1)); conditionalApprovals[0].PrimaryApprover = CreateValidEntities.User(4); conditionalApprovals[0].SecondaryApprover = CreateValidEntities.User(5); conditionalApprovals.Add(CreateValidEntities.ConditionalApproval(2)); conditionalApprovals[1].PrimaryApprover = CreateValidEntities.User(6); conditionalApprovals[1].SecondaryApprover = null; new FakeConditionalApprovals(0, ConditionalApprovalRepository, conditionalApprovals); UserIdentity.Expect(a => a.Current).Return("4"); // Same As conditional approval, but conditional approvals do not auto approve. #endregion Arrange #region Act OrderService.CreateApprovalsForNewOrder(order, conditionalApprovalIds, null, null, "2"); #endregion Act #region Assert SecurityService.AssertWasNotCalled(a => a.GetUser(Arg <string> .Is.Anything)); // the account was not found in the workgroup or the account table EventService.AssertWasCalled(a => a.OrderApprovalAdded(Arg <Order> .Is.Anything, Arg <Approval> .Is.Anything, Arg <bool> .Is.Anything), x => x.Repeat.Times(3)); EventService.AssertWasNotCalled(a => a.OrderAutoApprovalAdded(Arg <Order> .Is.Anything, Arg <Approval> .Is.Anything)); EventService.AssertWasCalled(a => a.OrderCreated(order)); Assert.AreEqual(5, order.Approvals.Count); Assert.AreEqual(OrderStatusCode.Codes.Approver, order.Approvals[0].StatusCode.Id); Assert.IsNull(order.Approvals[0].User); Assert.AreEqual(OrderStatusCode.Codes.AccountManager, order.Approvals[1].StatusCode.Id); Assert.AreEqual("LastName2", order.Approvals[1].User.LastName); Assert.AreEqual(OrderStatusCode.Codes.Purchaser, order.Approvals[2].StatusCode.Id); Assert.AreEqual("LastName4", order.Approvals[3].User.LastName); Assert.AreEqual(OrderStatusCode.Codes.ConditionalApprover, order.Approvals[3].StatusCode.Id); Assert.AreEqual("LastName5", order.Approvals[3].SecondaryUser.LastName); Assert.AreEqual("LastName6", order.Approvals[4].User.LastName); Assert.AreEqual(OrderStatusCode.Codes.ConditionalApprover, order.Approvals[4].StatusCode.Id); Assert.IsNull(order.Approvals[4].SecondaryUser); #endregion Assert }
public void TestOrderApprovedWhenApprovedFromPurchaser01() { #region Arrange UserIdentity.Expect(a => a.Current).Return("awong"); SetupUsers(); var order = SetupData1("bender", OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Purchaser)); order.DateCreated = new DateTime(2011, 12, 31, 09, 49, 33); var approval = new Approval(); approval.StatusCode = OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Purchaser); approval.Completed = true; order.Approvals = ApprovalRepository.Queryable.Where(a => a.Order.Id == order.Id).ToList(); foreach (var approval1 in order.Approvals) { if (approval1.StatusCode.Id == OrderStatusCode.Codes.Purchaser) { approval1.Completed = true; } } order.GenerateRequestNumber(); new FakeEmailPreferences(0, EmailPreferenceRepository); #endregion Arrange #region Act NotificationService.OrderApproved(order, approval); #endregion Act #region Assert Assert.AreEqual(4, order.EmailQueuesV2.Count); Assert.AreEqual(DateTime.UtcNow.ToPacificTime().Date, order.EmailQueuesV2[0].DateTimeCreated.Date); Assert.IsNull(order.EmailQueuesV2[0].DateTimeSent); Assert.AreEqual(EmailPreferences.NotificationTypes.PerEvent, order.EmailQueuesV2[0].NotificationType); Assert.IsTrue(order.EmailQueuesV2[0].Pending); Assert.IsNull(order.EmailQueuesV2[0].Status); Assert.AreEqual("Approved", order.EmailQueuesV2[0].Action); Assert.AreEqual("By Amy Wong at Purchaser review.", order.EmailQueuesV2[0].Details); Assert.AreEqual("bender", order.EmailQueuesV2[0].User.Id); Assert.AreEqual("Approved", order.EmailQueuesV2[1].Action); Assert.AreEqual("By Amy Wong at Purchaser review.", order.EmailQueuesV2[1].Details); Assert.AreEqual("hsimpson", order.EmailQueuesV2[1].User.Id); Assert.AreEqual("Approved", order.EmailQueuesV2[2].Action); Assert.AreEqual("By Amy Wong at Purchaser review.", order.EmailQueuesV2[2].Details); Assert.AreEqual("flanders", order.EmailQueuesV2[2].User.Id); //Don't care about this, just an artifact of the test data //Assert.AreEqual(string.Format("Order request {0} has arrived at your level (Complete-Not Uploaded KFS) for review from Amy Wong.", "#testOrg-FT1P9YR"), order.EmailQueuesV2[3].Text); //Assert.AreEqual("flanders", order.EmailQueuesV2[3].User.Id); #endregion Assert }
public void When_LogOff_Then_SessionAbandoned() { // Arrange _formsAuth.Expect(a => a.SignOut()); HttpSession.Expect(h => h.Abandon()); UserIdentity.Expect(a => a.RemoveAntiForgeryCookie(Arg <Controller> .Is.Anything)); // Act var result = _sut.LogOff(); // Assert AssertRedirectToActionReturned(result, "LogOn", "Account"); }
public void Given_PreviousUserActivity_When_LandingGet_Then_LastActivityDisplayed() { // Arrange UserIdentity.Expect(u => u.GetUserId(Arg <Controller> .Is.Anything)).Return(5); // Act var result = _sut.Landing(); // Assert var data = AssertViewResultReturnsType <LandingViewModel>(result); Assert.AreEqual(LastAccountActivity.ToLocalTime().ToString("dd/MM/yyyy HH:mm"), data.LastAccountActivity); Assert.AreEqual(TestFirstName, data.FirstName); }
public void Given_UserExists_When_ChangeEmailAddressGet_Then_ViewReturned() { // Arrange UserIdentity.Expect(a => a.GetUserId(Arg <Controller> .Is.Anything)).Return(TestUserId); // Act var result = _sut.ChangeEmailAddress(); // Assert var viewModel = AssertViewResultReturnsType <ChangeEmailAddressViewModel>(result); Assert.AreEqual(TestUserName, viewModel.EmailAddress); Assert.IsFalse(viewModel.IsFormLocked); }
public void TestCreateApprovalsForNewOrder26() { #region Arrange var order = CreateValidEntities.Order(1); order.CreatedBy = CreateValidEntities.User(109); order.SetIdTo(99); order.Splits = new List <Split>(); order.Splits.Add(new Split()); order.Splits[0].Account = null; order.Splits[0].Order = order; order.Workgroup.SetIdTo(1); new FakeWorkgroupAccounts(3, WorkgroupAccountRepository); new FakeAccounts(3, AccountRepository); new FakeUsers(3, UserRepository); UserIdentity.Expect(a => a.Current).Return("3"); var autoApprovals = new List <AutoApproval>(); autoApprovals.Add(CreateValidEntities.AutoApproval(1)); autoApprovals[0].User = CreateValidEntities.User(1); autoApprovals[0].IsActive = true; autoApprovals[0].Expiration = DateTime.UtcNow.ToPacificTime().AddDays(1); autoApprovals[0].TargetUser = order.CreatedBy; autoApprovals[0].Account = null; new FakeAutoApprovals(0, AutoAprovalRepository, autoApprovals); #endregion Arrange #region Act OrderService.CreateApprovalsForNewOrder(order, null, null, "1", "2"); #endregion Act #region Assert EventService.AssertWasCalled(a => a.OrderApprovalAdded(Arg <Order> .Is.Anything, Arg <Approval> .Is.Anything, Arg <bool> .Is.Anything), x => x.Repeat.Times(2)); EventService.AssertWasCalled(a => a.OrderAutoApprovalAdded(Arg <Order> .Is.Anything, Arg <Approval> .Is.Anything)); var args = (Approval)EventService.GetArgumentsForCallsMadeOn(a => a.OrderAutoApprovalAdded(Arg <Order> .Is.Anything, Arg <Approval> .Is.Anything))[0][1]; Assert.AreEqual(OrderStatusCode.Codes.Approver, args.StatusCode.Id); Assert.AreEqual(3, order.Approvals.Count); Assert.AreEqual(OrderStatusCode.Codes.Approver, order.Approvals[0].StatusCode.Id); Assert.AreEqual("LastName1", order.Approvals[0].User.LastName); Assert.AreEqual(OrderStatusCode.Codes.AccountManager, order.Approvals[1].StatusCode.Id); Assert.AreEqual("LastName2", order.Approvals[1].User.LastName); Assert.AreEqual(OrderStatusCode.Codes.Purchaser, order.Approvals[2].StatusCode.Id); #endregion Assert }
public void TestRemoveAdminRedirectsWhenUserNotInRole() { #region Arrange new FakeUsers(3, UserRepository); UserIdentity.Expect(a => a.IsUserInRole("3", Role.Codes.Admin)).Return(false); #endregion Arrange #region Act Controller.RemoveAdmin("3") .AssertActionRedirect() .ToAction <AdminController>(a => a.Index()); #endregion Act #region Assert Assert.AreEqual("3 is not an admin", Controller.Message); UserIdentity.AssertWasCalled(a => a.IsUserInRole("3", Role.Codes.Admin)); #endregion Assert }
public void TestRemoveAdminRedirectsWhenUserInRole() { #region Arrange new FakeUsers(3, UserRepository); UserIdentity.Expect(a => a.IsUserInRole("3", Role.Codes.Admin)).Return(true); #endregion Arrange #region Act var result = Controller.RemoveAdmin("3") .AssertViewRendered() .WithViewData <User>(); #endregion Act #region Assert UserIdentity.AssertWasCalled(a => a.IsUserInRole("3", Role.Codes.Admin)); Assert.IsNotNull(result); Assert.AreEqual("FirstName3 LastName3 (3)", result.FullNameAndId); #endregion Assert }
public void TestCreateApprovalsForNewOrder16() { #region Arrange var order = CreateValidEntities.Order(1); order.SetIdTo(99); order.CreatedBy = CreateValidEntities.User(109); order.Splits = new List <Split>(); order.Splits.Add(new Split()); //order.Splits[0].Account = "12345"; order.Splits[0].Order = order; order.Workgroup.SetIdTo(1); new FakeUsers(3, UserRepository); UserIdentity.Expect(a => a.Current).Return("1"); new FakeAutoApprovals(3, AutoAprovalRepository); #endregion Arrange #region Act OrderService.CreateApprovalsForNewOrder(order, null, null, "3", "2"); #endregion Act #region Assert SecurityService.AssertWasNotCalled(a => a.GetUser(Arg <string> .Is.Anything)); // the account was not found in the workgroup or the account table EventService.AssertWasCalled(a => a.OrderApprovalAdded(Arg <Order> .Is.Anything, Arg <Approval> .Is.Anything, Arg <bool> .Is.Anything), x => x.Repeat.Times(3)); EventService.AssertWasNotCalled(a => a.OrderAutoApprovalAdded(Arg <Order> .Is.Anything, Arg <Approval> .Is.Anything)); //var args = (Approval)EventService.GetArgumentsForCallsMadeOn(a => a.OrderAutoApprovalAdded(Arg<Order>.Is.Anything, Arg<Approval>.Is.Anything))[0][1]; //Assert.AreEqual(OrderStatusCode.Codes.Approver, args.StatusCode.Id); EventService.AssertWasCalled(a => a.OrderCreated(order)); Assert.AreEqual(3, order.Approvals.Count); Assert.AreEqual(OrderStatusCode.Codes.AccountManager, order.Approvals[1].StatusCode.Id); Assert.AreEqual(OrderStatusCode.Codes.Purchaser, order.Approvals[2].StatusCode.Id); Assert.AreEqual("LastName3", order.Approvals[0].User.LastName); Assert.IsFalse(order.Approvals[0].Completed); Assert.AreEqual("LastName2", order.Approvals[1].User.LastName); Assert.IsNull(order.Approvals[2].User); Assert.AreEqual(null, order.Splits[0].Account); Assert.AreEqual(OrderStatusCode.Codes.Approver, order.StatusCode.Id); #endregion Assert }
public void TestOrderEditedShouldCreateEmailQueueWithUserOrEmail() { #region Arrange UserIdentity.Expect(a => a.Current).Return("hsimpson"); SetupUsers(); var order = SetupData1("bender", OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Approver)); order.DateCreated = new DateTime(2011, 12, 31, 09, 49, 33); var approval = new Approval(); approval.StatusCode = OrderStatusCodeRepository.GetNullableById(OrderStatusCode.Codes.Approver); approval.Completed = true; new FakeEmailPreferences(0, EmailPreferenceRepository); #endregion Arrange #region Act NotificationService.OrderEdited(order, UserRepository.GetNullableById("hsimpson")); #endregion Act #region Assert Assert.AreEqual(1, order.EmailQueuesV2.Count); Assert.IsTrue(order.EmailQueuesV2[0].User != null || !string.IsNullOrWhiteSpace(order.EmailQueuesV2[0].Email)); #endregion Assert }
public void TestReRouteApprovalsForExistingOrderWhenCurrectLevelIsApprove02() { #region Arrange var order = CreateValidEntities.Order(1); order.CreatedBy = CreateValidEntities.User(3); order.SetIdTo(99); order.Splits = new List <Split>(); order.Splits.Add(CreateValidEntities.Split(1)); order.Splits[0].Order = order; order.StatusCode = OrderStatusCodeRepository.Queryable.Single(a => a.Id == OrderStatusCode.Codes.Approver); order.Approvals = new List <Approval>(); order.Approvals.Add(CreateValidEntities.Approval(1)); order.Approvals.Add(CreateValidEntities.Approval(2)); order.Approvals.Add(CreateValidEntities.Approval(3)); order.Approvals[0].StatusCode = OrderStatusCodeRepository.Queryable.Single(a => a.Id == OrderStatusCode.Codes.Approver); order.Approvals[1].StatusCode = OrderStatusCodeRepository.Queryable.Single(a => a.Id == OrderStatusCode.Codes.AccountManager); order.Approvals[2].StatusCode = OrderStatusCodeRepository.Queryable.Single(a => a.Id == OrderStatusCode.Codes.Purchaser); new FakeUsers(4, UserRepository); UserIdentity.Expect(a => a.Current).Return("3"); #endregion Arrange #region Act OrderService.ReRouteApprovalsForExistingOrder(order, "3", "2"); #endregion Act #region Assert EventService.AssertWasCalled(a => a.OrderApprovalAdded(Arg <Order> .Is.Anything, Arg <Approval> .Is.Anything, Arg <bool> .Is.Anything), x => x.Repeat.Times(2)); EventService.AssertWasCalled(a => a.OrderAutoApprovalAdded(Arg <Order> .Is.Anything, Arg <Approval> .Is.Anything)); EventService.AssertWasCalled(a => a.OrderReRouted(order)); Assert.AreEqual(3, order.Approvals.Count); Assert.AreEqual("LastName3", order.Approvals[0].User.LastName); Assert.IsTrue(order.Approvals[0].Completed); Assert.AreEqual("LastName2", order.Approvals[1].User.LastName); Assert.IsNull(order.Approvals[2].User); #endregion Assert }
public void TestCreateApprovalsForNewOrder24() { #region Arrange var order = CreateValidEntities.Order(1); order.SetIdTo(99); order.Splits = new List <Split>(); order.Splits.Add(new Split()); order.Splits[0].Account = null; order.Splits[0].Order = order; order.Workgroup.SetIdTo(1); new FakeWorkgroupAccounts(3, WorkgroupAccountRepository); new FakeAccounts(3, AccountRepository); new FakeUsers(3, UserRepository); UserIdentity.Expect(a => a.Current).Return("22"); //NOT same as approver new FakeAutoApprovals(3, AutoAprovalRepository); #endregion Arrange #region Act OrderService.CreateApprovalsForNewOrder(order, null, null, "1", "2"); #endregion Act #region Assert SecurityService.AssertWasNotCalled(a => a.GetUser(Arg <string> .Is.Anything)); // the account was not found in the workgroup or the account table EventService.AssertWasCalled(a => a.OrderApprovalAdded(Arg <Order> .Is.Anything, Arg <Approval> .Is.Anything, Arg <bool> .Is.Anything), x => x.Repeat.Times(3)); EventService.AssertWasNotCalled(a => a.OrderAutoApprovalAdded(Arg <Order> .Is.Anything, Arg <Approval> .Is.Anything)); EventService.AssertWasCalled(a => a.OrderCreated(order)); Assert.AreEqual(3, order.Approvals.Count); Assert.AreEqual(OrderStatusCode.Codes.Approver, order.Approvals[0].StatusCode.Id); Assert.AreEqual("LastName1", order.Approvals[0].User.LastName); Assert.AreEqual(OrderStatusCode.Codes.AccountManager, order.Approvals[1].StatusCode.Id); Assert.AreEqual("LastName2", order.Approvals[1].User.LastName); Assert.AreEqual(OrderStatusCode.Codes.Purchaser, order.Approvals[2].StatusCode.Id); #endregion Assert }