Esempio n. 1
0
        public void VerifyOneWay()
        {
            var rule = new MonitorRule
            {
                JsonMatcher = "json",
                SesMessage  = "ses",
                Regex       = "regex",
                Name        = "name",
                Id          = 1
            };

            var created = rule.Create();

            Assert.Equal(created.JsonMatcher, rule.JsonMatcher);
            Assert.Equal(created.Regex, rule.Regex);
            Assert.Equal(created.SesMessage, rule.SesMessage);
            Assert.Equal(created.Name, rule.Name);
            Assert.Equal(created.Id, rule.Id);
        }
        public IActionResult Post([FromBody] MonitorRule rule)
        {
            if (rule == null ||
                string.IsNullOrEmpty(rule.Regex) ||
                string.IsNullOrEmpty(rule.JsonMatcher) ||
                string.IsNullOrEmpty(rule.Name))
            {
                return(BadRequest("Invalid rule specified"));
            }


            if (!Enum.TryParse <SesMessageTypes>(rule.SesMessage, out _))
            {
                return(BadRequest("Invalid ses message"));
            }

            var dbRule = rule.Create();

            _monitorRuleRepository.Save(dbRule);

            return(Ok(dbRule.Create()));
        }