示例#1
0
        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
        }
示例#2
0
        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
        }
示例#3
0
        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
        }
示例#4
0
        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
        }
示例#5
0
        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 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 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
        }
示例#8
0
        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
        }
示例#9
0
        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
        }
示例#11
0
        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
        }
示例#12
0
        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
        }
示例#13
0
        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
        }
示例#14
0
        public void TestOrderCreatedProcessArrival12()
        {
            #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("zoidberg");
            approvals.Add(conditionalApproval);

            var accountManager = new Approval();
            accountManager.Order = new Order();
            accountManager.Order.SetIdTo(order.Id);
            accountManager.StatusCode    = OrderStatusCodeRepository.GetNullableById(Role.Codes.AccountManager);
            accountManager.User          = UserRepository.GetNullableById("AccManag".ToLower());
            accountManager.SecondaryUser = UserRepository.GetNullableById("AccManag".ToLower());
            approvals.Add(accountManager);

            var purchaser = new Approval();
            purchaser.Order = new Order();
            purchaser.Order.SetIdTo(order.Id);
            purchaser.StatusCode    = OrderStatusCodeRepository.GetNullableById(Role.Codes.AccountManager);
            purchaser.User          = UserRepository.GetNullableById("pur");
            purchaser.SecondaryUser = UserRepository.GetNullableById("pur");
            approvals.Add(purchaser);

            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();

            var emailPrefs = new List <EmailPreferences>();
            emailPrefs.Add(new EmailPreferences("bender"));
            emailPrefs[0].NotificationType         = EmailPreferences.NotificationTypes.Daily;
            emailPrefs[0].RequesterOrderSubmission = false;

            emailPrefs.Add(new EmailPreferences("Flarg".ToLower()));
            emailPrefs[1].NotificationType         = EmailPreferences.NotificationTypes.Daily;
            emailPrefs[1].RequesterOrderSubmission = true;  //Doesn't Matter, did not create it
            emailPrefs[1].ApproverOrderArrive      = false;

            emailPrefs.Add(new EmailPreferences("Blarg".ToLower()));
            emailPrefs[2].NotificationType         = EmailPreferences.NotificationTypes.Daily;
            emailPrefs[2].RequesterOrderSubmission = false;  //Doesn't Matter, did not create it
            emailPrefs[2].ApproverOrderArrive      = false;

            emailPrefs.Add(new EmailPreferences("zoidberg"));
            emailPrefs[3].NotificationType    = EmailPreferences.NotificationTypes.Daily;
            emailPrefs[3].ApproverOrderArrive = 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());
            Assert.AreEqual(7, order.Approvals.Count());
            //Assert.AreEqual(string.Format("Order request {0} has been submitted.", "#testOrg-FT1P9YR"), order.EmailQueuesV2[0].Text);
            //Assert.AreEqual("bender", order.EmailQueuesV2[0].User.Id);
            //Assert.AreEqual(string.Format("Order request {0} has arrived at your level (Approver) for review from Bender Rodriguez.", "#testOrg-FT1P9YR"), order.EmailQueuesV2[0].Text);
            //Assert.AreEqual("Flarg", order.EmailQueuesV2[0].User.Id);
            //Assert.AreEqual(string.Format("Order request {0} has arrived at your level (Approver) for review from Bender Rodriguez.", "#testOrg-FT1P9YR"), order.EmailQueuesV2[0].Text);
            //Assert.AreEqual("Blarg", order.EmailQueuesV2[0].User.Id);

            //Assert.AreEqual(string.Format("Order request {0} has arrived at your level (Approver) for review from Bender Rodriguez.", "#testOrg-FT1P9YR"), order.EmailQueuesV2[1].Text);
            //Assert.AreEqual("zoidberg", order.EmailQueuesV2[1].User.Id);
            #endregion Assert
        }
示例#15
0
        public void TestOrderApprovedWhenApproved02()
        {
            #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;


            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          = new User("Blah");
            conditionalApproval.SecondaryUser = new User("Blah");
            approvals.Add(conditionalApproval);

            var AccManage = new Approval();
            AccManage.Order = new Order();
            AccManage.Order.SetIdTo(order.Id);
            AccManage.StatusCode    = OrderStatusCodeRepository.GetNullableById(Role.Codes.AccountManager);
            AccManage.User          = new User("AccMan");
            AccManage.SecondaryUser = null;
            approvals.Add(AccManage);

            var pur = new Approval();
            pur.Order = new Order();
            pur.Order.SetIdTo(order.Id);
            pur.StatusCode    = OrderStatusCodeRepository.GetNullableById(Role.Codes.Purchaser);
            pur.User          = new User("pur");
            pur.SecondaryUser = null;
            approvals.Add(pur);

            foreach (var app in approvals)
            {
                if (app.StatusCode.Id == OrderStatusCode.Codes.Approver)
                {
                    app.Completed = true;
                }
                order.AddApproval(app);
            }
            order.GenerateRequestNumber();
            new FakeEmailPreferences(0, EmailPreferenceRepository);
            #endregion Arrange

            #region Act
            NotificationService.OrderApproved(order, approval);
            #endregion Act

            #region Assert
            Assert.AreEqual(3, 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 Homer Simpson at Approver review.", order.EmailQueuesV2[0].Details);
            Assert.AreEqual("bender", order.EmailQueuesV2[0].User.Id);

            Assert.AreEqual("Arrived", order.EmailQueuesV2[1].Action);
            Assert.AreEqual("At your level (Account Manager) for review from Homer Simpson.", order.EmailQueuesV2[1].Details);
            Assert.AreEqual("flanders", order.EmailQueuesV2[1].User.Id);

            Assert.AreEqual("Arrived", order.EmailQueuesV2[2].Action);
            Assert.AreEqual("At your level (Account Manager) for review from Homer Simpson.", order.EmailQueuesV2[1].Details);
            Assert.AreEqual("AccMan".ToLower(), order.EmailQueuesV2[2].User.Id);
            #endregion Assert
        }