Пример #1
0
 public void Should_Not_Add_sql_request_To_Dico_When_Sql_request_does_exist()
 {
     SqlRequestToActivityMapper.SaveSqlRequest("select 1", "ServiceClass1");
     SqlRequestToActivityMapper.SaveSqlRequest("select 1", "ServiceClass2");
     Assert.AreEqual(1, SqlRequestToActivityMapper.Count());
 }
Пример #2
0
 public void Should_return_First_serviceName_When_Sql_request_does_exist()
 {
     SqlRequestToActivityMapper.SaveSqlRequest("select 1", "ServiceClass1");
     SqlRequestToActivityMapper.SaveSqlRequest("select 1", "ServiceClass2");
     Assert.AreEqual("ServiceClass1", SqlRequestToActivityMapper.GetJdbcServiceName("select 1"));
 }
Пример #3
0
        public override CodeNamespaceCollection GenerateClassesToGenerate(Activity activity, Dictionary <string, string> variables)
        {
            var jdbcQueryActivity = (JdbcQueryActivity)activity;

            var result = new CodeNamespaceCollection();

            if (this.HasThisSqlRequestAlreadyGenerateAService(jdbcQueryActivity.QueryStatement))
            {
                this.ServiceToInvoke        = this.GetExistingJdbcServiceName(jdbcQueryActivity.QueryStatement);
                jdbcQueryActivity.ClassName = this.ServiceToInvoke.Replace("Service", string.Empty);
            }
            else
            {
                jdbcQueryActivity.ClassName = this.GenerateClassName(jdbcQueryActivity);
                this.ServiceToInvoke        = jdbcQueryActivity.ClassName + "Service";

                SqlRequestToActivityMapper.SaveSqlRequest(jdbcQueryActivity.QueryStatement, this.ServiceToInvoke);

                if (jdbcQueryActivity.QueryOutputStatementParameters != null && jdbcQueryActivity.QueryOutputStatementParameters.Count != 0)
                {
                    result.Add(this.resultSetBuilder.Build(jdbcQueryActivity));
                }

                var dataAccessNameSpace          = this.dataAccessBuilder.Build(jdbcQueryActivity);
                var dataAccessInterfaceNameSpace = InterfaceExtractorFromClass.Extract(dataAccessNameSpace.Types[0], TargetAppNameSpaceService.dataAccessNamespace());
                if (jdbcQueryActivity.QueryOutputStatementParameters != null &&
                    jdbcQueryActivity.QueryOutputStatementParameters.Count != 0)
                {
                    dataAccessInterfaceNameSpace.Imports.Add(new CodeNamespaceImport(TargetAppNameSpaceService.domainContractNamespaceName()));
                }

                dataAccessNameSpace.Types[0].BaseTypes.Add(new CodeTypeReference(dataAccessInterfaceNameSpace.Types[0].Name));

                var serviceNameSpace          = this.dataAccessServiceBuilder.Build(jdbcQueryActivity);
                var serviceInterfaceNameSpace = InterfaceExtractorFromClass.Extract(serviceNameSpace.Types[0], TargetAppNameSpaceService.domainContractNamespaceName());

                serviceNameSpace.Types[0].BaseTypes.Add(new CodeTypeReference(serviceInterfaceNameSpace.Types[0].Name));

                result.Add(dataAccessNameSpace);
                result.Add(dataAccessInterfaceNameSpace);
                result.Add(serviceNameSpace);
                result.Add(serviceInterfaceNameSpace);

                if (ConfigurationApp.GetProperty("HasCommonDataAccessAlreadyGenerated") != "true")
                {
                    var dataCommonNamespace = this.dataAccessCommonBuilder.Build();
                    result.Add(dataCommonNamespace);
                    ConfigurationApp.SaveProperty("HasCommonDataAccessAlreadyGenerated", "true");
                }

                //TODO : Find a more suitable way to retrieve the CustomAttribute To Build
                string dataCustomAttributeName = this.GetDataCustomAttributeName(dataAccessNameSpace);
                if (ConfigurationApp.GetProperty(dataCustomAttributeName) != "true")
                {
                    var dataBaseAttributeNamespace = new DatabaseAttributeBuilder().Build(dataCustomAttributeName);
                    result.Add(dataBaseAttributeNamespace);
                    ConfigurationApp.SaveProperty(dataCustomAttributeName, "true");
                }

                ModuleBuilder.AddServiceToRegister(dataAccessInterfaceNameSpace.Types[0].Name, dataAccessNameSpace.Types[0].Name);
                ModuleBuilder.AddServiceToRegister(serviceInterfaceNameSpace.Types[0].Name, this.ServiceToInvoke);
            }

            return(result);
        }