Inheritance: NotifyPropertyChangedObject
Ejemplo n.º 1
0
        public void RuleModel_DescriptionWithHyperlink_ShouldHaveInlines()
        {
            string descriptionText   = "Rule description text with [hyperlink](https://example.com).";
            ReportingDescriptor rule = new ReportingDescriptor
            {
                Id   = testRuleId,
                Name = testRuleName,
                DefaultConfiguration = new ReportingConfiguration
                {
                    Level = FailureLevel.Error,
                },
                FullDescription = new MultiformatMessageString
                {
                    Text = descriptionText
                }
            };

            RuleModel ruleModel = rule.ToRuleModel(testRuleId);

            ruleModel.Description.Should().BeEquivalentTo(descriptionText);
            ruleModel.DescriptionInlines.Should().NotBeNull();
            ruleModel.DescriptionInlines.Count.Should().Be(3);
            ruleModel.DescriptionInlines[1].GetType().Should().Be(typeof(Hyperlink));
            ruleModel.ShowPlainDescription.Should().BeFalse();
        }
Ejemplo n.º 2
0
        public static RuleModel ToRuleModel(this IRule rule, string defaultRuleId)
        {
            RuleModel model;

            if (rule == null)
            {
                model = new RuleModel()
                {
                    Id = defaultRuleId,
                };
            }
            else
            {
                model = new RuleModel()
                {
                    Id = rule.Id,
                    Name = rule.Name,
                    Category = rule.GetCategory(),
                    DefaultLevel = rule.DefaultLevel.ToString(),
                    Description = rule.FullDescription,
                    HelpUri = rule.HelpUri?.AbsoluteUri
                };
            }

            return model;
        }
Ejemplo n.º 3
0
        public void RuleModel_WithoutDefaultLevel_LevelShouldBeWarning()
        {
            ReportingDescriptor rule = new ReportingDescriptor
            {
                Id   = testRuleId,
                Name = testRuleName,
            };

            RuleModel ruleModel = rule.ToRuleModel(testRuleId);

            ruleModel.DefaultFailureLevel.Should().Be(FailureLevel.Warning);
            ruleModel.FailureLevel.Should().Be(FailureLevel.Warning);
        }
Ejemplo n.º 4
0
        public void RuleModel_WhenRuleIdIsGuid_IdShouldBeSameAsName()
        {
            string ruleId            = Guid.NewGuid().ToString();
            ReportingDescriptor rule = new ReportingDescriptor
            {
                Id   = ruleId,
                Name = testRuleName,
            };

            RuleModel ruleModel = rule.ToRuleModel(ruleId);

            ruleModel.Id.Should().BeEquivalentTo(rule.Name);
        }
Ejemplo n.º 5
0
        public void RuleModel_RuleNameIsNull()
        {
            ReportingDescriptor rule = new ReportingDescriptor
            {
                Id   = testRuleId,
                Name = null,
            };

            RuleModel ruleModel = rule.ToRuleModel(testRuleId);

            ruleModel.Id.Should().BeEquivalentTo(testRuleId);
            ruleModel.Name.Should().BeNull();
            ruleModel.DisplayName.Should().BeNull();
        }
Ejemplo n.º 6
0
        public void RuleModel_WhenRuleIdIsSameAsName_DisplayNameShouldBeNull()
        {
            ReportingDescriptor rule = new ReportingDescriptor
            {
                Id   = testRuleId,
                Name = testRuleId,
            };

            RuleModel ruleModel = rule.ToRuleModel(testRuleId);

            ruleModel.Id.Should().BeEquivalentTo(testRuleId);
            ruleModel.Name.Should().BeEquivalentTo(testRuleId);
            ruleModel.DisplayName.Should().BeNull();
        }
Ejemplo n.º 7
0
        public void RuleModel_NullRuleName_DisplayNameShouldBeNull()
        {
            ReportingDescriptor rule = new ReportingDescriptor
            {
                Id   = testRuleId,
                Name = null,
                DefaultConfiguration = new ReportingConfiguration
                {
                    Level = FailureLevel.Error,
                }
            };

            RuleModel ruleModel = rule.ToRuleModel(testRuleId);

            ruleModel.DisplayName.Should().BeNull();
        }
Ejemplo n.º 8
0
        public void RuleModel_Level_ShouldBeSameAsDefaultLevel()
        {
            ReportingDescriptor rule = new ReportingDescriptor
            {
                Id   = testRuleId,
                Name = testRuleName,
                DefaultConfiguration = new ReportingConfiguration
                {
                    Level = FailureLevel.Error,
                }
            };

            RuleModel ruleModel = rule.ToRuleModel(testRuleId);

            ruleModel.DefaultFailureLevel.Should().Be(FailureLevel.Error);
            ruleModel.FailureLevel.Should().Be(FailureLevel.Error);
        }
Ejemplo n.º 9
0
        public void RuleModel_RuleIdDoesNotEqualRuleName_DisplayName_ShouldBeRuleName()
        {
            ReportingDescriptor rule = new ReportingDescriptor
            {
                Id   = testRuleId,
                Name = testRuleName,
                DefaultConfiguration = new ReportingConfiguration
                {
                    Level = FailureLevel.Error,
                }
            };

            RuleModel ruleModel = rule.ToRuleModel(testRuleId);

            ruleModel.DisplayName.Should().NotBeNull();
            ruleModel.DisplayName.Should().BeEquivalentTo(testRuleName);
        }
Ejemplo n.º 10
0
        public void RuleModel_NullDescription_ShouldNotHaveInlines()
        {
            ReportingDescriptor rule = new ReportingDescriptor
            {
                Id   = testRuleId,
                Name = testRuleName,
                DefaultConfiguration = new ReportingConfiguration
                {
                    Level = FailureLevel.Error,
                }
            };

            RuleModel ruleModel = rule.ToRuleModel(testRuleId);

            ruleModel.Description.Should().BeNull();
            ruleModel.DescriptionInlines.Should().BeNullOrEmpty();
            ruleModel.ShowPlainDescription.Should().BeFalse();
        }
Ejemplo n.º 11
0
        public void RuleModel_PlainTextDescription_ShouldNotHaveInlines()
        {
            string plainText         = "Rule description text";
            ReportingDescriptor rule = new ReportingDescriptor
            {
                Id   = testRuleId,
                Name = testRuleName,
                DefaultConfiguration = new ReportingConfiguration
                {
                    Level = FailureLevel.Error,
                },
                FullDescription = new MultiformatMessageString
                {
                    Text = plainText
                }
            };

            RuleModel ruleModel = rule.ToRuleModel(testRuleId);

            ruleModel.Description.Should().BeEquivalentTo(plainText);
            ruleModel.DescriptionInlines.Should().BeNullOrEmpty();
            ruleModel.ShowPlainDescription.Should().BeTrue();
        }