Ejemplo n.º 1
0
        public void RuleConstructorTest()
        {
            var newActionType = RequestedOperation.Compile;
            var newIsPublic = false;
            var newIsRetired = true;
            var newNameRequiredAction = RequiredChange.MustChange;
            var newMajorRequiredAction = RequiredChange.MustIncrement;
            var newMinorRequiredAction = RequiredChange.MustReset;
            var newBuildRequiredAction = RequiredChange.NoActionRequired;
            var newRevisionRequiredAction = RequiredChange.MustChange;

            Rule target = new Rule(newActionType,
                                                newIsPublic,
                                                newIsRetired,
                                                newNameRequiredAction,
                                                newMajorRequiredAction,
                                                newMinorRequiredAction,
                                                newBuildRequiredAction,
                                                newRevisionRequiredAction);

            Assert.IsTrue(target.IsPublic == newIsPublic);
            Assert.IsTrue(target.IsRetired == newIsRetired);
            Assert.IsTrue(target.NameRequiredChange == newNameRequiredAction);
            Assert.IsTrue(target.MajorRequiredChange == newMajorRequiredAction);
            Assert.IsTrue(target.MinorRequiredChange == newMinorRequiredAction);
            Assert.IsTrue(target.BuildRequiredChange == newBuildRequiredAction);
            Assert.IsTrue(target.BuildRequiredChange == newBuildRequiredAction);
            Assert.IsTrue(target.RevisionRequiredChange == newRevisionRequiredAction);
        }
Ejemplo n.º 2
0
        public void RuleTest()
        {
            VersionFault target = new VersionFault();
            Rule expected = new Rule(RequestedOperation.Compile,
                                     false,
                                     true,
                                     RequiredChange.MustChange,
                                     RequiredChange.MustIncrement,
                                     RequiredChange.MustReset,
                                     RequiredChange.NoActionRequired,
                                     RequiredChange.MustChange);

            Rule actual;

            target.Rule = expected;
            actual = target.Rule;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 3
0
        public void VersionExceptionConstructorTest()
        {
            string message = new string('A', 150);
            Rule rule = new Rule(RequestedOperation.Compile,
                                    false,
                                    true,
                                    RequiredChange.MustChange,
                                    RequiredChange.MustIncrement,
                                    RequiredChange.MustReset,
                                    RequiredChange.NoActionRequired,
                                    RequiredChange.MustChange);

            var target = new VersionException(message, rule);

            Assert.IsNotNull(target);

            Assert.AreEqual(message, target.Message);
            Assert.AreEqual(rule, target.Rule);
        }
Ejemplo n.º 4
0
        private static bool CheckVersionSection(Rule rule,
            Section section,
            IEnumerable<StoreActivitiesDC> previousVersions,
            StoreActivitiesDC workflowToTest,
            ref string errorString)
        {
            var isRulePassed = true; // defaults to a state of passing the section

            // make a lookup so we can easily determine the required change, without resorting to a switch statement or similar
            var ruleActions = new Dictionary<Section, RequiredChange>
                                  {
                                     {Section.Major,    rule.MajorRequiredChange},
                                     {Section.Minor,    rule.MinorRequiredChange},
                                     {Section.Build,    rule.BuildRequiredChange},
                                     {Section.Revision, rule.RevisionRequiredChange},
                                  };

            var ruleAction = ruleActions.First(ruleAction1 => ruleAction1.Key == section).Value;

            if (ruleAction != RequiredChange.NoActionRequired)
            {
                var sectionValue = GetVersionSection(workflowToTest.Version, section); // the value of the specified piece of the version number

                switch (ruleAction)
                {
                    case RequiredChange.MustIncrement:
                        if (previousVersions.Any())
                            isRulePassed = previousVersions
                                               .Select(workflow => GetVersionSection(workflow.Version, section))
                                               .Max() < sectionValue;
                        if (!isRulePassed)
                            errorString += string.Format(MustBeIncrementedMessage, section.ToString());

                        break;

                    case RequiredChange.MustReset:
                        isRulePassed = (sectionValue == versionSectionResetValues[section]);
                        if (!isRulePassed)
                            errorString += string.Format(MustBeResetMessage, section, versionSectionResetValues[section]);

                        break;

                    default:
                        throw new NotImplementedException();
                }
            }

            return isRulePassed;
        }
Ejemplo n.º 5
0
 // TODO: VersionException may be replaced by BusinessException.  Providing -1 for error code temporarily.
 /// <summary>
 /// requires that this exception type specify a message and the rule that was broken upon construction
 /// </summary>
 /// <param name="message">Message for the base class</param>
 /// <param name="rule">The versioning rule that was broken</param>
 public VersionException(string message, Rule rule)
     : base(-1, message)
 {
     Rule = rule;
 }