Exemplo n.º 1
0
        //public static T GetProperty<T>(this IEnumerable<IStereotype> stereotypes, string stereoTypeName, string tagName, T defaultValue = default(T))
        //{
        //    foreach (var s in stereotypes)
        //    {
        //        if (s.Name == stereoTypeName)
        //        {
        //            foreach (var tag in s.Properties)
        //            {
        //                if (tag.Key == tagName)
        //                {
        //                    if (!string.IsNullOrWhiteSpace(tag.Value))
        //                    {
        //                        return (T)Convert.ChangeType(tag.Value, typeof(T));
        //                    }
        //                }
        //            }
        //        }
        //    }
        //    return defaultValue;
        //}

        //public static string TypeName(this IAttribute attribute)
        //{
        //    return attribute.Type.ConvertType();
        //}

        public static string ConvertType <T>(this IntentRoslynProjectItemTemplateBase <T> template, ITypeReference type, string context = null, string collectionType = nameof(IEnumerable))
        {
            var returnType = template.NormalizeNamespace(template.Types.Get(type, context));

            if (type.IsCollection && type.Type != ReferenceType.ClassType) // GCB - ClassType automatically adds the collectiont type. This disparity is a smell..
            {
                returnType = $"{collectionType}<{returnType}>";
            }
            return(returnType);
        }
        public void Scenario4()
        {
            var result = IntentRoslynProjectItemTemplateBase.NormalizeNamespace(
                localNamespace: "Solution.Application.Contracts.Internal.CompanyDetailsManagement",
                foreignType: "Solution.Application.Common.Enums.CompanyDetails.SocialMediaType",
                knownOtherPaths: ProjectNames,
                usingPaths: new string[]
            {
            });

            Assert.Equal("Common.Enums.CompanyDetails.SocialMediaType", result);
        }
        public void Scenario3()
        {
            var result = IntentRoslynProjectItemTemplateBase.NormalizeNamespace(
                localNamespace: "Solution.Application.ApplicationLayer",
                foreignType: "Solution.Application.Contracts.Internal.CompanyDetailsManagement.StatutoryInfoDTO",
                knownOtherPaths: ProjectNames,
                usingPaths: new string[]
            {
                "System.Runtime.Serialization",
                "AutoMapper",
                "Intent.RoslynWeaver.Attributes",
            });

            Assert.Equal("Contracts.Internal.CompanyDetailsManagement.StatutoryInfoDTO", result);
        }
        public void Scenario1()
        {
            var result = IntentRoslynProjectItemTemplateBase.NormalizeNamespace(
                localNamespace: "Solution.Application.Contracts.Internal.CompanyDetailsManagement",
                foreignType: "Solution.Common.Types.Country",
                knownOtherPaths: ProjectNames,
                usingPaths: new string[]
            {
                "System",
                "System.Collections.Generic",
                "System.Runtime.Serialization",
                "Intent.RoslynWeaver.Attributes",
            });

            Assert.Equal("Solution.Common.Types.Country", result);
        }
        public void Scenario5()
        {
            var result = IntentRoslynProjectItemTemplateBase.NormalizeNamespace(
                localNamespace: "MyCompany.Movies.Api",
                foreignType: "MyCompany.Movies.Application.Movies",
                knownOtherPaths: new string[]
            {
                "MyCompany.Movies.Infrastructure.Data",
                "MyCompany.Movies.Application",
                "MyCompany.Movies.Application.ServiceCallHandlers.Movies",
                "MyCompany.Movies.Domain"
            },
                usingPaths: new string[]
            {
                "MyCompany.Movies.Infrastructure.Data",
                "MyCompany.Movies.Application",
                "MyCompany.Movies.Application.ServiceCallHandlers.Movies",
                "MyCompany.Movies.Domain"
            });

            Assert.Equal("Application.Movies", result);
        }