示例#1
0
        public Program(IOptions <MySettings> optionsSettings, MySettings settings, IRuleSet <MyModel> ruleset, ITransformationManager transformer)
        {
            // Data transformations
            TransformSourceData sourceData = new TransformSourceData()
            {
                Word       = "Development",
                SourceTime = DateTime.Now,
                WordCount  = 100
            };

            TransformDestinationData destinationData =
                transformer.Transform <TransformSourceData, TransformDestinationData>(sourceData);

            foreach (var timeWord in destinationData.TimeWords)
            {
                Console.WriteLine("Time word: {0}", timeWord);
            }

            // Rule validations
            var model1 = new MyModel();
            var model2 = new MyModel
            {
                Name   = "brazil",
                Number = 34
            };

            var result1 = ruleset.Check(model1);
            var result2 = ruleset.ByDefaultCategory().Check(model1);
            var result3 = ruleset.ByCategory("critical").Check(model1);
            var result4 = ruleset.ByCode("RN-001").Check(model1);
            var result5 = ruleset.ByCode(new[] { "RN-002", "RN-004" }).Check(model1);
            var result6 = ruleset.ByDefaultCategory().Check(model2);
            var result7 = ruleset.ByCategory("critical").Check(model2);

            Assert(result1 != null, "result != null");
            Assert(!result1.IsSuccess, "!result.IsSuccess");
            Assert(result1.Unconformities != null, "result.Unconformities != null");
            Assert(result1.Unconformities.Count == 4, "result.Unconformities.Count == 4");
            Assert(string.Join(" ", result2.Unconformities.Keys) == "RN-001 RN-002",
                   "RN-001 RN-002");
            Assert(string.Join(" ", result3.Unconformities.Keys) == "RN-003 RN-004",
                   "RN-003 RN-004");
            Assert(string.Join(" ", result4.Unconformities.Keys) == "RN-001", "RN-001");
            Assert(string.Join(" ", result5.Unconformities.Keys) == "RN-002 RN-004",
                   "RN-002 RN-004");
            Assert(result6.IsSuccess, "result6.IsSuccess");
            Assert(!result7.IsSuccess, "!result7.IsSuccess");
            Assert(string.Join(" ", result7.Unconformities.Keys) == "RN-003 RN-004",
                   "RN-003 RN-004 (result7)");
        }
        public async Task NotifyAsync(TEnum type, object body, Parameters parameters = null)
        {
            Checker.NotNullArgument(type, nameof(type));

            parameters = parameters ?? new Parameters();

            var message  = new NotificationMessage <TEnum>(type, body, parameters);
            var ruleCode = type.GetTag(CustomIdKey) ?? type.ToString();

            // TODO: O que fazer com exceptionMessageTemplate aqui?
            await _ruleSet.ByCode(ruleCode).EnsureAsync(message);

            foreach (var dispatcher in _dispatchers)
            {
                await dispatcher.DispatchAsync(message);
            }
        }