public void CreateWithCorrelationAndTransitional(BuildSqlVarient sqlVarient) { var saga = new SagaDefinition( tableSuffix: "theSaga", name: "theSaga", correlationProperty: new CorrelationProperty ( name: "CorrelationProperty", type: CorrelationPropertyType.String ), transitionalCorrelationProperty: new CorrelationProperty ( name: "TransitionalProperty", type: CorrelationPropertyType.String ) ); var builder = new StringBuilder(); using (var writer = new StringWriter(builder)) { SagaScriptBuilder.BuildCreateScript(saga, sqlVarient, writer); } var script = builder.ToString(); if (sqlVarient != BuildSqlVarient.MySql) { SqlValidator.Validate(script); } using (ApprovalResults.ForScenario(sqlVarient)) { Approvals.Verify(script); } }
public OutboxPersisterTests(BuildSqlVarient sqlVarient) { this.sqlVarient = sqlVarient; dbConnection = GetConnection(); persister = new OutboxPersister(sqlVarient.Convert(), connectionBuilder: dbConnection, tablePrefix: $"{nameof(OutboxPersisterTests)}_"); }
public static string BuildDropScript(BuildSqlVarient sqlVarient) { var stringBuilder = new StringBuilder(); using (var stringWriter = new StringWriter(stringBuilder)) { BuildDropScript(stringWriter, sqlVarient); } return stringBuilder.ToString(); }
public TimeoutPersisterTests(BuildSqlVarient sqlVarient) { this.sqlVarient = sqlVarient; dbConnection = GetConnection(); persister = new TimeoutPersister( connectionBuilder: dbConnection, tablePrefix: $"{nameof(TimeoutPersisterTests)}_", sqlVarient:sqlVarient.Convert()); }
public static string BuildCreateScript(SagaDefinition saga, BuildSqlVarient sqlVarient) { var stringBuilder = new StringBuilder(); using (var stringWriter = new StringWriter(stringBuilder)) { BuildCreateScript(saga, sqlVarient, stringWriter); } return stringBuilder.ToString(); }
static ISagaScriptWriter GetSqlVarientWriter(BuildSqlVarient sqlVarient, TextWriter textWriter, SagaDefinition saga) { if (sqlVarient == BuildSqlVarient.MsSqlServer) { return new MsSqlServerSagaScriptWriter(textWriter, saga); } if (sqlVarient == BuildSqlVarient.MySql) { return new MySqlSagaScriptWriter(textWriter, saga); } throw new Exception($"Unknown SqlVarient {sqlVarient}."); }
void Write(ModuleDefinition moduleDefinition, BuildSqlVarient sqlVarient) { var scriptPath = Path.Combine(IntermediateDirectory, "NServiceBus.Persistence.Sql", sqlVarient.ToString()); if (Directory.Exists(scriptPath)) { Directory.Delete(scriptPath, true); } Directory.CreateDirectory(scriptPath); WriteSagaScripts(scriptPath, moduleDefinition, sqlVarient); WriteTimeoutScript(scriptPath, sqlVarient); WriteSubscriptionScript(scriptPath, sqlVarient); WriteOutboxScript(scriptPath, sqlVarient); }
public void BuildCreateScript(BuildSqlVarient sqlVarient) { var builder = new StringBuilder(); using (var writer = new StringWriter(builder)) { TimeoutScriptBuilder.BuildCreateScript(writer, sqlVarient); } var script = builder.ToString(); if (sqlVarient != BuildSqlVarient.MySql) { SqlValidator.Validate(script); } using (ApprovalResults.ForScenario(sqlVarient)) { Approvals.Verify(script); } }
public static void BuildCreateScript(SagaDefinition saga, BuildSqlVarient sqlVarient, TextWriter writer) { Guard.AgainstNull(nameof(saga), saga); Guard.AgainstNull(nameof(writer), writer); SagaDefinitionValidator.ValidateSagaDefinition( correlationProperty: saga.CorrelationProperty?.Name, sagaName: saga.Name, tableSuffix: saga.TableSuffix, transitionalProperty: saga.TransitionalCorrelationProperty?.Name); var sqlVarientWriter = GetSqlVarientWriter(sqlVarient, writer, saga); WriteComment(writer, "TableNameVariable"); sqlVarientWriter.WriteTableNameVariable(); WriteComment(writer, "CreateTable"); sqlVarientWriter.WriteCreateTable(); if (saga.CorrelationProperty != null) { WriteComment(writer, $"AddProperty {saga.CorrelationProperty.Name}"); sqlVarientWriter.AddProperty(saga.CorrelationProperty); WriteComment(writer, $"VerifyColumnType {saga.CorrelationProperty.Type}"); sqlVarientWriter.VerifyColumnType(saga.CorrelationProperty); WriteComment(writer, $"WriteCreateIndex {saga.CorrelationProperty.Name}"); sqlVarientWriter.WriteCreateIndex(saga.CorrelationProperty); } if (saga.TransitionalCorrelationProperty != null) { WriteComment(writer, $"AddProperty {saga.TransitionalCorrelationProperty.Name}"); sqlVarientWriter.AddProperty(saga.TransitionalCorrelationProperty); WriteComment(writer, $"VerifyColumnType {saga.TransitionalCorrelationProperty.Type}"); sqlVarientWriter.VerifyColumnType(saga.TransitionalCorrelationProperty); WriteComment(writer, $"CreateIndex {saga.TransitionalCorrelationProperty.Name}"); sqlVarientWriter.WriteCreateIndex(saga.TransitionalCorrelationProperty); } WriteComment(writer, "PurgeObsoleteIndex"); sqlVarientWriter.WritePurgeObsoleteIndex(); WriteComment(writer, "PurgeObsoleteProperties"); sqlVarientWriter.WritePurgeObsoleteProperties(); }
public void BuildDropScript(BuildSqlVarient sqlVarient) { var builder = new StringBuilder(); using (var writer = new StringWriter(builder)) { OutboxScriptBuilder.BuildDropScript(writer, sqlVarient); } var script = builder.ToString(); if (sqlVarient == BuildSqlVarient.MsSqlServer) { SqlValidator.Validate(script); } using (ApprovalResults.ForScenario(sqlVarient)) { Approvals.Verify(script); } }
public void CreateWithNoCorrelation(BuildSqlVarient sqlVarient) { var saga = new SagaDefinition( tableSuffix: "theSaga", name: "theSaga" ); var builder = new StringBuilder(); using (var writer = new StringWriter(builder)) { SagaScriptBuilder.BuildCreateScript(saga, sqlVarient, writer); } var script = builder.ToString(); if (sqlVarient != BuildSqlVarient.MySql) { SqlValidator.Validate(script); } using (ApprovalResults.ForScenario(sqlVarient)) { Approvals.Verify(script); } }
void WriteSagaScripts(string scriptPath, ModuleDefinition moduleDefinition, BuildSqlVarient sqlVarient) { var metaDataReader = new AllSagaDefinitionReader(moduleDefinition); var sagasScriptPath = Path.Combine(scriptPath, "Sagas"); Directory.CreateDirectory(sagasScriptPath); var index = 0; foreach (var saga in metaDataReader.GetSagas((exception, type) => { logger.LogError($"Error in '{type.FullName}'. Error:{exception.Message}", type.GetFileName()); })) { var sagaFileName = saga.TableSuffix; var maximumNameLength = 244 - sagasScriptPath.Length; if (sagaFileName.Length > maximumNameLength) { sagaFileName = $"{sagaFileName.Substring(0, maximumNameLength)}_{index}"; index++; } var createPath = Path.Combine(sagasScriptPath, $"{sagaFileName}_Create.sql"); File.Delete(createPath); using (var writer = File.CreateText(createPath)) { SagaScriptBuilder.BuildCreateScript(saga, sqlVarient, writer); } var dropPath = Path.Combine(sagasScriptPath, $"{sagaFileName}_Drop.sql"); File.Delete(dropPath); using (var writer = File.CreateText(dropPath)) { SagaScriptBuilder.BuildDropScript(saga, sqlVarient, writer); } } }
public static void BuildDropScript(SagaDefinition saga, BuildSqlVarient sqlVarient, TextWriter writer) { var sqlVarientWriter = GetSqlVarientWriter(sqlVarient, writer, saga); WriteComment(writer, "TableNameVariable"); sqlVarientWriter.WriteTableNameVariable(); WriteComment(writer, "DropTable"); sqlVarientWriter.WriteDropTable(); }
public static string ReadResource(BuildSqlVarient sqlVarient, string prefix) { return Resource.AsStringUnChecked($"NServiceBus.Persistence.Sql.ScriptBuilder.{prefix}_{sqlVarient}.sql"); }
public static void BuildDropScript(TextWriter writer, BuildSqlVarient sqlVarient) { writer.Write(ResourceReader.ReadResource(sqlVarient, "Timeout.Drop")); }
static void Write(string testDirectory, BuildSqlVarient varient, string suffix, string script) { Write(testDirectory, suffix, script, varient.ToString()); }
static void WriteSubscriptionScript(string scriptPath, BuildSqlVarient sqlVarient) { var createPath = Path.Combine(scriptPath, "Subscription_Create.sql"); File.Delete(createPath); using (var writer = File.CreateText(createPath)) { SubscriptionScriptBuilder.BuildCreateScript(writer, sqlVarient); } var dropPath = Path.Combine(scriptPath, "Subscription_Drop.sql"); File.Delete(dropPath); using (var writer = File.CreateText(dropPath)) { SubscriptionScriptBuilder.BuildCreateScript(writer, sqlVarient); } }
public static void BuildCreateScript(TextWriter writer, BuildSqlVarient sqlVarient) { writer.Write(ResourceReader.ReadResource(sqlVarient, "Outbox.Create")); }
public void BuildDropScript(BuildSqlVarient sqlVarient) { var builder = new StringBuilder(); using (var writer = new StringWriter(builder)) { var saga = new SagaDefinition( tableSuffix: "theSaga", name: "theSaga" ); SagaScriptBuilder.BuildDropScript(saga, sqlVarient, writer); } var script = builder.ToString(); if (sqlVarient == BuildSqlVarient.MsSqlServer) { SqlValidator.Validate(script); } using (ApprovalResults.ForScenario(sqlVarient)) { Approvals.Verify(script); } }