Example #1
0
        public void DoesNotRequireApproval()
        {
            var mockActivityIdProperty = new Mock <IPropertyInfo>();

            mockActivityIdProperty.Setup(mp => mp.Type).Returns(typeof(int));
            mockActivityIdProperty.Setup(mp => mp.Name).Returns("ActivityId");
            var mockStatusProperty = new Mock <IPropertyInfo>();

            mockStatusProperty.Setup(mp => mp.Type).Returns(typeof(Common.Enums.ActivitySubmissionStatus));
            mockStatusProperty.Setup(mp => mp.Name).Returns("Status");
            var mockApprovedByIdProperty = new Mock <IPropertyInfo>();

            mockApprovedByIdProperty.Setup(mp => mp.Type).Returns(typeof(int));
            mockApprovedByIdProperty.Setup(mp => mp.Name).Returns("ApprovedById");

            var newRule = new DefaultActivityStatus(mockActivityIdProperty.Object, mockStatusProperty.Object, mockApprovedByIdProperty.Object);

            var targetObject = new Mock <IActivityEdit>();

            var ruleContext = new RuleContext(Complete, newRule, targetObject.Object, new Dictionary <IPropertyInfo, object> {
                { mockActivityIdProperty.Object, ItemRequiresApproval + 1 }, { mockStatusProperty.Object, Common.Enums.ActivitySubmissionStatus.Unset }, { mockApprovedByIdProperty.Object, 0 }
            });

            var ruleRunner = (IBusinessRule)newRule;

            ruleRunner.Execute(ruleContext);

            Assert.IsNotNull(newRule);
            Assert.IsTrue(ruleContext.OutputPropertyValues.Count == 1);
            Assert.IsNotNull(ruleContext.OutputPropertyValues.SingleOrDefault(o => o.Key.Name == mockStatusProperty.Object.Name));
            Assert.AreEqual(Common.Enums.ActivitySubmissionStatus.Approved, ruleContext.OutputPropertyValues.Single(o => o.Key.Name == mockStatusProperty.Object.Name).Value);
        }
Example #2
0
        public void LeaveApprovedAlone()
        {
            var mockActivityIdProperty = new Mock <IPropertyInfo>();

            mockActivityIdProperty.Setup(mp => mp.Type).Returns(typeof(int));
            mockActivityIdProperty.Setup(mp => mp.Name).Returns("ActivityId");
            var mockStatusProperty = new Mock <IPropertyInfo>();

            mockStatusProperty.Setup(mp => mp.Type).Returns(typeof(Common.Enums.ActivitySubmissionStatus));
            mockStatusProperty.Setup(mp => mp.Name).Returns("Status");
            var mockApprovedByIdProperty = new Mock <IPropertyInfo>();

            mockApprovedByIdProperty.Setup(mp => mp.Type).Returns(typeof(int));
            mockApprovedByIdProperty.Setup(mp => mp.Name).Returns("ApprovedById");

            var newRule = new DefaultActivityStatus(mockActivityIdProperty.Object, mockStatusProperty.Object, mockApprovedByIdProperty.Object);


            var targetObject = new Mock <IActivityEdit>();

            var ruleContext = new RuleContext(Complete, newRule, targetObject.Object, new Dictionary <IPropertyInfo, object> {
                { mockActivityIdProperty.Object, 1 }, { mockStatusProperty.Object, Common.Enums.ActivitySubmissionStatus.Approved }, { mockApprovedByIdProperty.Object, 54 }
            });

            var ruleRunner = (IBusinessRule)newRule;

            ruleRunner.Execute(ruleContext);

            Assert.IsNotNull(newRule);
            Assert.IsNull(ruleContext.OutputPropertyValues);
        }
        public void ApprovedByIdCorrectType()
        {
            var mockActivityIdProperty = new Mock <IPropertyInfo>();

            mockActivityIdProperty.Setup(mp => mp.Type).Returns(typeof(int));
            mockActivityIdProperty.Setup(mp => mp.Name).Returns("ActivityId");
            var mockStatusProperty = new Mock <IPropertyInfo>();

            mockStatusProperty.Setup(mp => mp.Type).Returns(typeof(Common.Enums.ActivitySubmissionStatus));
            var mockApprovedByIdProperty = new Mock <IPropertyInfo>();

            mockApprovedByIdProperty.Setup(mp => mp.Type).Returns(typeof(string));

            var newRule = new DefaultActivityStatus(mockActivityIdProperty.Object, mockStatusProperty.Object, mockApprovedByIdProperty.Object);

            Assert.Fail("Rule Created when error should occur.");
        }
Example #4
0
        public void AcceptsCorrectParameters()
        {
            var mockActivityIdProperty = new Mock <IPropertyInfo>();

            mockActivityIdProperty.Setup(mp => mp.Type).Returns(typeof(int));
            mockActivityIdProperty.Setup(mp => mp.Name).Returns("ActivityId");
            var mockStatusProperty = new Mock <IPropertyInfo>();

            mockStatusProperty.Setup(mp => mp.Type).Returns(typeof(Common.Enums.ActivitySubmissionStatus));
            var mockApprovedByIdProperty = new Mock <IPropertyInfo>();

            mockApprovedByIdProperty.Setup(mp => mp.Type).Returns(typeof(int));

            var newRule = new DefaultActivityStatus(mockActivityIdProperty.Object, mockStatusProperty.Object, mockApprovedByIdProperty.Object);

            Assert.IsNotNull(newRule);
        }