Beispiel #1
0
        public void InvalidPlaceholders_NoInvalid_SomeValid()
        {
            var sut = new AllowedPlaceholderValidator();

            var use = $"  {Placeholder.PropertyName}, {Placeholder.PropertyNameWithSpaces}, {Placeholder.PropertyType}";

            var(isValid, invalidList) = sut.ContainsOnlyValidPlaceholders(typeof(Mapping), nameof(Mapping.Output), use);

            Assert.IsTrue(isValid);
            Assert.IsFalse(invalidList.Any());
        }
Beispiel #2
0
        public void InvalidPlaceholders_NoInvalid_NoValid()
        {
            var sut = new AllowedPlaceholderValidator();

            var use = $"for bar  blah blah blah";

            var(isValid, invalidList) = sut.ContainsOnlyValidPlaceholders(typeof(Mapping), nameof(Mapping.Output), use);

            Assert.IsTrue(isValid);
            Assert.IsFalse(invalidList.Any());
        }
        public void EnsureOnlyValidPlaceholdersInDefaultConfig()
        {
            var defSet = ConfiguredSettings.GetDefaultSettings();
            var apv    = new AllowedPlaceholderValidator();

            foreach (var profile in defSet.Profiles)
            {
                var checkResult = apv.ContainsOnlyValidPlaceholders(typeof(Profile), nameof(Profile.FallbackOutput), profile.FallbackOutput);

                if (!checkResult.isValid)
                {
                    Assert.Fail($"{nameof(Profile.FallbackOutput)} in profile '{profile.Name}' contained invalid placeholder(s): {string.Join(", ", checkResult.invalidPlaceholders)}");
                }

                checkResult = apv.ContainsOnlyValidPlaceholders(typeof(Profile), nameof(Profile.SubPropertyOutput), profile.SubPropertyOutput);

                if (!checkResult.isValid)
                {
                    Assert.Fail($"{nameof(Profile.SubPropertyOutput)} in profile '{profile.Name}' contained invalid placeholder(s): {string.Join(", ", checkResult.invalidPlaceholders)}");
                }

                checkResult = apv.ContainsOnlyValidPlaceholders(typeof(Profile), nameof(Profile.EnumMemberOutput), profile.EnumMemberOutput);

                if (!checkResult.isValid)
                {
                    Assert.Fail($"{nameof(Profile.EnumMemberOutput)} in profile '{profile.Name}' contained invalid placeholder(s): {string.Join(", ", checkResult.invalidPlaceholders)}");
                }

                foreach (var mapping in profile.Mappings)
                {
                    checkResult = apv.ContainsOnlyValidPlaceholders(typeof(Mapping), nameof(Mapping.Output), mapping.Output);

                    if (!checkResult.isValid)
                    {
                        Assert.Fail($"Mapping output in profile '{profile.Name}' contained invalid placeholder(s): {string.Join(", ", checkResult.invalidPlaceholders)}");
                    }
                }
            }
        }
Beispiel #4
0
        public void InvalidPlaceholders__OneInvalid_SomeValid()
        {
            var sut = new AllowedPlaceholderValidator();

            var invalidPlaceholder = Placeholder.EnumElement;

            var use = $"{invalidPlaceholder}, {Placeholder.PropertyName}, {Placeholder.PropertyNameWithSpaces}, {Placeholder.PropertyType}";

            var(isValid, invalidList) = sut.ContainsOnlyValidPlaceholders(typeof(Mapping), nameof(Mapping.Output), use);

            Assert.IsFalse(isValid);
            Assert.IsNotNull(invalidList);
            Assert.AreEqual(1, invalidList.Count);
            Assert.AreEqual(invalidPlaceholder, invalidList[0]);
        }
Beispiel #5
0
        public void InvalidPlaceholders_OneInvalid_NoValid()
        {
            var sut = new AllowedPlaceholderValidator();

            var invalidPlaceholder = Placeholder.EnumElement;

            var use = $"for bar {invalidPlaceholder} blah blah blah";

            var(isValid, invalidList) = sut.ContainsOnlyValidPlaceholders(typeof(Mapping), nameof(Mapping.Output), use);

            Assert.IsFalse(isValid);
            Assert.IsNotNull(invalidList);
            Assert.AreEqual(1, invalidList.Count);
            Assert.AreEqual(invalidPlaceholder, invalidList[0]);
        }
Beispiel #6
0
        public void InvalidPlaceholders_DuplicateInvalid_RepeatedInResults()
        {
            var sut = new AllowedPlaceholderValidator();

            var invalidPlaceholder = Placeholder.EnumPropName;

            var use = $"{invalidPlaceholder}, {invalidPlaceholder}, {Placeholder.PropertyName}, {Placeholder.PropertyNameWithSpaces}, {Placeholder.PropertyType}";

            var(isValid, invalidList) = sut.ContainsOnlyValidPlaceholders(typeof(Mapping), nameof(Mapping.Output), use);

            Assert.IsFalse(isValid);
            Assert.IsNotNull(invalidList);
            Assert.AreEqual(2, invalidList.Count);
            Assert.AreEqual(invalidPlaceholder, invalidList[0]);
            Assert.AreEqual(invalidPlaceholder, invalidList[1]);
        }
Beispiel #7
0
        public void InvalidPlaceholders_TwoInvalid_NoValid()
        {
            var sut = new AllowedPlaceholderValidator();

            var invalidPlaceholder1 = Placeholder.EnumElement;
            var invalidPlaceholder2 = Placeholder.EnumElementWithSpaces;

            var use = $"{invalidPlaceholder1}, {invalidPlaceholder2} ";

            var(isValid, invalidList) = sut.ContainsOnlyValidPlaceholders(typeof(Mapping), nameof(Mapping.Output), use);

            Assert.IsFalse(isValid);
            Assert.IsNotNull(invalidList);
            Assert.AreEqual(2, invalidList.Count);
            Assert.AreEqual(invalidPlaceholder1, invalidList[0]);
            Assert.AreEqual(invalidPlaceholder2, invalidList[1]);
        }
Beispiel #8
0
        public void EnsureOnlyValidPlaceholdersInDefaultConfig()
        {
            var defSet = ConfiguredSettings.GetDefaultSettings();
            var apv    = new AllowedPlaceholderValidator();

            foreach (var profile in defSet.Profiles)
            {
                var checkResult = apv.ContainsOnlyValidPlaceholders(typeof(Profile), nameof(Profile.FallbackOutput), profile.FallbackOutput);

                if (!checkResult.isValid)
                {
                    Assert.Fail($"{nameof(Profile.FallbackOutput)} in profile '{profile.Name}' contained invalid placeholder(s): {string.Join(", ", checkResult.invalidPlaceholders)}");
                }

                checkResult = apv.ContainsOnlyValidPlaceholders(typeof(Profile), nameof(Profile.SubPropertyOutput), profile.SubPropertyOutput);

                if (!checkResult.isValid)
                {
                    Assert.Fail($"{nameof(Profile.SubPropertyOutput)} in profile '{profile.Name}' contained invalid placeholder(s): {string.Join(", ", checkResult.invalidPlaceholders)}");
                }

                checkResult = apv.ContainsOnlyValidPlaceholders(typeof(Profile), nameof(Profile.EnumMemberOutput), profile.EnumMemberOutput);

                if (!checkResult.isValid)
                {
                    Assert.Fail($"{nameof(Profile.EnumMemberOutput)} in profile '{profile.Name}' contained invalid placeholder(s): {string.Join(", ", checkResult.invalidPlaceholders)}");
                }

                checkResult = apv.ContainsOnlyValidPlaceholders(typeof(ViewGenerationSettings), nameof(ViewGenerationSettings.CodePlaceholder), profile.ViewGeneration.CodePlaceholder);

                if (!checkResult.isValid)
                {
                    Assert.Fail($"{nameof(ViewGenerationSettings)}.{nameof(ViewGenerationSettings.CodePlaceholder)} in profile '{profile.Name}' contained invalid placeholder(s): {string.Join(", ", checkResult.invalidPlaceholders)}");
                }

                checkResult = apv.ContainsOnlyValidPlaceholders(typeof(ViewGenerationSettings), nameof(ViewGenerationSettings.XamlPlaceholder), profile.ViewGeneration.XamlPlaceholder);

                if (!checkResult.isValid)
                {
                    Assert.Fail($"{nameof(ViewGenerationSettings)}.{nameof(ViewGenerationSettings.XamlPlaceholder)} in profile '{profile.Name}' contained invalid placeholder(s): {string.Join(", ", checkResult.invalidPlaceholders)}");
                }

                checkResult = apv.ContainsOnlyValidPlaceholders(typeof(DatacontextSettings), nameof(DatacontextSettings.XamlPageAttribute), profile.Datacontext.XamlPageAttribute);

                if (!checkResult.isValid)
                {
                    Assert.Fail($"{nameof(DatacontextSettings)}.{nameof(DatacontextSettings.XamlPageAttribute)} in profile '{profile.Name}' contained invalid placeholder(s): {string.Join(", ", checkResult.invalidPlaceholders)}");
                }

                checkResult = apv.ContainsOnlyValidPlaceholders(typeof(DatacontextSettings), nameof(DatacontextSettings.CodeBehindPageContent), profile.Datacontext.CodeBehindPageContent);

                if (!checkResult.isValid)
                {
                    Assert.Fail($"{nameof(DatacontextSettings)}.{nameof(DatacontextSettings.CodeBehindPageContent)} in profile '{profile.Name}' contained invalid placeholder(s): {string.Join(", ", checkResult.invalidPlaceholders)}");
                }

                checkResult = apv.ContainsOnlyValidPlaceholders(typeof(DatacontextSettings), nameof(DatacontextSettings.CodeBehindConstructorContent), profile.Datacontext.CodeBehindConstructorContent);

                if (!checkResult.isValid)
                {
                    Assert.Fail($"{nameof(DatacontextSettings)}.{nameof(DatacontextSettings.CodeBehindConstructorContent)} in profile '{profile.Name}' contained invalid placeholder(s): {string.Join(", ", checkResult.invalidPlaceholders)}");
                }

                checkResult = apv.ContainsOnlyValidPlaceholders(typeof(DatacontextSettings), nameof(DatacontextSettings.DefaultCodeBehindConstructor), profile.Datacontext.DefaultCodeBehindConstructor);

                if (!checkResult.isValid)
                {
                    Assert.Fail($"{nameof(DatacontextSettings)}.{nameof(DatacontextSettings.DefaultCodeBehindConstructor)} in profile '{profile.Name}' contained invalid placeholder(s): {string.Join(", ", checkResult.invalidPlaceholders)}");
                }

                foreach (var mapping in profile.Mappings)
                {
                    checkResult = apv.ContainsOnlyValidPlaceholders(typeof(Mapping), nameof(Mapping.Output), mapping.Output);

                    if (!checkResult.isValid)
                    {
                        Assert.Fail($"Mapping output in profile '{profile.Name}' contained invalid placeholder(s): {string.Join(", ", checkResult.invalidPlaceholders)}");
                    }
                }
            }
        }