Example #1
0
        public void CheckWithRuleTest_email_empty()
        {
            string reason = "";

            Assert.IsTrue(RuleService.CheckWithRule("", "email", out reason));
            Assert.AreEqual("", reason);
        }
Example #2
0
        public RuleRunnerGrain(
            IGrainState <State> state,
            IAppProvider appProvider,
            IEventStore eventStore,
            IEventDataFormatter eventDataFormatter,
            IRuleEventRepository ruleEventRepository,
            RuleService ruleService,
            ISemanticLog log)
        {
            Guard.NotNull(state, nameof(state));
            Guard.NotNull(appProvider, nameof(appProvider));
            Guard.NotNull(eventStore, nameof(eventStore));
            Guard.NotNull(eventDataFormatter, nameof(eventDataFormatter));
            Guard.NotNull(ruleEventRepository, nameof(ruleEventRepository));
            Guard.NotNull(ruleService, nameof(ruleService));
            Guard.NotNull(log, nameof(log));

            this.state               = state;
            this.appProvider         = appProvider;
            this.eventStore          = eventStore;
            this.eventDataFormatter  = eventDataFormatter;
            this.ruleEventRepository = ruleEventRepository;
            this.ruleService         = ruleService;
            this.log = log;
        }
 public int DeleteUser(string userId)
 {
     return(Models.Service.UserService.DeleteUser(
                RuleService.ValidateUser(
                    Models.Service.UserService.GetUserById(int.Parse(userId), this._db))
                , this._db));
 }
Example #4
0
        public void test()
        {
            //Empl empl = new Empl() { Name = "徐峰", Code = "xufeng" };
            //Dept dept = new Dept() { Name = "xx部门", Code="123" };
            //dept.Empl.Add(empl);
            //Org org = new Org();
            //org.Name = "xx公司";
            //org.Code = "abc";
            //org.Dept.Add(dept);
            //AddEntity(org);

            RuleService ruleService = new RuleService();

            Auth auth1 = new Auth()
            {
                Code = "001", Description = "test1"
            };
            Auth auth2 = new Auth()
            {
                Code = "002", Description = "test2"
            };

            Rule rule = new Rule()
            {
                Code = "001", Name = "测试员"
            };

            rule.Auth.Add(auth1);
            rule.Auth.Add(auth2);

            ruleService.AddEntity(rule);
        }
Example #5
0
        public void CheckWithRuleTest_mobile_invalid()
        {
            string reason = "";

            Assert.IsFalse(RuleService.CheckWithRule("323-2322122", "mobile", out reason));
            Assert.AreEqual("mobile", reason);
        }
Example #6
0
        public void CheckWithRuleTest_mobile_empty()
        {
            string reason = "";

            Assert.IsFalse(RuleService.CheckWithRule("", "mobile", out reason));
            Assert.AreEqual("mobile", reason);
        }
Example #7
0
        public void CheckWithRuleTest_username_normal()
        {
            string reason = "";

            Assert.IsTrue(RuleService.CheckWithRule("alanc210", "username", out reason));
            Assert.AreEqual("", reason);
        }
Example #8
0
        public void CheckWithRuleTest_mobile_normal()
        {
            string reason = "";

            Assert.IsTrue(RuleService.CheckWithRule("3232322122", "mobile", out reason));
            Assert.AreEqual("", reason);
        }
Example #9
0
        public void CheckWithRuleTest_username_outofreange()
        {
            string reason = "";

            Assert.IsFalse(RuleService.CheckWithRule("alancao3210", "username", out reason));
            Assert.AreEqual("username", reason);
        }
Example #10
0
        public void CheckWithRuleTest_username_invalidchar()
        {
            string reason = "";

            Assert.IsFalse(RuleService.CheckWithRule("alanc_210", "username", out reason));
            Assert.AreEqual("username", reason);
        }
Example #11
0
        public RuleDequeuer(RuleService ruleService, IRuleEventRepository ruleEventRepository, ISemanticLog log, IClock clock)
        {
            Guard.NotNull(ruleEventRepository, nameof(ruleEventRepository));
            Guard.NotNull(ruleService, nameof(ruleService));
            Guard.NotNull(clock, nameof(clock));
            Guard.NotNull(log, nameof(log));

            this.ruleEventRepository = ruleEventRepository;
            this.ruleService         = ruleService;

            this.clock = clock;

            this.log = log;

            requestBlock =
                new ActionBlock <IRuleEventEntity>(MakeRequestAsync,
                                                   new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 32, BoundedCapacity = 32
            });

            blockBlock =
                new TransformBlock <IRuleEventEntity, IRuleEventEntity>(x => BlockAsync(x),
                                                                        new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 1, BoundedCapacity = 1
            });

            blockBlock.LinkTo(requestBlock, new DataflowLinkOptions {
                PropagateCompletion = true
            });

            timer = new CompletionTimer(5000, QueryAsync);
        }
Example #12
0
        public void CheckWithRuleTest_username_special()
        {
            string reason = "";

            Assert.IsFalse(RuleService.CheckWithRule("admin", "username", out reason));
            Assert.AreEqual("username", reason);
        }
Example #13
0
        public void RuleServiceConstructorNoVehicleTest()
        {
            VehicleModel vehicle = null;
            var          target  = new RuleService(vehicle);

            Assert.Inconclusive("TODO: Implement code to verify target");
        }
Example #14
0
        public UnitTestRulesService()
        {
            var databaseService = Substitute.For <IDatabaseService>();

            ruleService = new RuleService(databaseService);
            databaseService
            .GetConnection();
        }
        private static void SolvePartOne(List <string> rules)
        {
            Console.WriteLine("Part I");

            var numberOfColors = new RuleService(rules).GetNumberOfOuterBags("shiny gold");

            Console.WriteLine($"Number of colors: {numberOfColors}");
        }
 public void Setup()
 {
     Service = new RuleService(
         GetService <IEnumerable <Lazy <IVendorRuleBuilder, PluginMetadata> > >(),
         GetService <IEnumerable <Lazy <IPluginRuleService, PluginMetadata> > >(),
         GetService <IRuleEngine>(),
         GetService <EFContext>()
         );
 }
Example #17
0
        public void RuleServiceConstructorNoStatusTransitionObjectTest()
        {
            var vehicle = new VehicleModel {
                VehicleID = 0
            };
            var target = new RuleService(vehicle);

            Assert.Inconclusive("TODO: Implement code to verify target");
        }
Example #18
0
        public async void GetBadgeRules_should_return_all_BadgesRules()
        {
            var mockRules  = new Mock <IPlatformRuleRepository>();
            var mockRules1 = new Mock <IBadgeRulesRepository>();

            mockRules1.Setup(c => c.GetAllBadgeRules()).ReturnsAsync(BadgeRules);
            var ruleService = new RuleService(mockRules.Object, mockRules1.Object);
            var platform    = await ruleService.GetBadgeRules();

            Assert.Equal(BadgeRules, platform);
        }
Example #19
0
 public Node GetNode(Node entry)
 {
     entry.Transitions = TransitionService.Query(entry.InstanceID).Where(t => t.RelationshipID == entry.NID).ToList();
     entry.Groups      = GroupService.Query(entry.InstanceID).Where(e => e.RelationshipID == entry.NID).ToList();
     entry.Actors      = ActorService.Query(entry.InstanceID).Where(e => e.RelationshipID == entry.NID).ToList();
     entry.Actions     = ActionService.Query(entry.InstanceID).Where(e => e.RelationshipID == entry.NID).ToList();
     entry.Command     = CommandService.Query(entry.InstanceID).Where(e => e.RelationshipID == entry.NID).FirstOrDefault();
     entry.Rules       = RuleService.Query(entry.InstanceID).Where(e => e.RelationshipID == entry.NID).ToList();
     entry.Previous    = GetPrevious(entry);
     return(entry);
 }
Example #20
0
        public RuleEnqueuer(IAppProvider appProvider, IRuleEventRepository ruleEventRepository,
                            RuleService ruleService)
        {
            Guard.NotNull(appProvider, nameof(appProvider));
            Guard.NotNull(ruleEventRepository, nameof(ruleEventRepository));
            Guard.NotNull(ruleService, nameof(ruleService));

            this.appProvider = appProvider;

            this.ruleEventRepository = ruleEventRepository;
            this.ruleService         = ruleService;
        }
Example #21
0
        private static void Main(string[] args)
        {
            ///Booting Mods.
            ///
            LoadService.Setup();
            var mods = LoadService.GetListOfMods();

            var rules = RuleService.GetRules();

            File.WriteAllText("rules.json", JsonConvert.SerializeObject(rules));
            var orderedList = RuleService.OrderMods(mods);
        }
 public RulesConfigurationViewModel(RuleService ruleService, IEnumerable<IRule> registeredRules)
 {
     RegisteredRules = new ObservableCollection<IRule>(registeredRules);
     Rules = ruleService.Rules;
     Rules.CollectionChanged += (sender, args) =>
     {
         if (!Rules.Contains(SelectedRule))
         {
             SelectedRule = null;
         }
     };
 }
Example #23
0
        public void NothingHappensWithoutConfiguration()
        {
            var mockConfigRepo = new Mock <IConfigurationRepository>(MockBehavior.Strict);

            mockConfigRepo.Setup(x => x.GetByKey("sqs_notification_config")).Returns((ConfigurationItem)null);

            var service = new RuleService(mockConfigRepo.Object, null, null);

            service.ProcessMessage("json", MonitorRuleType.BounceEvent);

            mockConfigRepo.Verify(x => x.GetByKey("sqs_notification_config"), Times.Once);
        }
 public RulesConfigurationViewModel(RuleService ruleService, IEnumerable <IRule> registeredRules)
 {
     RegisteredRules          = new ObservableCollection <IRule>(registeredRules);
     Rules                    = ruleService.Rules;
     Rules.CollectionChanged += (sender, args) =>
     {
         if (!Rules.Contains(SelectedRule))
         {
             SelectedRule = null;
         }
     };
 }
Example #25
0
        public RuleServiceTests()
        {
            typeNameRegistry.Map(typeof(ContentCreated));
            typeNameRegistry.Map(typeof(WebhookAction));

            A.CallTo(() => ruleActionHandler.ActionType)
            .Returns(typeof(WebhookAction));

            A.CallTo(() => ruleTriggerHandler.TriggerType)
            .Returns(typeof(ContentChangedTrigger));

            sut = new RuleService(new[] { ruleTriggerHandler }, new[] { ruleActionHandler }, clock, typeNameRegistry);
        }
Example #26
0
        public RuleEnqueuer(
            IRuleEventRepository ruleEventRepository,
            IRuleRepository ruleRepository,
            RuleService ruleService)
        {
            Guard.NotNull(ruleEventRepository, nameof(ruleEventRepository));
            Guard.NotNull(ruleRepository, nameof(ruleRepository));
            Guard.NotNull(ruleService, nameof(ruleService));

            this.ruleEventRepository = ruleEventRepository;
            this.ruleRepository      = ruleRepository;
            this.ruleService         = ruleService;
        }
Example #27
0
        public void Persistent(Element entry, Action <string, object> execute)
        {
            Node n = (entry as Node);

            entry.NID = Guid.NewGuid().ToString();
            execute(ResourceManage.SQL_WORKFLOW_NODE_INSERT, new { entry.NID, entry.ID, entry.Name, NodeType = n.NodeType.ToString(), entry.InstanceID, n.Cooperation });

            foreach (Transition transition in n.Transitions)
            {
                transition.RelationshipID = entry.NID;
                transition.Origin         = entry.ID;
                transition.InstanceID     = entry.InstanceID;
                TransitionService.Persistent(transition, execute);
            }

            foreach (Elements.Action a in n.Actions)
            {
                a.RelationshipID = entry.NID;
                a.InstanceID     = entry.InstanceID;
                ActionService.Persistent(a, execute);
            }

            foreach (Group r in n.Groups)
            {
                r.RelationshipID = entry.NID;
                r.InstanceID     = entry.InstanceID;
                GroupService.Persistent(r, execute);
            }

            foreach (Actor a in n.Actors)
            {
                a.RelationshipID = entry.NID;
                a.InstanceID     = entry.InstanceID;
                ActorService.Persistent(a, execute);
            }

            foreach (Elements.Rule r in n.Rules)
            {
                r.RelationshipID = entry.NID;
                r.InstanceID     = entry.InstanceID;
                RuleService.Persistent(r, execute);
            }

            if (n.Command != null)
            {
                n.Command.InstanceID     = entry.InstanceID;
                n.Command.RelationshipID = entry.NID;

                CommandService.Persistent(n.Command, execute);
            }
        }
        internal static List <Breakdown> GetAlgorithmBreakdown(List <Breakdown> noAlg)
        {
            List <Breakdown> algList = CopyFromNoAlgorithm(noAlg);

            for (int i = 0; i < algList.Count; i++)
            {
                foreach (Rule rule in RuleService.GetRules())
                {
                    rule.ApplyRule(algList, i);
                }
            }

            return(algList);
        }
 public string CreateUser(User user)
 {
     try
     {
         Models.Service.UserService.CreateUser(
             Models.Service.UserService.CheckUniqueUser(
                 RuleService.ValidateUser(user), this._db), this._db);
         return("");
     }
     catch (Models.Service.Exceptions.UserUniqueException ex)
     {
         return(ex.Message);
     }
 }
Example #30
0
        public RuleEnqueuer(IAppProvider appProvider, IMemoryCache cache, IRuleEventRepository ruleEventRepository,
                            RuleService ruleService)
        {
            Guard.NotNull(appProvider);
            Guard.NotNull(cache);
            Guard.NotNull(ruleEventRepository);
            Guard.NotNull(ruleService);

            this.appProvider = appProvider;

            this.cache = cache;

            this.ruleEventRepository = ruleEventRepository;
            this.ruleService         = ruleService;
        }
Example #31
0
        protected string GetErrorMessage(Rule rule, List <KeyValue> errorMessages)
        {
            var item = errorMessages.FirstOrDefault(s => s.Key == rule.ErrorName);

            if (item != null)
            {
                return(string.Format(item.Value, rule.ErrorFormatParams));
            }
            else if (!string.IsNullOrEmpty(RuleService.GetCommonSetting(rule.ErrorName)))
            {
                // Look up in common setting if any
                return(string.Format(RuleService.GetCommonSetting(rule.ErrorName), rule.ErrorFormatParams));
            }
            return("Somthing wrongs when finding error message");
        }