示例#1
0
        private void btSave_Click(object sender, EventArgs e)
        {
            List <MatchingRule> addRules    = new List <MatchingRule>();
            List <MatchingRule> removeRules = new List <MatchingRule>();

            foreach (ListViewItem lvItem in lvRules.Items)
            {
                if (!_rules.Any(item => item.Rule == lvItem.SubItems[1].Text))
                {
                    continue;
                }

                MatchingRule rule = _rules.First(item => item.Rule == lvItem.SubItems[1].Text);

                if (((RuleState)lvItem.Tag) == RuleState.Added)
                {
                    addRules.Add(rule);
                }
                else if (((RuleState)lvItem.Tag) == RuleState.Removed)
                {
                    removeRules.Add(rule);
                }
            }

            _processor.AddRules(addRules);
            _processor.RemoveRules(removeRules);
            ReadRules();

            _hasChanges    = false;
            btStart.Text   = "Get rules";
            btSave.Enabled = false;
            EnableControls(true);
        }
        public void MatchShouldThrowWhenTransactionIsNull()
        {
            MatchingRule subject = Arrange();

            subject.Match(null);
            Assert.Fail();
        }
        public void AnObjectIsNotEqualWithNull()
        {
            MatchingRule subject = Arrange();

            Assert.IsFalse(subject.Equals(null));
            Assert.IsTrue(subject != null);
        }
        public void TwoObjectsReferringToSameAreEqual()
        {
            MatchingRule subject  = Arrange();
            MatchingRule subject2 = subject;

            Assert.IsTrue(subject.Equals(subject2));
            Assert.IsTrue(subject == subject2);
            Assert.IsTrue(subject.GetHashCode() == subject2.GetHashCode());
        }
        public void RulesWithDifferentIdAreConsideredNotEqual()
        {
            MatchingRule subject  = Arrange();
            MatchingRule subject2 = Arrange();

            Assert.IsFalse(subject.Equals(subject2));
            Assert.IsTrue(subject != subject2);
            Assert.IsTrue(subject.GetHashCode() != subject2.GetHashCode());
        }
        public void RulesWithSameIdAreConsideredEqual()
        {
            MatchingRule subject  = Arrange();
            MatchingRule subject2 = Arrange();

            subject2.RuleId = subject.RuleId;
            Assert.IsTrue(subject.Equals(subject2));
            Assert.IsTrue(subject == subject2);
            Assert.IsTrue(subject.GetHashCode() == subject2.GetHashCode());
        }
        public void MatchShouldSetLastMatchWhenMatchIsMade()
        {
            MatchingRule subject = Arrange();

            subject.Description = "Testing Description";
            subject.LastMatch   = DateTime.MinValue;
            subject.Match(new Transaction {
                Description = "Testing Description"
            });
            Assert.IsTrue(subject.LastMatch > DateTime.MinValue);
        }
        public void TwoObjectsReferringToSameAreEqual2()
        {
            MatchingRule subject  = Arrange();
            object       subject2 = subject;

            Assert.IsTrue(subject.Equals(subject2));
#pragma warning disable 252,253
            Assert.IsTrue(subject == subject2);
#pragma warning restore 252,253
            Assert.IsTrue(subject.GetHashCode() == subject2.GetHashCode());
        }
示例#9
0
 public bool ContainsMatch <TExpected, TActual>(MatchingRule rule, TExpected expected, IEnumerable <TActual> actuals)
 {
     foreach (var actual in actuals)
     {
         if (IsMatch(rule, expected, actual))
         {
             return(true);
         }
     }
     return(false);
 }
        public void MatchShouldSetMatchCountWhenMatchIsMade()
        {
            MatchingRule subject = Arrange();

            subject.Description = "Testing Description";
            subject.MatchCount  = 1;
            subject.Match(new Transaction {
                Description = "Testing Description"
            });
            Assert.AreEqual(2, subject.MatchCount);
        }
示例#11
0
        private void CreateFissureAlert(MatchingRule matchingRule)
        {
            Alerts.Add(new FissureAlert(
                           (MissionType)((ComboItem)fissureMissionType.SelectedItem).Member,
                           (FissureTier)((ComboItem)fissureTier.SelectedItem).Member
                           )
            {
                MatchingRule = matchingRule
            });

            PopulateAlerts();
        }
        public void AndMatchShouldNotMatchOnDescription1()
        {
            MatchingRule subject = Arrange();

            subject.Description = "Testing Description";

            bool success = subject.Match(new Transaction {
                Description = "xxxTesting Description"
            });

            Assert.IsFalse(success);
        }
        public void AndMatchShouldMatchOnTransacionType()
        {
            MatchingRule subject = Arrange();

            subject.Description     = "Testing Description";
            subject.TransactionType = "Foo";

            bool success = subject.Match(new Transaction {
                Description = "Testing Description", TransactionType = new NamedTransaction("Foo")
            });

            Assert.IsTrue(success);
        }
        /// <summary>
        /// Add an additional field to the entity.
        /// </summary>
        /// <param name="entity">Entity where the field is added.</param>
        /// <param name="name">Name of the additional field.</param>
        /// <param name="displayName">Display name of the field.</param>
        /// <param name="value">Value of the field.</param>
        /// <param name="matchingRule">Matching rule of the field.</param>
        /// <returns>The entity where the field was added.</returns>
        public static Entity AddAdditionalField(
            this Entity entity,
            string name,
            string displayName        = null,
            string value              = null,
            MatchingRule matchingRule = MatchingRule.Loose
            )
        {
            var additionalField = new Entity.AdditionalField(name, displayName, value, matchingRule);

            entity.AdditionalFields.Add(additionalField);
            return(entity);
        }
        public void AndMatchShouldFailWhenBucketIsInactive()
        {
            MatchingRule subject = Arrange();

            subject.Description   = "Testing Description";
            subject.Bucket.Active = false;

            bool success = subject.Match(new Transaction {
                Description = "Testing Description"
            });

            Assert.IsFalse(success);
        }
        public void AndMatchShouldMatchOnAmountAndDescription()
        {
            MatchingRule subject = Arrange();

            subject.Description = "Testing Description";
            subject.Amount      = 11.01M;

            bool success = subject.Match(new Transaction {
                Description = "Testing Description", Amount = 11.01M
            });

            Assert.IsTrue(success);
        }
示例#17
0
        private void AddToList(MatchingRule rule)
        {
            if (!(rule is SingleUseMatchingRule))
            {
                Rules.Add(rule);
                RulesGroupedByBucket.Single(g => g.Bucket == rule.Bucket).Rules.Add(rule);
                EventHandler <MatchingRuleEventArgs> handler = RuleAdded;
                handler?.Invoke(this, new MatchingRuleEventArgs {
                    Rule = rule
                });
            }

            this.applicationDatabaseService.NotifyOfChange(ApplicationDataType.MatchingRules);
        }
        public void OrMatchShouldMatchOnDescription3()
        {
            MatchingRule subject = Arrange();

            subject.And         = false;
            subject.Description = "Testing Description";
            subject.Reference1  = "Ref1";

            bool success = subject.Match(new Transaction {
                Description = "Testing Description"
            });

            Assert.IsTrue(success);
        }
        public void AndMatchShouldMatchOnReferences()
        {
            MatchingRule subject = Arrange();

            subject.Reference1 = "Testing 1";
            subject.Reference2 = "Testing 2";
            subject.Reference3 = "Testing 3";

            bool success = subject.Match(new Transaction {
                Reference1 = "Testing 1", Reference2 = "Testing 2", Reference3 = "Testing 3"
            });

            Assert.IsTrue(success);
        }
示例#20
0
        public bool IsMatch(MatchingRule rule, object expected, object actual)
        {
            if (rule.Match == "type")
            {
                return(TypeMatch(expected, actual));
            }

            if (rule.Match == "regex")
            {
                return(RegExMatch(actual, rule.Regex));
            }

            return(expected.Equals(actual));
        }
示例#21
0
 public void TestInitialise()
 {
     TestData = new MatchingRule(new BucketBucketRepoAlwaysFind())
     {
         Amount          = 123.45M,
         BucketCode      = "CARMTC",
         Description     = "Testing Description",
         LastMatch       = new DateTime(2014, 06, 22),
         MatchCount      = 2,
         Reference1      = "Testing Reference1",
         Reference2      = "Testing Reference2",
         Reference3      = "Testing Reference3",
         TransactionType = "Testing TransactionType"
     };
 }
示例#22
0
        private void AddRule(MatchingRule ruleToAdd)
        {
            if (ruleToAdd == null)
            {
                throw new ArgumentNullException(nameof(ruleToAdd));
            }

            if (string.IsNullOrWhiteSpace(this.rulesStorageKey))
            {
                throw new InvalidOperationException("Unable to add a matching rule at this time, the service has not yet loaded a matching rule set.");
            }

            // Make sure no rule already exists with this id:
            if (MatchingRules.Any(r => r.RuleId == ruleToAdd.RuleId))
            {
                throw new DuplicateNameException($"Unable to add new matching rule: Rule ID {ruleToAdd.RuleId} already exists in the collection.");
            }

            // Check to see if an existing group object for the desired bucket already exists.
            var existingGroup = MatchingRulesGroupedByBucket.FirstOrDefault(group => group.Bucket == ruleToAdd.Bucket);

            if (existingGroup == null)
            {
                // Create a new group object for this bucket.
                var addNewGroup = new RulesGroupedByBucket(ruleToAdd.Bucket, new[] { ruleToAdd });
                this.matchingRulesGroupedByBucket.Add(addNewGroup);
                this.matchingRules.Add(ruleToAdd);
            }
            else
            {
                // Add to existing group object.
                if (existingGroup.Rules.Contains(ruleToAdd))
                {
                    this.logger.LogWarning(l => "Attempt to add new rule failed. Rule already exists in Grouped collection. " + ruleToAdd);
                    return;
                }
                existingGroup.Rules.Add(ruleToAdd);
                if (MatchingRules.Contains(ruleToAdd))
                {
                    this.logger.LogWarning(l => "Attempt to add new rule failed. Rule already exists in main collection. " + ruleToAdd);
                    return;
                }

                this.matchingRules.Add(ruleToAdd);
            }

            this.logger.LogInfo(_ => "Matching Rule Added: " + ruleToAdd);
        }
示例#23
0
            /// <summary>
            ///     Creates an additional field to be used by an entity for additional information.
            ///     These fields are passed to the next transformation as STDIN parameters.
            /// </summary>
            /// <param name="name">Name of the additional field (mandatory).</param>
            /// <param name="displayName">The name which will be displayed in the UI field.</param>
            /// <param name="value">The value of the field.</param>
            /// <param name="matchingRule">
            ///     "strict" or "loose". If "strict" is chosen, the attribute will be used to distinguish two entities with the same
            ///     attribute value. If "loose" is used, entities with the same name but different attribute values will be considered
            ///     as equal entities.
            /// </param>
            public AdditionalField(
                string name,
                string displayName        = null,
                string value              = null,
                MatchingRule matchingRule = TransNet.MatchingRule.Loose
                )
            {
                Name         = name;
                DisplayName  = displayName;
                Value        = value;
                MatchingRule = matchingRule.ToString().ToLower();

                if (name == null)
                {
                    throw new ArgumentNullException(nameof(name), "Name is mandatory and cannot be null.");
                }
            }
示例#24
0
        private void btRuleRemove_Click(object sender, EventArgs ea)
        {
            if (string.IsNullOrEmpty(TbRuleQuery.Text))
            {
                MessageBox.Show("You try to remove an empty rule that isn't allowed action.", "Remove rule", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (!_rules.Any(item => item.Rule.Equals(TbRuleQuery.Text)))
            {
                MessageBox.Show("You try to remove not existing item. Select another one and try again.", "Remove rule", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                if (lvRules.SelectedItems.Count != 0)
                {
                    foreach (ListViewItem selected in lvRules.SelectedItems)
                    {
                        if (_rules.Any(item => item.Rule == selected.SubItems[1].Text))
                        {
                            MatchingRule rule = _rules.First(item => item.Rule == selected.SubItems[1].Text);

                            if (((RuleState)selected.Tag) == RuleState.Added)
                            {
                                lvRules.Items.Remove(selected);
                            }
                            else
                            {
                                selected.BackColor = System.Drawing.Color.LightCoral;
                                selected.Tag       = RuleState.Removed;
                            }
                        }

                        if (!_hasChanges)
                        {
                            _hasChanges    = true;
                            btStart.Text   = "Cancel";
                            btSave.Enabled = true;
                        }
                    }
                }
            }
        }
示例#25
0
        public PactLogBuilder Unmatched(object expected, object actual, MatchingRule rule)
        {
            string expectationCaption;

            if (rule.Match == "regex")
            {
                expectationCaption = $"A string value matching: '{rule.Regex}'";
            }
            else if (rule.Match == "type")
            {
                expectationCaption = $"A value of a type compatible with: '{expected.GetType().Name}'";
            }
            else
            {
                expectationCaption = "";
            }

            Unmatched(expected, actual, expectationCaption);

            return(this);
        }
示例#26
0
        public bool RemoveRule(MatchingRule ruleToRemove)
        {
            if (ruleToRemove == null)
            {
                throw new ArgumentNullException(nameof(ruleToRemove));
            }

            if (string.IsNullOrWhiteSpace(this.rulesStorageKey))
            {
                throw new InvalidOperationException(
                          "Unable to remove a matching rule at this time, the service has not yet loaded a matching rule set.");
            }

            var existingGroup = MatchingRulesGroupedByBucket.FirstOrDefault(g => g.Bucket == ruleToRemove.Bucket);

            if (existingGroup == null)
            {
                return(false);
            }

            var success1    = existingGroup.Rules.Remove(ruleToRemove);
            var success2    = this.matchingRules.Remove(ruleToRemove);
            var removedRule = ruleToRemove;

            this.logger.LogInfo(_ => "Matching Rule is being Removed: " + removedRule);
            if (!success1)
            {
                this.logger.LogWarning(
                    _ => "Matching Rule was not removed successfully from the Grouped list: " + removedRule);
            }

            if (!success2)
            {
                this.logger.LogWarning(
                    _ => "Matching Rule was not removed successfully from the flat list: " + removedRule);
            }

            return(true);
        }
示例#27
0
        private void RemoveRule()
        {
            if (EditingRule)
            {
                EditingRule = false;
            }

            MatchingRule selectedRule = SelectedRule;

            if (!this.ruleService.RemoveRule(SelectedRule))
            {
                return;
            }

            this.applicationDatabaseService.NotifyOfChange(ApplicationDataType.MatchingRules);

            EventHandler <MatchingRuleEventArgs> handler = RuleRemoved;

            handler?.Invoke(selectedRule, new MatchingRuleEventArgs {
                Rule = selectedRule
            });

            SelectedRule = null;
        }
        private void OnRuleAdded(object sender, MatchingRuleEventArgs e)
        {
            MatchingRule rule     = e.Rule;
            var          flatList = (ObservableCollection <MatchingRule>) this.FlatListBox.ItemsSource;

            if (flatList.All(r => r.RuleId != rule.RuleId))
            {
                flatList.Add(rule);
            }

            var groupedList            = (ObservableCollection <RulesGroupedByBucket>) this.GroupedByListBox.ItemsSource;
            RulesGroupedByBucket group = groupedList.SingleOrDefault(g => g.Bucket == rule.Bucket);

            if (group == null)
            {
                group = new RulesGroupedByBucket(rule.Bucket, new[] { rule });
                groupedList.Add(group);
            }

            if (group.Rules.All(r => r.RuleId != rule.RuleId))
            {
                group.Rules.Add(rule);
            }
        }
 // ReSharper disable once RedundantAssignment
 partial void ModelFactory(MatchingRuleDto dto, ref MatchingRule model)
 {
     model = new MatchingRule(this.bucketRepo);
 }
示例#30
0
        private void AddToList(MatchingRule rule)
        {
            if (!(rule is SingleUseMatchingRule))
            {
                Rules.Add(rule);
                RulesGroupedByBucket.Single(g => g.Bucket == rule.Bucket).Rules.Add(rule);
                EventHandler<MatchingRuleEventArgs> handler = RuleAdded;
                handler?.Invoke(this, new MatchingRuleEventArgs { Rule = rule });
            }

            this.applicationDatabaseService.NotifyOfChange(ApplicationDataType.MatchingRules);
        }
        public bool RemoveRule(MatchingRule ruleToRemove)
        {
            if (ruleToRemove == null)
            {
                throw new ArgumentNullException(nameof(ruleToRemove));
            }

            if (string.IsNullOrWhiteSpace(this.rulesStorageKey))
            {
                throw new InvalidOperationException(
                    "Unable to remove a matching rule at this time, the service has not yet loaded a matching rule set.");
            }

            var existingGroup = MatchingRulesGroupedByBucket.FirstOrDefault(g => g.Bucket == ruleToRemove.Bucket);
            if (existingGroup == null)
            {
                return false;
            }

            var success1 = existingGroup.Rules.Remove(ruleToRemove);
            var success2 = this.matchingRules.Remove(ruleToRemove);
            var removedRule = ruleToRemove;

            this.logger.LogInfo(_ => "Matching Rule is being Removed: " + removedRule);
            if (!success1)
            {
                this.logger.LogWarning(
                    _ => "Matching Rule was not removed successfully from the Grouped list: " + removedRule);
            }

            if (!success2)
            {
                this.logger.LogWarning(
                    _ => "Matching Rule was not removed successfully from the flat list: " + removedRule);
            }

            return true;
        }
        private void AddRule(MatchingRule ruleToAdd)
        {
            if (ruleToAdd == null)
            {
                throw new ArgumentNullException(nameof(ruleToAdd));
            }

            if (string.IsNullOrWhiteSpace(this.rulesStorageKey))
            {
                throw new InvalidOperationException("Unable to add a matching rule at this time, the service has not yet loaded a matching rule set.");
            }

            // Make sure no rule already exists with this id:
            if (MatchingRules.Any(r => r.RuleId == ruleToAdd.RuleId))
            {
                throw new DuplicateNameException($"Unable to add new matching rule: Rule ID {ruleToAdd.RuleId} already exists in the collection.");
            }

            // Check to see if an existing group object for the desired bucket already exists.
            var existingGroup = MatchingRulesGroupedByBucket.FirstOrDefault(group => group.Bucket == ruleToAdd.Bucket);
            if (existingGroup == null)
            {
                // Create a new group object for this bucket.
                var addNewGroup = new RulesGroupedByBucket(ruleToAdd.Bucket, new[] { ruleToAdd });
                this.matchingRulesGroupedByBucket.Add(addNewGroup);
                this.matchingRules.Add(ruleToAdd);
            }
            else
            {
                // Add to existing group object.
                if (existingGroup.Rules.Contains(ruleToAdd))
                {
                    this.logger.LogWarning(l => "Attempt to add new rule failed. Rule already exists in Grouped collection. " + ruleToAdd);
                    return;
                }
                existingGroup.Rules.Add(ruleToAdd);
                if (MatchingRules.Contains(ruleToAdd))
                {
                    this.logger.LogWarning(l => "Attempt to add new rule failed. Rule already exists in main collection. " + ruleToAdd);
                    return;
                }

                this.matchingRules.Add(ruleToAdd);
            }

            this.logger.LogInfo(_ => "Matching Rule Added: " + ruleToAdd);
        }
示例#33
0
        private void AddToList(MatchingRule rule)
        {
            RulesGroupedByBucket existingGroup = RulesGroupedByBucket.FirstOrDefault(group => group.Bucket == rule.Bucket);
            if (existingGroup == null)
            {
                var addNewGroup = new RulesGroupedByBucket(rule.Bucket, new[] { rule });
                RulesGroupedByBucket.Add(addNewGroup);
                Rules.Add(rule);
            }
            else
            {
                existingGroup.Rules.Add(rule);
                Rules.Add(rule);
            }

            SaveRules();
            this.logger.LogInfo(() => "Matching Rule Added: " + rule);
            EventHandler<MatchingRuleEventArgs> handler = RuleAdded;
            if (handler != null)
            {
                handler(this, new MatchingRuleEventArgs { Rule = rule });
            }
        }
 public void TestInitialise()
 {
     TestData = new MatchingRule(new BucketBucketRepoAlwaysFind())
     {
         Amount = 123.45M,
         BucketCode = "CARMTC",
         Description = "Testing Description",
         LastMatch = new DateTime(2014, 06, 22),
         MatchCount = 2,
         Reference1 = "Testing Reference1",
         Reference2 = "Testing Reference2",
         Reference3 = "Testing Reference3",
         TransactionType = "Testing TransactionType"
     };
 }
 partial void ToDtoPostprocessing(ref MatchingRuleDto dto, MatchingRule model)
 {
     dto.BucketCode = model.Bucket.Code;
 }
 partial void ToModelPostprocessing(MatchingRuleDto dto, ref MatchingRule model)
 {
     model.BucketCode = dto.BucketCode;
 }
        public void CtorShouldInitialiseCreated()
        {
            MatchingRule subject = Arrange();

            Assert.AreNotEqual(DateTime.MinValue, subject.Created);
        }
        public void CtorShouldInitialiseId()
        {
            MatchingRule subject = Arrange();

            Assert.AreNotEqual(Guid.Empty, subject.RuleId);
        }