Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ReadModelSqlGenerator column prefix and suffix usage [Copilot workspare test] #1036

Open
wants to merge 4 commits into
base: develop-v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// The MIT License (MIT)
//
// Copyright (c) 2015-2024 Rasmus Mikkelsen
// https://github.com/eventflow/EventFlow
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using EventFlow.PostgreSql.ReadModels;
using EventFlow.Sql.ReadModels;
using EventFlow.ReadStores;
using FluentAssertions;
using NUnit.Framework;

namespace EventFlow.PostgreSql.Tests.UnitTests
{
[TestFixture]
public class ReadModelSqlGeneratorTests
{
[Test]
public void PostgresReadModelSqlGenerator_ApplyColumnPrefixesAndSuffixesInSelectQueries()
{
// Arrange
var readModelSqlGenerator = new PostgresReadModelSqlGenerator();

// Act
var selectSql = readModelSqlGenerator.CreateSelectSql<TestReadModel>();

Check failure on line 41 in Source/EventFlow.PostgreSql.Tests/UnitTests/ReadModelSqlGeneratorTests.cs

View workflow job for this annotation

GitHub Actions / Test results

EventFlow.PostgreSql.Tests.UnitTests.ReadModelSqlGeneratorTests ► PostgresReadModelSqlGenerator_ApplyColumnPrefixesAndSuffixesInSelectQueries

Failed test found in: Source/EventFlow.PostgreSql.Tests/TestResults/_fv-az652-748_2024-06-19_07_15_36.trx Source/EventFlow.PostgreSql.Tests/TestResults/_fv-az652-748_2024-06-19_07_16_04.trx Error: Expected string "SELECT * FROM "ReadModel-Test" WHERE AggregateId = @EventFlowReadModelId" to contain ""AggregateId" = @EventFlowReadModelId".
Raw output
Expected string "SELECT * FROM "ReadModel-Test" WHERE AggregateId = @EventFlowReadModelId" to contain ""AggregateId" = @EventFlowReadModelId".
   at FluentAssertions.Execution.LateBoundTestFramework.Throw(String message)
   at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
   at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
   at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
   at FluentAssertions.Primitives.StringAssertions.Contain(String expected, String because, Object[] becauseArgs)
   at EventFlow.PostgreSql.Tests.UnitTests.ReadModelSqlGeneratorTests.PostgresReadModelSqlGenerator_ApplyColumnPrefixesAndSuffixesInSelectQueries() in /home/runner/work/EventFlow/EventFlow/Source/EventFlow.PostgreSql.Tests/UnitTests/ReadModelSqlGeneratorTests.cs:line 41

// Assert
selectSql.Should().Contain("\"AggregateId\" = @EventFlowReadModelId");
}

[Test]
public void PostgresReadModelSqlGenerator_ApplyColumnPrefixesAndSuffixesInInsertQueries()
{
// Arrange
var readModelSqlGenerator = new PostgresReadModelSqlGenerator();

// Act
var insertSql = readModelSqlGenerator.CreateInsertSql<TestReadModel>();

Check failure on line 54 in Source/EventFlow.PostgreSql.Tests/UnitTests/ReadModelSqlGeneratorTests.cs

View workflow job for this annotation

GitHub Actions / Test results

EventFlow.PostgreSql.Tests.UnitTests.ReadModelSqlGeneratorTests ► PostgresReadModelSqlGenerator_ApplyColumnPrefixesAndSuffixesInInsertQueries

Failed test found in: Source/EventFlow.PostgreSql.Tests/TestResults/_fv-az652-748_2024-06-19_07_15_36.trx Source/EventFlow.PostgreSql.Tests/TestResults/_fv-az652-748_2024-06-19_07_16_04.trx Error: Expected string "INSERT INTO "ReadModel-Test" (Id, Name) VALUES (@id, @name)" to contain ""AggregateId", "Name"".
Raw output
Expected string "INSERT INTO "ReadModel-Test" (Id, Name) VALUES (@Id, @Name)" to contain ""AggregateId", "Name"".
   at FluentAssertions.Execution.LateBoundTestFramework.Throw(String message)
   at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
   at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
   at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
   at FluentAssertions.Primitives.StringAssertions.Contain(String expected, String because, Object[] becauseArgs)
   at EventFlow.PostgreSql.Tests.UnitTests.ReadModelSqlGeneratorTests.PostgresReadModelSqlGenerator_ApplyColumnPrefixesAndSuffixesInInsertQueries() in /home/runner/work/EventFlow/EventFlow/Source/EventFlow.PostgreSql.Tests/UnitTests/ReadModelSqlGeneratorTests.cs:line 54

// Assert
insertSql.Should().Contain("\"AggregateId\", \"Name\"");
}

[Test]
public void PostgresReadModelSqlGenerator_ApplyColumnPrefixesAndSuffixesInUpdateQueries()
{
// Arrange
var readModelSqlGenerator = new PostgresReadModelSqlGenerator();

// Act
var updateSql = readModelSqlGenerator.CreateUpdateSql<TestReadModel>();

Check failure on line 67 in Source/EventFlow.PostgreSql.Tests/UnitTests/ReadModelSqlGeneratorTests.cs

View workflow job for this annotation

GitHub Actions / Test results

EventFlow.PostgreSql.Tests.UnitTests.ReadModelSqlGeneratorTests ► PostgresReadModelSqlGenerator_ApplyColumnPrefixesAndSuffixesInUpdateQueries

Failed test found in: Source/EventFlow.PostgreSql.Tests/TestResults/_fv-az652-748_2024-06-19_07_15_36.trx Source/EventFlow.PostgreSql.Tests/TestResults/_fv-az652-748_2024-06-19_07_16_04.trx Error: Expected string "UPDATE "ReadModel-Test" SET Id = @id, Name = @name WHERE AggregateId = @AggregateId " to contain ""AggregateId" = @id".
Raw output
Expected string "UPDATE "ReadModel-Test" SET Id = @Id, Name = @Name WHERE AggregateId = @AggregateId " to contain ""AggregateId" = @Id".
   at FluentAssertions.Execution.LateBoundTestFramework.Throw(String message)
   at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
   at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
   at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
   at FluentAssertions.Primitives.StringAssertions.Contain(String expected, String because, Object[] becauseArgs)
   at EventFlow.PostgreSql.Tests.UnitTests.ReadModelSqlGeneratorTests.PostgresReadModelSqlGenerator_ApplyColumnPrefixesAndSuffixesInUpdateQueries() in /home/runner/work/EventFlow/EventFlow/Source/EventFlow.PostgreSql.Tests/UnitTests/ReadModelSqlGeneratorTests.cs:line 67

// Assert
updateSql.Should().Contain("\"AggregateId\" = @Id");
}

[Test]
public void PostgresReadModelSqlGenerator_ApplyColumnPrefixesAndSuffixesInDeleteQueries()
{
// Arrange
var readModelSqlGenerator = new PostgresReadModelSqlGenerator();

// Act
var deleteSql = readModelSqlGenerator.CreateDeleteSql<TestReadModel>();

Check failure on line 80 in Source/EventFlow.PostgreSql.Tests/UnitTests/ReadModelSqlGeneratorTests.cs

View workflow job for this annotation

GitHub Actions / Test results

EventFlow.PostgreSql.Tests.UnitTests.ReadModelSqlGeneratorTests ► PostgresReadModelSqlGenerator_ApplyColumnPrefixesAndSuffixesInDeleteQueries

Failed test found in: Source/EventFlow.PostgreSql.Tests/TestResults/_fv-az652-748_2024-06-19_07_15_36.trx Source/EventFlow.PostgreSql.Tests/TestResults/_fv-az652-748_2024-06-19_07_16_04.trx Error: Expected string "DELETE FROM "ReadModel-Test" WHERE AggregateId = @EventFlowReadModelId" to contain ""AggregateId" = @EventFlowReadModelId".
Raw output
Expected string "DELETE FROM "ReadModel-Test" WHERE AggregateId = @EventFlowReadModelId" to contain ""AggregateId" = @EventFlowReadModelId".
   at FluentAssertions.Execution.LateBoundTestFramework.Throw(String message)
   at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
   at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
   at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
   at FluentAssertions.Primitives.StringAssertions.Contain(String expected, String because, Object[] becauseArgs)
   at EventFlow.PostgreSql.Tests.UnitTests.ReadModelSqlGeneratorTests.PostgresReadModelSqlGenerator_ApplyColumnPrefixesAndSuffixesInDeleteQueries() in /home/runner/work/EventFlow/EventFlow/Source/EventFlow.PostgreSql.Tests/UnitTests/ReadModelSqlGeneratorTests.cs:line 80

// Assert
deleteSql.Should().Contain("\"AggregateId\" = @EventFlowReadModelId");
}

public class TestReadModel : IReadModel
{
public string Id { get; set; }
public string Name { get; set; }
}
}
}
4 changes: 2 additions & 2 deletions Source/EventFlow.Sql/ReadModels/ReadModelSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected ReadModelSqlGenerator(ReadModelSqlGeneratorConfiguration configuration
var tableName = GetTableName<TReadModel>();
var identityColumn = GetIdentityColumn<TReadModel>();

sql = $"SELECT * FROM {tableName} WHERE {identityColumn} = @EventFlowReadModelId";
sql = $"SELECT * FROM {tableName} WHERE {Configuration.ColumnQuotedIdentifierPrefix}{identityColumn}{Configuration.ColumnQuotedIdentifierSuffix} = @EventFlowReadModelId";

_selectSqls[readModelType] = sql;

Expand Down Expand Up @@ -238,4 +238,4 @@ protected IReadOnlyCollection<PropertyInfo> GetPropertyInfos(Type readModelType)
});
}
}
}
}
Loading