Exemplo n.º 1
0
 public static IEnumerable <object[]> GreaterOrEqualTo_Should_CollectError_Data()
 {
     return(RulesHelper.GetSetsCompilation(
                NumberDataHelper.GreaterOrEqualTo_Unsigned(_convert),
                NumberDataHelper.GreaterOrEqualTo_Signed(_convert),
                NumberDataHelper.GreaterOrEqualTo_Limits(short.MinValue, short.MaxValue, 1)
                ));
 }
Exemplo n.º 2
0
 public static IEnumerable <object[]> Between_Should_CollectError_Data()
 {
     return(RulesHelper.GetSetsCompilation(
                NumberDataHelper.Between_Unsigned(_convert),
                NumberDataHelper.Between_Signed(_convert),
                NumberDataHelper.Between_Limits(long.MinValue, long.MaxValue, 1)
                ));
 }
Exemplo n.º 3
0
 public static IEnumerable <object[]> NonPositive_Should_CollectError_Data()
 {
     return(RulesHelper.GetTestDataCombined(
                NumbersTestData.NonPositive_Unsigned(Convert),
                NumbersTestData.NonPositive_Signed(Convert),
                new[] { new object[] { 0.000001F, false } },
                new[] { new object[] { -0.000001F, true } }));
 }
Exemplo n.º 4
0
 public static IEnumerable <object[]> GreaterThan_Should_CollectError_Data()
 {
     return(RulesHelper.GetSetsCompilation(
                NumberDataHelper.GreaterThan_Unsigned(_convert),
                NumberDataHelper.GreaterThan_Signed(_convert),
                NumberDataHelper.GreaterThan_Limits(decimal.MinValue, decimal.MaxValue, 1)
                ));
 }
        public void ToQualityProfile_WhenRuleSetNull_ReturnsNull()
        {
            // Arrange & Act
            var result = RulesHelper.ToQualityProfile(null, Language.Unknown);

            // Assert
            result.Should().BeNull();
        }
Exemplo n.º 6
0
        private void SetDataSource()
        {
            var rulesDtos     = RulesHelper.GetRulesDtos();
            var bindingSource = new BindingSource();

            bindingSource.DataSource = rulesDtos;
            dataGridView1.DataSource = bindingSource;
        }
        public void ToRuleSet_WhenRoslynExportProfileResponseNull_ReturnsNull()
        {
            // Arrange & Act
            var result = RulesHelper.ToRuleSet(null);

            // Assert
            result.Should().BeNull();
        }
Exemplo n.º 8
0
 public static IEnumerable <object[]> Between_Should_CollectError_Data()
 {
     return(RulesHelper.GetTestDataCombined(
                NumbersTestData.Between_Unsigned(Convert),
                NumbersTestData.Between_Signed(Convert),
                NumbersTestData.Between_Limits(float.MinValue, float.MaxValue, 0),
                new[] { new object[] { 0.999999F, 1, 1.000001F, true } },
                new[] { new object[] { 0.999999F, 0.999999F, 1.000001F, false } },
                new[] { new object[] { 0.999999F, 1.000001F, 1.000001F, false } }));
 }
        private void Window_Closed(object sender, EventArgs e)
        {
            if (App.RulesTreeView != null)
            {
                App.RulesTreeView.PromptChangesNotSaved();
            }

            RulesHelper.DeleteWorkingTempFile();
            App.Current.Shutdown();
        }
Exemplo n.º 10
0
 public static IEnumerable <object[]> NotEqualTo_Should_CollectError_Data()
 {
     return(RulesHelper.GetTestDataCombined(
                NumbersTestData.NotEqualTo_Unsigned(Convert),
                NumbersTestData.NotEqualTo_Signed(Convert),
                NumbersTestData.NotEqualTo_Limits(double.MinValue, double.MaxValue, 0),
                new[] { new object[] { 0.999999D, 0D, true } },
                new[] { new object[] { 1.000001D, 0D, true } },
                new[] { new object[] { 1.123456D, 1.123456D, false } }));
 }
Exemplo n.º 11
0
        public void InitialState_TestingValidatedCommand_SuccessResultReplied()
        {
            var aggregateId = TestAggregateId.New;
            var commandId   = SourceId.New;
            var command     = new ValidatedCommand(aggregateId, true).WithSourceId(commandId);

            var result = RulesHelper.ProcessRules(command);

            result.Should().NotBeNull().And.Match <ValidationResult>(r => r.IsValid);
        }
Exemplo n.º 12
0
 public static IEnumerable <object[]> Between_Should_CollectError_Data()
 {
     return(RulesHelper.GetSetsCompilation(
                NumberDataHelper.Between_Signed(_convert),
                NumberDataHelper.Between_Unsigned(_convert),
                NumberDataHelper.Between_Limits(double.MinValue, double.MaxValue, 0),
                new[] { new object[] { 0.999999d, 1, 1.000001d, true } },
                new[] { new object[] { 0.999999d, 0.999999d, 1.000001d, false } },
                new[] { new object[] { 0.999999d, 1.000001d, 1.000001d, false } }
                ));
 }
Exemplo n.º 13
0
 public static IEnumerable <object[]> NotCloseTo_MemberData()
 {
     return(RulesHelper.GetSetsCompilation(
                NumberDataHelper.NotEqualTo_Signed(_convert),
                NumberDataHelper.NotEqualTo_Unsigned(_convert),
                NumberDataHelper.NotEqualTo_Limits(double.MinValue, double.MaxValue, 0),
                new[] { new object[] { 0.999999d, 0d, true } },
                new[] { new object[] { 1.000001d, 0d, true } },
                new[] { new object[] { 1.123456d, 1.123456d, false } }
                ));
 }
Exemplo n.º 14
0
        public Map Solve(Map map)
        {
            var cell     = map.Cells[0][0];
            var dfsStack = new Stack <CellMapPair>();

            dfsStack.Push(new CellMapPair(cell, map));

            while (dfsStack.Any())
            {
                var cellMapPair = dfsStack.Pop();
                var currentMap  = cellMapPair.Map;
                var currentCell = cellMapPair.Cell;
                if (currentCell.IsSolved)
                {
                    if (currentCell.IsLastCell)
                    {
                        return(currentMap);
                    }

                    var nextCoordinate = currentCell.Coordinate.GetNextCoordinate();
                    dfsStack.Push(new CellMapPair(currentMap.Cells[nextCoordinate.Row][nextCoordinate.Column], currentMap));
                    continue;
                }

                var candidates = currentCell.Candidates.Any() ? currentCell.Candidates : new List <int> {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                };
                foreach (var candidate in candidates)
                {
                    if (RulesHelper.ViolatesRules(candidate, currentMap, currentCell))
                    {
                        continue;
                    }

                    var candidateMap  = currentMap.Clone();
                    var candidateCell = currentCell.Clone();
                    candidateCell.Number = candidate;
                    candidateMap.Cells[candidateCell.Coordinate.Row][candidateCell.Coordinate.Column] = candidateCell;
                    if (currentCell.IsLastCell)
                    {
                        return(candidateMap);
                    }

                    var nextCoordinate = currentCell.Coordinate.GetNextCoordinate();
                    dfsStack.Push(new CellMapPair(candidateMap.Cells[nextCoordinate.Row][nextCoordinate.Column], candidateMap));

                    //Console.Clear();
                    //Console.WriteLine(candidateMap);
                    //Thread.Sleep(50);
                }
            }

            return(map);
        }
        public void ToRuleSet_DumpsContentToRuleSetFileAndLoadsIt()
        {
            // Arrange
            var ruleset = TestRuleSetHelper.CreateTestRuleSet(numRules: 10);
            var roslynProfileExporter = RoslynExportProfileHelper.CreateExport(ruleset);

            // Act
            var result = RulesHelper.ToRuleSet(roslynProfileExporter);

            // Assert
            TestRuleSetHelper.RuleSetToXml(result).Should().Be(TestRuleSetHelper.RuleSetToXml(ruleset));
        }
Exemplo n.º 16
0
 public static IEnumerable <object[]> NonZero_WithTolerance_Should_CollectError_MemberData()
 {
     return(RulesHelper.GetTestDataCombined(
                new[] { new object[] { 0.000100F, 0.0000001F, true } },
                new[] { new object[] { 0.000100F, 0.000001F, true } },
                new[] { new object[] { 0.000100F, 0.00001F, true } },
                new[] { new object[] { 0.000100F, 0.0001F, true } },
                new[] { new object[] { 0.000100F, 0.001F, false } },
                new[] { new object[] { 0.000100F, 0.01F, false } },
                new[] { new object[] { 0.000100F, 0.1F, false } },
                new[] { new object[] { 0.000100F, 1F, false } }));
 }
Exemplo n.º 17
0
 public static IEnumerable <object[]> EqualTo_WithTolerance_Should_CollectError_MemberData()
 {
     return(RulesHelper.GetTestDataCombined(
                new[] { new object[] { 1.000100D, 1.000199D, 0.0000001D, false } },
                new[] { new object[] { 1.000100D, 1.000199D, 0.000001D, false } },
                new[] { new object[] { 1.000100D, 1.000199D, 0.00001D, false } },
                new[] { new object[] { 1.000100D, 1.000199D, 0.0001D, true } },
                new[] { new object[] { 1.000100D, 1.000199D, 0.001D, true } },
                new[] { new object[] { 1.000100D, 1.000199D, 0.01D, true } },
                new[] { new object[] { 1.000100D, 1.000199D, 0.1D, true } },
                new[] { new object[] { 1.000100D, 1.000199D, 1D, true } }));
 }
        public RulesTreeView()
        {
            InitializeComponent();

            RulesHelper.CreateWorkableTempFile();

            _tracker.DataChanged      += new RulesChangeTracker.DataChangeHandler(_tracker_DataChanged);
            RulesHelper.DataCommitted += new RulesHelper.ChangesCommittedHandler(_tracker_DataCommitted);

            InitTreeData();

            treeRules.ContextMenu = treeRules.Resources["NodeContext"] as System.Windows.Controls.ContextMenu;
        }
        public void ToQualityProfile_SelectRulesNotMarkedAsNone()
        {
            // Arrange
            var ruleset           = TestRuleSetHelper.CreateTestRuleSet(numRules: 5);
            var nonNoneRulesCount = ruleset.Rules.Count(x => x.Action != RuleAction.None);

            // Act
            var result = RulesHelper.ToQualityProfile(ruleset, Language.CSharp);

            // Assert
            result.Language.Should().Be(Language.CSharp);
            result.Rules.Should().HaveCount(nonNoneRulesCount);
        }
Exemplo n.º 20
0
 public static IEnumerable <object[]> NotCloseTo_WithTolerance_MemberData()
 {
     return(RulesHelper.GetSetsCompilation(
                new[] { new object[] { 1.000100d, 1.000199d, 0.0000001d, true } },
                new[] { new object[] { 1.000100d, 1.000199d, 0.000001d, true } },
                new[] { new object[] { 1.000100d, 1.000199d, 0.00001d, true } },
                new[] { new object[] { 1.000100d, 1.000199d, 0.0001d, false } },
                new[] { new object[] { 1.000100d, 1.000199d, 0.001d, false } },
                new[] { new object[] { 1.000100d, 1.000199d, 0.01d, false } },
                new[] { new object[] { 1.000100d, 1.000199d, 0.1d, false } },
                new[] { new object[] { 1.000100d, 1.000199d, 1d, false } }
                ));
 }
Exemplo n.º 21
0
        public string Apply(int i)
        {
            var message = string.Empty;

            foreach (var fooBarQix in RulesHelper.GetFooBarQixKeys())
            {
                if (i % fooBarQix == 0)
                {
                    message += RulesHelper.GetFooBarQix(fooBarQix);
                }
            }
            return(message);
        }
        private void InitTreeData()
        {
            this.treeRules.DataContext = null;
            _rootNode = new ObservableCollection <RootNode>();
            _rootNode.Add(
                new RootNode
            {
                Name = "Business Rules"
            });

            _rootNode[0].Nodes = RulesHelper.GetRulesHierarchy();

            this.treeRules.DataContext = _rootNode;
        }
        private void Refresh()
        {
            List <BusinessRuleComponentVO> list = RulesHelper.GetComponentList();

            if (_isSelection)
            {
                //Only show parent components.
                list = (from l in list
                        where l.ParentId == Guid.Empty
                        select l).ToList();
            }

            lvComponents.ItemsSource = list;
        }
        /// <summary>
        /// Saves the tracking changes.
        /// </summary>
        /// <returns>Succesful save or not.</returns>
        public bool SaveChangesToWorkingFile()
        {
            try
            {
                RulesHelper.SaveRules(_changedRules != null ? _changedRules.ToList() : null,
                                      _changedComponents != null? _changedComponents.ToList() : null);

                this.ClearChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error trying to save: " + ex.Message
                                + Environment.NewLine + "Stack trace: " + ex.StackTrace);
                return(false);
            }
            return(true);
        }
        public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
            ViewHolderExpandableRule vh = holder as ViewHolderExpandableRule;

            vh.IsRecyclable = false;
            vh.ExpandableLayout.SetInRecyclerView(true);
            vh.Name.Text = ruleSet[position].Name;
            bool isSubCategory = RulesHelper.HasTwoSubLevels(ruleSet[position].ChildRules);

            if (isSubCategory)
            {
                vh.Icon.SetImageResource(Resource.Drawable.arrow_expand);
                SetUpInnerRecyclerView(vh.InnerRecyclerView, ruleSet[position].ChildRules);
            }
            else
            {
                vh.Icon.SetImageResource(Resource.Drawable.arrow_advance);
            }

            if (vh.ClickHandler != null)
            {
                vh.View.Click -= vh.ClickHandler;
            }

            vh.ClickHandler = new EventHandler((sender, e) => {
                if (isSubCategory)
                {
                    if (vh.ExpandableLayout.Expanded)
                    {
                        vh.Icon.SetImageResource(Resource.Drawable.arrow_expand);
                    }
                    else
                    {
                        vh.Icon.SetImageResource(Resource.Drawable.arrow_collapse);
                    }
                    vh.ExpandableLayout.Toggle();
                }
                else
                {
                    var activity = parent.Activity as MainActivity;
                    activity.LoadRulesSubsectionsFragment(ruleSet[position]);
                }
            });
            vh.View.Click += vh.ClickHandler;
        }
Exemplo n.º 26
0
        private List <int> FindCandidates(Map map, Cell cell)
        {
            var possibleCandidates = cell.Candidates.Any() ? cell.Candidates : new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            var candidates = new List <int>();

            foreach (var candidate in possibleCandidates)
            {
                if (RulesHelper.ViolatesRules(candidate, map, cell))
                {
                    continue;
                }

                candidates.Add(candidate);
            }

            return(candidates);
        }
Exemplo n.º 27
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            SetContentView(Resource.Layout.activity_main);

            SupportToolbar toolbar = FindViewById <SupportToolbar>(Resource.Id.mainToolbar);

            SetSupportActionBar(toolbar);
            SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.ic_menu);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);

            _drawerLayout   = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);
            _navigationView = FindViewById <NavigationView>(Resource.Id.nav_view);

            if (_navigationView != null)
            {
                SetupDrawerContent(_navigationView);
            }

            var projectName      = savedInstanceState?.GetString("projectName");
            var previousMenuItem = savedInstanceState?.GetInt("menuItem");

            if (projectName != null)
            {
                CurrentProject = ProjectsLogic.DownloadProjects().Find(p => p.Name == projectName);
                CurrentProject.ProjectRules = RulesHelper.DownloadRules(Assets);
                ActivateProjectSubmenu(CurrentProject);
            }

            if (previousMenuItem != null && _navigationView != null)
            {
                _previousMenuItem = _navigationView.Menu.FindItem((int)previousMenuItem);
                _previousMenuItem.SetChecked(true);
            }

            _searchQuery = savedInstanceState?.GetString("searchQuery") ?? string.Empty;

            base.OnCreate(savedInstanceState);
            if (savedInstanceState == null)
            {
                LoadProjectsListFragment();
            }
        }
Exemplo n.º 28
0
        public string Apply(int i)
        {
            var message = string.Empty;

            foreach (var numberChar in i.ToString())
            {
                foreach (var fooBarQix in RulesHelper.GetFooBarQixKeys())
                {
                    if (numberChar.Equals(fooBarQix.ToString()[0]))
                    {
                        message += RulesHelper.GetFooBarQix(fooBarQix);
                    }
                }
                if (numberChar.Equals('0'))
                {
                    message += "*";
                }
            }
            return(message);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            var rulesDtos      = RulesHelper.GetRulesDtos();
            var rulesForExport = string.Empty;

            foreach (var rulesDto in rulesDtos)
            {
                var csvLine = string.Empty;
                csvLine        += rulesDto.FindWhat + ",";
                csvLine        += rulesDto.ReplaceWith + ",";
                csvLine        += rulesDto.FileName + ",";
                csvLine        += rulesDto.ProjectName + ",";
                csvLine        += rulesDto.SolutionName + ",";
                csvLine        += rulesDto.Enabled + ",";
                csvLine        += rulesDto.CaseSensitive + ",";
                csvLine        += rulesDto.Comments + Environment.NewLine;
                rulesForExport += csvLine;
            }

            ExportRules(rulesForExport);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Begin site method - call prior to getParameters
        /// </summary>
        /// <param name="caller">Calling class object</param>
        /// <param name="siteId">SiteId specifier object</param>
        /// <param name="ruleIds">List of Business rule strings</param>
        /// <param name="rules">List of BusinessRuleVO objects - Output param</param>
        /// <returns>PawnRulesSystemReturnCode</returns>
        public PawnRulesSystemReturnCode beginSite(object caller, SiteId siteId, List <string> ruleIds, out Dictionary <string, BusinessRuleVO> rules)
        {
            rules = new Dictionary <string, BusinessRuleVO>();

            //Validate input
            if (caller == null || CollectionUtilities.isEmpty(ruleIds))
            {
                return
                    (new PawnRulesSystemReturnCode(
                         PawnRulesSystemReturnCode.Code.ERROR,
                         "Input values to beginSite are invalid."));
            }
            //Check if this object is already using the pawn rules system
            if (this.beginBlockRegistry.ContainsKey(caller))
            {
                PairType <SiteId, bool> curSiteBegin = this.beginBlockRegistry[caller];
                if (curSiteBegin.Right)
                {
                    return
                        (new PawnRulesSystemReturnCode(
                             PawnRulesSystemReturnCode.Code.WARNING,
                             "Already in an active begin block for this site and this caller parent object."));
                }
                curSiteBegin.Right = true;
                curSiteBegin.Left  = siteId;
            }
            else
            {
                this.beginBlockRegistry.Add(caller, new PairType <SiteId, bool>(siteId, true));
            }

            //Set site id
            this.currentSite = siteId;
            //Change last parameter to true if you want to save the rules file to the disk after it is loaded
            //into the rules engine data structure
            //rules = RulesHelper.BuildBusinessRules(siteId, true);
            rules = RulesHelper.BuildBusinessRules(siteId);

            return(new PawnRulesSystemReturnCode(PawnRulesSystemReturnCode.Code.SUCCESS));
        }