public void Create()
        {
            var expectedProperties = new List <string>
            {
                "static readonly PutAnotherPropertyValidators = [Validators.minLength(123), Validators.maxLength(123)];",
                "static readonly PutPropertyValidators = [Validators.min(33), Validators.max(66), Validators.required];",
                "static readonly GetSomePropertyValidators = [Validators.required, Validators.minLength(55)];",
                "static readonly PostCollectionOfNestedTypesValidators = [Validators.required];",
                "static readonly PostSomePropertyValidators = [Validators.required, Validators.pattern(`^[a-z''-'\\s]{1,3}$`)];",
                "static readonly TestNestedPropertyValidators = [Validators.minLength(123), Validators.maxLength(123)];",
                "static readonly TestAnotherNestedTypeInCollectionPropertyValidators = [Validators.required, Validators.maxLength(22)];",
                "static readonly TestEmailNestedTypeInCollectionPropertyValidators = [Validators.email];",
                "static readonly TestNestedTypeInCollectionPropertyValidators = [Validators.required, Validators.pattern(``)];"
            };
            var expectedClasses = new List <string>
            {
                "TypeFinderTestsTestApiTestGetRequest",
                "TypeFinderTestsTestApiTestPostRequest",
                "TypeFinderTestsTestApiTestPutRequest",
                "TypeFinderTestsTestApiTestNestedType",
                "TypeFinderTestsTestApiTestNestedTypeInCollection",
                "TypeFinderTestsTestApiNamespaceWithDuplicatedNamesTestNestedType"
            };

            var ts = NgReactiveFormValidators.CreateFor(
                AttributesTranform.For(FindTypes.Find("TypeFinder.Tests.dll"), NgValidatorsFromAttribute.For));

            expectedProperties.ForEach(c => Assert.IsTrue(ts.Contains(c)));
            expectedClasses.ForEach(c => Assert.IsTrue(ts.Contains($"export class {c}Validators")));
        }
Esempio n. 2
0
        public void Create()
        {
            var expectedProperties = new List <string>
            {
                "PutAnotherPropertyStringLength = 123",
                "PutPropertyRangeMin = 33",
                "PutPropertyRangeMax = 66",
                "PutPropertyIsRequired = true",
                "PutPropertyIsCreditCard = true",
                "GetSomePropertyIsRequired = true",
                "GetSomePropertyMinLength = 55",
                "PostCollectionOfNestedTypesIsRequired = true",
                "PostSomePropertyIsRequired = true",
                "TestNestedPropertyStringLength = 123",
                "TestNestedTypeInCollectionPropertyIsRequired = true",
                "PostSomePropertyRegularExpression = `^[a-z''-'\\s]{1,3}$`",
                "TestNestedTypeInCollectionPropertyRegularExpression = ``",
                "TestAnotherNestedTypeInCollectionPropertyMaxLength = 22",
            };
            var expectedClasses = new List <string>
            {
                "TypeFinderTestsTestApiTestGetRequest",
                "TypeFinderTestsTestApiTestPostRequest",
                "TypeFinderTestsTestApiTestPutRequest",
                "TypeFinderTestsTestApiTestNestedType",
                "TypeFinderTestsTestApiTestNestedTypeInCollection",
                "TypeFinderTestsTestApiNamespaceWithDuplicatedNamesTestNestedType"
            };

            var ts = TsDefinitions.CreateFor(AttributesTranform.For(FindTypes.Find("TypeFinder.Tests.dll"), TsFromAttribute.For));

            expectedProperties.ForEach(c => Assert.IsTrue(ts.Contains(c)));
            expectedClasses.ForEach(c => Assert.IsTrue(ts.Contains($"export class {c}")));
        }
        public static void Generate(string assemblyFilePath, string tsConstantsDestination, string ngReactiveFormValidatorsDestination)
        {
            var types = FindTypes.Find(assemblyFilePath);

            if (!string.IsNullOrWhiteSpace(tsConstantsDestination))
            {
                System.IO.File.WriteAllText(tsConstantsDestination, TsDefinitions.CreateFor(AttributesTranform.For(types, TsFromAttribute.For)));
            }
            if (!string.IsNullOrWhiteSpace(ngReactiveFormValidatorsDestination))
            {
                System.IO.File.WriteAllText(
                    ngReactiveFormValidatorsDestination,
                    NgReactiveFormValidators.CreateFor(AttributesTranform.For(types, NgValidatorsFromAttribute.For)));
            }
        }