Example #1
0
        static Project CreateTestProject(string projectPath, ODataT4CodeGenerator.LanguageOption targetLanguage = ODataT4CodeGenerator.LanguageOption.CSharp)
        {
            var fullPathPropertyMock = new Mock <Property>();

            fullPathPropertyMock.SetupGet(p => p.Value).Returns(projectPath);

            var projectPropertiesMock = new Mock <Properties>();

            projectPropertiesMock.Setup(p => p.Item(It.Is <string>(s => s == "FullPath")))
            .Returns(fullPathPropertyMock.Object);



            var projectMock = new Mock <Project>();

            projectMock.SetupGet(p => p.Properties)
            .Returns(projectPropertiesMock.Object);
            var projectCodeModelMock = new Mock <CodeModel>();

            if (targetLanguage == ODataT4CodeGenerator.LanguageOption.CSharp)
            {
                projectCodeModelMock.Setup(p => p.Language)
                .Returns(EnvDTE.CodeModelLanguageConstants.vsCMLanguageCSharp);
            }
            else
            {
                projectCodeModelMock.Setup(p => p.Language)
                .Returns(EnvDTE.CodeModelLanguageConstants.vsCMLanguageVB);
            }
            projectMock.SetupGet(p => p.CodeModel)
            .Returns(projectCodeModelMock.Object);
            return(projectMock.Object);
        }
        private string Generate(string edmx, string referenceName, ODataT4CodeGenerator.LanguageOption languageOption, bool useDataServiceCollection)
        {
            ODataT4CodeGenerator t4CodeGenerator = new ODataT4CodeGenerator
            {
                Edmx                     = edmx,
                NamespacePrefix          = referenceName,
                TargetLanguage           = languageOption,
                UseDataServiceCollection = useDataServiceCollection,
            };

            return(t4CodeGenerator.TransformText());
        }
Example #3
0
        static V4CodeGenDescriptor SetupCodeGenDescriptor(ServiceConfiguration serviceConfig, string serviceName, IODataT4CodeGeneratorFactory codeGenFactory, TestConnectedServiceHandlerHelper handlerHelper, ODataT4CodeGenerator.LanguageOption targetLanguage = ODataT4CodeGenerator.LanguageOption.CSharp)
        {
            var referenceFolderPath = Path.Combine(TestProjectRootPath, ServicesRootFolder, serviceName);

            Directory.CreateDirectory(referenceFolderPath);
            Project project         = CreateTestProject(TestProjectRootPath, targetLanguage);
            var     serviceInstance = new ODataConnectedServiceInstance()
            {
                ServiceConfig = serviceConfig,
                Name          = serviceName
            };

            handlerHelper.ServicesRootFolder = ServicesRootFolder;
            ConnectedServiceHandlerContext context = new TestConnectedServiceHandlerContext(serviceInstance, handlerHelper);

            return(new TestV4CodeGenDescriptor(serviceConfig.Endpoint ?? MetadataUri, context, project, codeGenFactory));
        }
        private void GenerateClientCodeFile(string edmx, string path, string nameSpacePrefix, ODataT4CodeGenerator.LanguageOption languageOption, bool useDataServiceCollection)
        {
            var result = this.Generate(edmx, nameSpacePrefix, languageOption, useDataServiceCollection);

            using (StreamWriter file = new StreamWriter(path, false))
            {
                file.WriteLine(result);
            }
        }