public async Task SerializeDeserialize_WhenRoutineRoundTripped_PreservesJsonStructure() { var routine = new DatabaseRoutine("test_routine_name", "test_routine_definition"); var routines = new[] { routine }; var tables = Array.Empty <IRelationalDatabaseTable>(); var views = Array.Empty <IDatabaseView>(); var sequences = Array.Empty <IDatabaseSequence>(); var synonyms = Array.Empty <IDatabaseSynonym>(); var db = new RelationalDatabase( new IdentifierDefaults(null, null, "main"), new VerbatimIdentifierResolutionStrategy(), tables, views, sequences, synonyms, routines ); var json = await Serializer.SerializeAsync(db).ConfigureAwait(false); var importedDb = await Serializer.DeserializeAsync(json).ConfigureAwait(false); var reExportedJson = await Serializer.SerializeAsync(importedDb).ConfigureAwait(false); Assert.Multiple(() => { Assert.That(reExportedJson, Is.Not.Null); Assert.That(reExportedJson, Is.Not.Empty); Assert.That(reExportedJson, Is.EqualTo(json)); }); }
public async Task SerializeDeserialize_WhenRoutineRoundTripped_ExportsAndParsesWithoutError() { var routine = new DatabaseRoutine("test_routine_name", "test_routine_definition"); var routines = new[] { routine }; var tables = Array.Empty <IRelationalDatabaseTable>(); var views = Array.Empty <IDatabaseView>(); var sequences = Array.Empty <IDatabaseSequence>(); var synonyms = Array.Empty <IDatabaseSynonym>(); var db = new RelationalDatabase( new IdentifierDefaults(null, null, "main"), new VerbatimIdentifierResolutionStrategy(), tables, views, sequences, synonyms, routines ); var json = await Serializer.SerializeAsync(db).ConfigureAwait(false); var importedDb = await Serializer.DeserializeAsync(json).ConfigureAwait(false); db.Should().BeEquivalentTo(importedDb); }
public static void Definition_PropertyGet_EqualsCtorArg() { Identifier routineName = "test_routine"; const string definition = "create function test_function..."; var routine = new DatabaseRoutine(routineName, definition); Assert.That(routine.Definition, Is.EqualTo(definition)); }
public static void ToString_WhenInvoked_ReturnsExpectedString(string schema, string localName, string expectedOutput) { var routineName = Identifier.CreateQualifiedIdentifier(schema, localName); const string definition = "create function test_function..."; var routine = new DatabaseRoutine(routineName, definition); var result = routine.ToString(); Assert.That(result, Is.EqualTo(expectedOutput)); }
public static async Task AnalyseRoutines_GivenRoutineWithNameContainingWhitespace_ProducesMessages() { var rule = new WhitespaceNameRule(RuleLevel.Error); var routineName = new Identifier(" test "); var routine = new DatabaseRoutine(routineName, "routine_definition"); var routines = new[] { routine }; var hasMessages = await rule.AnalyseRoutines(routines).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.True); }
public static async Task AnalyseRoutines_GivenRoutineWithNameContainingReservedKeyword_ProducesMessages() { var rule = new ReservedKeywordNameRule(CreateFakeDialect(), RuleLevel.Error); var routineName = new Identifier("SELECT"); var routine = new DatabaseRoutine(routineName, "routine_definition"); var routines = new[] { routine }; var hasMessages = await rule.AnalyseRoutines(routines).AnyAsync().ConfigureAwait(false); Assert.That(hasMessages, Is.True); }