From 48aaaf708c79e7cca1876a7085f0cd647c070dd7 Mon Sep 17 00:00:00 2001 From: Dmytro Dorodnykh Date: Wed, 5 Jul 2023 12:39:38 +0300 Subject: [PATCH 1/9] Add database test --- .../ModelGenerator/EntitiesGenerator.cs | 1 + .../DbContextGenerator/DbContextGenerator.cs | 3 +- .../Examples/SampleWebAppDbContextExample.cs | 4 +- .../Database/Design/test.solution.nox.yaml | 237 ++++++++++++++++++ .../Database/EntityFrameworkTests.cs | 74 ++++++ .../Database/Models/AuditableEntityBase.cs | 40 +++ .../Database/Models/SampleWebAppDbContext.cs | 55 ++++ .../Database/Models/TestEntity.cs | 36 +++ .../Database/SqliteTestBase.cs | 53 ++++ .../Nox.Generator.Tests.csproj | 12 +- 10 files changed, 510 insertions(+), 5 deletions(-) create mode 100644 tests/Nox.Generator.Tests/Database/Design/test.solution.nox.yaml create mode 100644 tests/Nox.Generator.Tests/Database/EntityFrameworkTests.cs create mode 100644 tests/Nox.Generator.Tests/Database/Models/AuditableEntityBase.cs create mode 100644 tests/Nox.Generator.Tests/Database/Models/SampleWebAppDbContext.cs create mode 100644 tests/Nox.Generator.Tests/Database/Models/TestEntity.cs create mode 100644 tests/Nox.Generator.Tests/Database/SqliteTestBase.cs diff --git a/src/Nox.Generator/Domain/ModelGenerator/EntitiesGenerator.cs b/src/Nox.Generator/Domain/ModelGenerator/EntitiesGenerator.cs index 9b25f29693..e223da7688 100644 --- a/src/Nox.Generator/Domain/ModelGenerator/EntitiesGenerator.cs +++ b/src/Nox.Generator/Domain/ModelGenerator/EntitiesGenerator.cs @@ -27,6 +27,7 @@ private static void GenerateEntity(SourceProductionContext context, string solut var code = new CodeBuilder($"{entity.Name}.g.cs", context); code.AppendLine($"using Nox.Types;"); + code.AppendLine($"using System;"); code.AppendLine($"using System.Collections.Generic;"); code.AppendLine(); code.AppendLine($"namespace {solutionNameSpace}.Domain;"); diff --git a/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs b/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs index ac12826106..a83ce15285 100644 --- a/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs +++ b/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs @@ -83,8 +83,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) } } - base.OnModelCreating(modelBuilder); } + + base.OnModelCreating(modelBuilder); } } "); diff --git a/src/SampleWebApp/Examples/SampleWebAppDbContextExample.cs b/src/SampleWebApp/Examples/SampleWebAppDbContextExample.cs index 83eb2c9f20..664a93388f 100644 --- a/src/SampleWebApp/Examples/SampleWebAppDbContextExample.cs +++ b/src/SampleWebApp/Examples/SampleWebAppDbContextExample.cs @@ -49,8 +49,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) _databaseConfigurator.ConfigureEntity(modelBuilder.Entity(type), entity); } } - - base.OnModelCreating(modelBuilder); } + + base.OnModelCreating(modelBuilder); } } \ No newline at end of file diff --git a/tests/Nox.Generator.Tests/Database/Design/test.solution.nox.yaml b/tests/Nox.Generator.Tests/Database/Design/test.solution.nox.yaml new file mode 100644 index 0000000000..fb06d787f7 --- /dev/null +++ b/tests/Nox.Generator.Tests/Database/Design/test.solution.nox.yaml @@ -0,0 +1,237 @@ +# +# workplace.solution.nox.yaml +# +# yaml-language-server: $schema=https://noxorg.dev/schemas/solution.json +# + +name: SampleWebApp + +description: Sample Nox solution yaml configuration + +variables: + DATABASE_PROVIDER: slqServer + DATABASE_SERVER: localhost + DATABASE_USER: sa + DATABASE_PASSWORD: Developer*123 + DATABASE_PORT: "5432" + +environments: + + - name: dev + description: Used for development and testing + + - name: test + description: Test environment + + - name: uat + description: For them end users to check it works + + - name: prod + description: Production environment used for, well - the real thing! + isProduction: true + +versionControl: + provider: azureDevops + host: https://dev.azure.com/iwgplc + folders: + sourceCode: /src + containers: /docker + +team: + + - name: Andre Sharpe + userName: andre.sharpe@iwgplc.com + roles: [architect, owner, administrator, developer, manager] + + - name: Jan Schutte + userName: jan.schutte@iwgplc.com + roles: [architect, administrator, developer, devOpsEngineer] + + - name: Anton Du Plessis + userName: anton.duplessis@iwgplc.com + roles: [projectManager] + + - name: Morne Van Zyl + userName: morne.vanzyl@iwgplc.com + roles: [technicalWriter] + + - name: Dmytro Dorodnykh + userName: dmytro.dorodnykh@iwgplc.com + roles: [developer] + + - name: Oleksandr Vlasenko + userName: oleksandr.vlasenko@regus.com + roles: [architect, developer] + +domain: + + entities: + + - name: TestEntity + description: Entity created for testing database + + userInterface: + icon: world + + persistence: + isVersioned: true + tableName: TestEntity + schema: dbo + create: + isEnabled: true + raiseEvents: true + read: + isEnabled: true + update: + isEnabled: true + raiseEvents: true + delete: + isEnabled: true + raiseEvents: true + useSoftDelete: true + + keys: + + - name: Id + type: text + textTypeOptions: + isUnicode: false + minLength: 2 + maxLength: 2 + + attributes: + + - name: TextTestField + type: text + textTypeOptions: + minLength: 4 + maxLength: 63 + isRequired: true + + - name: NumberTestField + type: number + numberTypeOptions: + minValue: 4 + maxValue: 894 + isRequired: true + + - name: MoneyTestField + type: money + + #- name: GeoCoordTestField + # type: latLong + + #- name: AreaTestField + # type: area + + #- name: BooleanTestField + # type: boolean + + #- name: CountryCode2TestField + # type: countryCode2 + + #- name: CountryCode3TestField + # type: countryCode3 + + #- name: CountryNumberTestField + # type: countryNumber + + #- name: CurrencyCodeTestField + # type: currencyCode + + #- name: CurrencyNumberTestField + # type: currencyNumber + + #- name: DateTimeTestField + # type: dateTime + + #- name: DateTimeRangeTestField + # type: dateTimeRange + + #- name: DistanceTestField + # type: distance + + #- name: EmailTestField + # type: email + + #- name: EncryptedTextTestField + # type: encryptedText + + #- name: GuidTestField + # type: guid + + #- name: HashedTextTestField + # type: hashedText + + #- name: InternetDomainTestField + # type: internetDomain + + #- name: IpAddressTestField + # type: ipAddress + + #- name: LengthTestField + # type: length + + #- name: MacAddressTestField + # type: macAddress + + #- name: MonthTestField + # type: month + + #- name: NuidTestField + # type: nuid + + #- name: PasswordTestField + # type: password + + #- name: PercentageTestField + # type: percentage + + #- name: PhoneNumberTestField + # type: phoneNumber + + #- name: StreetAddressTestField + # type: streetAddress + + #- name: TempratureTestField + # type: temperature + + #- name: UriTestField + # type: uri + + #- name: VolumeTestField + # type: volume + + #- name: WeightTestField + # type: weight + + #- name: YearTestField + # type: year + + #- name: CultureCodeTestField + # type: cultureCode + + #- name: LanguageCodeTestField + # type: languageCode + +infrastructure: + + persistence: + databaseServer: + name: SampleCurrencyDb + + # Sql Server + serverUri: sqlserver.iwgplc.com + provider: sqlServer + port: 1433 + user: sqluser + password: sqlpassword + + messaging: + integrationEventServer: + name: IntegrationBus + provider: rabbitMq + serverUri: rabbitmq://localhost + port: 5672 + user: guest + password: guest diff --git a/tests/Nox.Generator.Tests/Database/EntityFrameworkTests.cs b/tests/Nox.Generator.Tests/Database/EntityFrameworkTests.cs new file mode 100644 index 0000000000..36189fba98 --- /dev/null +++ b/tests/Nox.Generator.Tests/Database/EntityFrameworkTests.cs @@ -0,0 +1,74 @@ +using FluentAssertions; +using Nox.Types; +using NoxSourceGeneratorTests.DatabaseTests; +using SampleWebApp.Domain; +using System.Linq; +using Xunit; + +namespace Nox.Generator.Test.DatabaseTests; + +public class EntityFrameworkTests : SqliteTestBase +{ + [Fact] + public void GeneratedEntity_CanSaveAndReadFields_AllTypes() + { + // TODO: + // array + // color + // colour + // autoNumber + // collection + // entity + // file + // formula + // image + // imagePng + // imageJpg + // imageSvg + // object + // user + // cultureCode + // languageCode + // yaml + // uri + // url + // date + // dateTimeDuration + // dateTimeSchedule + // html + // json + // time + // translatedText + // markdown + // jwtToken + + // TODO: commented types + + var text = "TestTextValue"; + var number = 123; + var money = 10; + var currencyCode = CurrencyCode.UAH; + + var newItem = new TestEntity() + { + Id = Text.From(text), + TextTestField = Text.From(text), + NumberTestField = Number.From(number), + MoneyTestField = Money.From(money, currencyCode) + }; + DbContext.TestEntities.Add(newItem); + DbContext.SaveChanges(); + + // Force the recreation of DBContext and ensure we have fresh data from database + RecreateDbContext(); + + var testEntity = DbContext.TestEntities.First(); + + // TODO: make it work without .Value + testEntity.Id.Value.Should().Be(text); + testEntity.TextTestField.Value.Should().Be(text); + testEntity.NumberTestField.Value.Should().Be(number); + testEntity.MoneyTestField.Value.Amount.Should().Be(money); + testEntity.MoneyTestField.Value.CurrencyCode.Should().Be(currencyCode); + } +} \ No newline at end of file diff --git a/tests/Nox.Generator.Tests/Database/Models/AuditableEntityBase.cs b/tests/Nox.Generator.Tests/Database/Models/AuditableEntityBase.cs new file mode 100644 index 0000000000..4ac2729b85 --- /dev/null +++ b/tests/Nox.Generator.Tests/Database/Models/AuditableEntityBase.cs @@ -0,0 +1,40 @@ +// Generated + +#nullable enable + +using System; + +namespace SampleWebApp.Domain; + +public partial class AuditableEntityBase +{ + /// + /// The date and time when this entity was first created (in Coordinated Universal Time). + /// + public DateTime CreatedAtUtc { get; set; } + + /// + /// The user that created the entity. + /// + public string? CreatedBy { get; set; } + + /// + /// The date and time when this entity was last updated (in Coordinated Universal Time). + /// + public DateTime? UpdatedAtUtc { get; set; } + + /// + /// The user that last updated the entity. + /// + public string? UpdatedBy { get; set; } + + /// + /// The date and time when this entity was deleted (in Coordinated Universal Time). + /// + public DateTime? DeletedAtUtc { get; set; } + + /// + /// The user that deleted the entity. + /// + public string? DeletedBy { get; set; } +} diff --git a/tests/Nox.Generator.Tests/Database/Models/SampleWebAppDbContext.cs b/tests/Nox.Generator.Tests/Database/Models/SampleWebAppDbContext.cs new file mode 100644 index 0000000000..30a17685eb --- /dev/null +++ b/tests/Nox.Generator.Tests/Database/Models/SampleWebAppDbContext.cs @@ -0,0 +1,55 @@ +// Generated + +#nullable enable + +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Nox.Solution; +using Nox.Types.EntityFramework.vNext; +using SampleWebApp.Domain; +using System; + +namespace SampleWebApp.Infrastructure.Persistence; + +public partial class SampleWebAppDbContext : DbContext +{ + private NoxSolution _noxSolution { get; set; } + private INoxDatabaseConfigurator _databaseConfigurator { get; set; } + + public SampleWebAppDbContext( + DbContextOptions options, + NoxSolution noxSolution, + INoxDatabaseConfigurator databaseConfigurator + ) : base(options) + { + _noxSolution = noxSolution; + _databaseConfigurator = databaseConfigurator; + } + + public DbSet TestEntities { get; set; } = null!; + + + public static void RegisterDbContext(IServiceCollection services) + { + services.AddDbContext(); + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + if (_noxSolution.Domain != null) + { + foreach (var entity in _noxSolution.Domain.Entities) + { + var type = Type.GetType("SampleWebApp.Domain." + entity.Name); + + if (type != null) + { + _databaseConfigurator.ConfigureEntity(modelBuilder.Entity(type), entity); + } + } + } + + base.OnModelCreating(modelBuilder); + } +} + diff --git a/tests/Nox.Generator.Tests/Database/Models/TestEntity.cs b/tests/Nox.Generator.Tests/Database/Models/TestEntity.cs new file mode 100644 index 0000000000..417c770928 --- /dev/null +++ b/tests/Nox.Generator.Tests/Database/Models/TestEntity.cs @@ -0,0 +1,36 @@ +// Generated + +#nullable enable + +using Nox.Types; +using System; +using System.Collections.Generic; + +namespace SampleWebApp.Domain; + +/// +/// Entity created for testing database. +/// +public partial class TestEntity : AuditableEntityBase +{ + + /// + /// (Optional) + /// + public Text Id { get; set; } = null!; + + /// + /// (Required) + /// + public Text TextTestField { get; set; } = null!; + + /// + /// (Required) + /// + public Number NumberTestField { get; set; } = null!; + + /// + /// (Optional) + /// + public Money? MoneyTestField { get; set; } = null!; +} diff --git a/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs b/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs new file mode 100644 index 0000000000..5f87db3514 --- /dev/null +++ b/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs @@ -0,0 +1,53 @@ +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using Nox.Solution; +using Nox.Types.EntityFramework.Sqlite; +using SampleWebApp.Infrastructure.Persistence; +using System; + +namespace NoxSourceGeneratorTests.DatabaseTests; + +public abstract class SqliteTestBase : IDisposable +{ + //private const string InMemoryConnectionString = "DataSource=:memory:"; + private const string InMemoryConnectionString = @"DataSource=test_database.db"; + private const string _testSolutionFile = @"..\..\..\Database\Design\test.solution.nox.yaml"; + private readonly SqliteConnection _connection; + + protected SampleWebAppDbContext DbContext; + + protected SqliteTestBase() + { + _connection = new SqliteConnection(InMemoryConnectionString); + _connection.Open(); + DbContext = CreateDbContext(_connection); + } + + private static SampleWebAppDbContext CreateDbContext(SqliteConnection connection) + { + var databaseConfigurator = new SqliteDatabaseConfigurator(); + var solution = new NoxSolutionBuilder() + .UseYamlFile(_testSolutionFile) + .Build(); + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + var dbContext = new SampleWebAppDbContext(options, solution, databaseConfigurator); + dbContext.Database.EnsureCreated(); + return dbContext; + } + + internal void RecreateDbContext() + { + var previousDbContext = DbContext; + DbContext = CreateDbContext(_connection); + previousDbContext.Dispose(); + } + + public void Dispose() + { + GC.SuppressFinalize(this); + DbContext?.Dispose(); + _connection.Dispose(); + } +} \ No newline at end of file diff --git a/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj b/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj index 6f5f7daf9d..f1007b32a8 100644 --- a/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj +++ b/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj @@ -2,7 +2,7 @@ net7.0 - false + false @@ -13,6 +13,9 @@ runtime; build; native; contentfiles; analyzers; buildtransitive + + + @@ -30,7 +33,10 @@ - + + + + @@ -38,6 +44,7 @@ + @@ -74,6 +81,7 @@ + Always From 14fff8024521c20b1d2af20b045a8bf1b2266b1b Mon Sep 17 00:00:00 2001 From: Dmytro Dorodnykh Date: Wed, 5 Jul 2023 12:45:20 +0300 Subject: [PATCH 2/9] add dynamic db name --- tests/Nox.Generator.Tests/Database/SqliteTestBase.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs b/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs index 5f87db3514..3ca04df002 100644 --- a/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs +++ b/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs @@ -10,7 +10,8 @@ namespace NoxSourceGeneratorTests.DatabaseTests; public abstract class SqliteTestBase : IDisposable { //private const string InMemoryConnectionString = "DataSource=:memory:"; - private const string InMemoryConnectionString = @"DataSource=test_database.db"; + private const string _inMemoryConnectionStringTemplate = @"DataSource=test_database_{0}.db"; + private static string _inMemoryConnectionString = string.Empty; private const string _testSolutionFile = @"..\..\..\Database\Design\test.solution.nox.yaml"; private readonly SqliteConnection _connection; @@ -18,7 +19,8 @@ public abstract class SqliteTestBase : IDisposable protected SqliteTestBase() { - _connection = new SqliteConnection(InMemoryConnectionString); + _inMemoryConnectionString = string.Format(_inMemoryConnectionStringTemplate, DateTime.UtcNow.Ticks); + _connection = new SqliteConnection(_inMemoryConnectionString); _connection.Open(); DbContext = CreateDbContext(_connection); } From 4b34151d7b8eb52c65dde0537df1c11b5acd8e2c Mon Sep 17 00:00:00 2001 From: Dmytro Dorodnykh Date: Wed, 5 Jul 2023 12:52:10 +0300 Subject: [PATCH 3/9] fix path --- tests/Nox.Generator.Tests/Database/SqliteTestBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs b/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs index 3ca04df002..90c455bd23 100644 --- a/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs +++ b/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs @@ -12,7 +12,7 @@ public abstract class SqliteTestBase : IDisposable //private const string InMemoryConnectionString = "DataSource=:memory:"; private const string _inMemoryConnectionStringTemplate = @"DataSource=test_database_{0}.db"; private static string _inMemoryConnectionString = string.Empty; - private const string _testSolutionFile = @"..\..\..\Database\Design\test.solution.nox.yaml"; + private const string _testSolutionFile = @"../../../Database/Design/test.solution.nox.yaml"; private readonly SqliteConnection _connection; protected SampleWebAppDbContext DbContext; From daabe7eccce6bc717d3559315ce8ee0d0d2234df Mon Sep 17 00:00:00 2001 From: Dmytro Dorodnykh Date: Wed, 5 Jul 2023 12:54:32 +0300 Subject: [PATCH 4/9] use in-memory db --- tests/Nox.Generator.Tests/Database/SqliteTestBase.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs b/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs index 90c455bd23..37881a7272 100644 --- a/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs +++ b/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs @@ -9,8 +9,8 @@ namespace NoxSourceGeneratorTests.DatabaseTests; public abstract class SqliteTestBase : IDisposable { - //private const string InMemoryConnectionString = "DataSource=:memory:"; - private const string _inMemoryConnectionStringTemplate = @"DataSource=test_database_{0}.db"; + private const string _inMemoryConnectionStringTemplate = "DataSource=:memory:"; + //private const string _inMemoryConnectionStringTemplate = @"DataSource=test_database_{0}.db"; private static string _inMemoryConnectionString = string.Empty; private const string _testSolutionFile = @"../../../Database/Design/test.solution.nox.yaml"; private readonly SqliteConnection _connection; From 1cb2e6a8e0502dcfcf0558845236d7128e3a8a1e Mon Sep 17 00:00:00 2001 From: Dmytro Dorodnykh Date: Wed, 5 Jul 2023 13:35:33 +0300 Subject: [PATCH 5/9] fix comments --- .../DbContextGenerator/DbContextGenerator.cs | 2 +- .../Nox.Generator.NoxCodeGenerator/Country.g.cs | 1 + .../CountryLocalNames.g.cs | 1 + .../Nox.Generator.NoxCodeGenerator/Currency.g.cs | 1 + .../SampleWebAppDbContext.g.cs | 3 ++- .../Nox.Generator.NoxCodeGenerator/Store.g.cs | 1 + .../Database/Design/test.solution.nox.yaml | 8 ++++---- ...orkTests.cs => EntityFrameworkSqliteTests.cs} | 6 +++--- .../Database/Models/AuditableEntityBase.cs | 2 +- ...ntext.cs => TestDatabaseWebAppDbContext.g.cs} | 15 ++++++++------- .../Database/Models/TestEntity.cs | 2 +- .../Database/SqliteTestBase.cs | 16 ++++++++-------- .../Nox.Generator.Tests.csproj | 4 +++- 13 files changed, 35 insertions(+), 27 deletions(-) rename tests/Nox.Generator.Tests/Database/{EntityFrameworkTests.cs => EntityFrameworkSqliteTests.cs} (92%) rename tests/Nox.Generator.Tests/Database/Models/{SampleWebAppDbContext.cs => TestDatabaseWebAppDbContext.g.cs} (73%) diff --git a/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs b/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs index a83ce15285..4ab0836c19 100644 --- a/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs +++ b/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs @@ -24,7 +24,7 @@ public static void Generate(SourceProductionContext context, string solutionName code.AppendLine(@"using Microsoft.EntityFrameworkCore;"); code.AppendLine(@"using Nox.Solution;"); code.AppendLine(@"using Nox.Types.EntityFramework.vNext;"); - code.AppendLine(@"using SampleWebApp.Domain;"); + code.AppendLine($@"using {solutionNameSpace}.Domain;"); code.AppendLine(); code.AppendLine($"namespace {solutionNameSpace}.Infrastructure.Persistence;"); code.AppendLine(); diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Country.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Country.g.cs index 6805e60b72..7fde1e2354 100644 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Country.g.cs +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Country.g.cs @@ -3,6 +3,7 @@ #nullable enable using Nox.Types; +using System; using System.Collections.Generic; namespace SampleWebApp.Domain; diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNames.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNames.g.cs index 4a0eb3b9e7..79c7b172ac 100644 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNames.g.cs +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNames.g.cs @@ -3,6 +3,7 @@ #nullable enable using Nox.Types; +using System; using System.Collections.Generic; namespace SampleWebApp.Domain; diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Currency.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Currency.g.cs index 296af5eefa..b8cd178735 100644 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Currency.g.cs +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Currency.g.cs @@ -3,6 +3,7 @@ #nullable enable using Nox.Types; +using System; using System.Collections.Generic; namespace SampleWebApp.Domain; diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs index 8cca3953cd..25db3cec68 100644 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs @@ -52,8 +52,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) } } - base.OnModelCreating(modelBuilder); } + + base.OnModelCreating(modelBuilder); } } diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Store.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Store.g.cs index 462ee71e47..fd77ec669a 100644 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Store.g.cs +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Store.g.cs @@ -3,6 +3,7 @@ #nullable enable using Nox.Types; +using System; using System.Collections.Generic; namespace SampleWebApp.Domain; diff --git a/tests/Nox.Generator.Tests/Database/Design/test.solution.nox.yaml b/tests/Nox.Generator.Tests/Database/Design/test.solution.nox.yaml index fb06d787f7..406937e071 100644 --- a/tests/Nox.Generator.Tests/Database/Design/test.solution.nox.yaml +++ b/tests/Nox.Generator.Tests/Database/Design/test.solution.nox.yaml @@ -4,7 +4,7 @@ # yaml-language-server: $schema=https://noxorg.dev/schemas/solution.json # -name: SampleWebApp +name: TestDatabaseWebApp description: Sample Nox solution yaml configuration @@ -118,6 +118,9 @@ domain: - name: MoneyTestField type: money + #- name: CountryCode2TestField + # type: countryCode2 + #- name: GeoCoordTestField # type: latLong @@ -127,9 +130,6 @@ domain: #- name: BooleanTestField # type: boolean - #- name: CountryCode2TestField - # type: countryCode2 - #- name: CountryCode3TestField # type: countryCode3 diff --git a/tests/Nox.Generator.Tests/Database/EntityFrameworkTests.cs b/tests/Nox.Generator.Tests/Database/EntityFrameworkSqliteTests.cs similarity index 92% rename from tests/Nox.Generator.Tests/Database/EntityFrameworkTests.cs rename to tests/Nox.Generator.Tests/Database/EntityFrameworkSqliteTests.cs index 36189fba98..92f4777469 100644 --- a/tests/Nox.Generator.Tests/Database/EntityFrameworkTests.cs +++ b/tests/Nox.Generator.Tests/Database/EntityFrameworkSqliteTests.cs @@ -1,13 +1,13 @@ using FluentAssertions; using Nox.Types; using NoxSourceGeneratorTests.DatabaseTests; -using SampleWebApp.Domain; using System.Linq; +using TestDatabaseWebApp.Domain; using Xunit; namespace Nox.Generator.Test.DatabaseTests; -public class EntityFrameworkTests : SqliteTestBase +public class EntityFrameworkSqliteTests : SqliteTestBase { [Fact] public void GeneratedEntity_CanSaveAndReadFields_AllTypes() @@ -54,7 +54,7 @@ public void GeneratedEntity_CanSaveAndReadFields_AllTypes() Id = Text.From(text), TextTestField = Text.From(text), NumberTestField = Number.From(number), - MoneyTestField = Money.From(money, currencyCode) + MoneyTestField = Money.From(money, currencyCode), }; DbContext.TestEntities.Add(newItem); DbContext.SaveChanges(); diff --git a/tests/Nox.Generator.Tests/Database/Models/AuditableEntityBase.cs b/tests/Nox.Generator.Tests/Database/Models/AuditableEntityBase.cs index 4ac2729b85..f76e75eed7 100644 --- a/tests/Nox.Generator.Tests/Database/Models/AuditableEntityBase.cs +++ b/tests/Nox.Generator.Tests/Database/Models/AuditableEntityBase.cs @@ -4,7 +4,7 @@ using System; -namespace SampleWebApp.Domain; +namespace TestDatabaseWebApp.Domain; public partial class AuditableEntityBase { diff --git a/tests/Nox.Generator.Tests/Database/Models/SampleWebAppDbContext.cs b/tests/Nox.Generator.Tests/Database/Models/TestDatabaseWebAppDbContext.g.cs similarity index 73% rename from tests/Nox.Generator.Tests/Database/Models/SampleWebAppDbContext.cs rename to tests/Nox.Generator.Tests/Database/Models/TestDatabaseWebAppDbContext.g.cs index 30a17685eb..0dc5cd59d3 100644 --- a/tests/Nox.Generator.Tests/Database/Models/SampleWebAppDbContext.cs +++ b/tests/Nox.Generator.Tests/Database/Models/TestDatabaseWebAppDbContext.g.cs @@ -6,18 +6,18 @@ using Microsoft.Extensions.DependencyInjection; using Nox.Solution; using Nox.Types.EntityFramework.vNext; -using SampleWebApp.Domain; using System; +using TestDatabaseWebApp.Domain; -namespace SampleWebApp.Infrastructure.Persistence; +namespace TestDatabaseWebApp.Infrastructure.Persistence; -public partial class SampleWebAppDbContext : DbContext +public partial class TestDatabaseWebAppDbContext : DbContext { private NoxSolution _noxSolution { get; set; } private INoxDatabaseConfigurator _databaseConfigurator { get; set; } - public SampleWebAppDbContext( - DbContextOptions options, + public TestDatabaseWebAppDbContext( + DbContextOptions options, NoxSolution noxSolution, INoxDatabaseConfigurator databaseConfigurator ) : base(options) @@ -31,7 +31,7 @@ INoxDatabaseConfigurator databaseConfigurator public static void RegisterDbContext(IServiceCollection services) { - services.AddDbContext(); + services.AddDbContext(); } protected override void OnModelCreating(ModelBuilder modelBuilder) @@ -40,13 +40,14 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { foreach (var entity in _noxSolution.Domain.Entities) { - var type = Type.GetType("SampleWebApp.Domain." + entity.Name); + var type = Type.GetType("TestDatabaseWebApp.Domain." + entity.Name); if (type != null) { _databaseConfigurator.ConfigureEntity(modelBuilder.Entity(type), entity); } } + } base.OnModelCreating(modelBuilder); diff --git a/tests/Nox.Generator.Tests/Database/Models/TestEntity.cs b/tests/Nox.Generator.Tests/Database/Models/TestEntity.cs index 417c770928..b08f576244 100644 --- a/tests/Nox.Generator.Tests/Database/Models/TestEntity.cs +++ b/tests/Nox.Generator.Tests/Database/Models/TestEntity.cs @@ -6,7 +6,7 @@ using System; using System.Collections.Generic; -namespace SampleWebApp.Domain; +namespace TestDatabaseWebApp.Domain; /// /// Entity created for testing database. diff --git a/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs b/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs index 37881a7272..00e23b92e0 100644 --- a/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs +++ b/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs @@ -2,20 +2,20 @@ using Microsoft.EntityFrameworkCore; using Nox.Solution; using Nox.Types.EntityFramework.Sqlite; -using SampleWebApp.Infrastructure.Persistence; using System; +using TestDatabaseWebApp.Infrastructure.Persistence; namespace NoxSourceGeneratorTests.DatabaseTests; public abstract class SqliteTestBase : IDisposable { - private const string _inMemoryConnectionStringTemplate = "DataSource=:memory:"; - //private const string _inMemoryConnectionStringTemplate = @"DataSource=test_database_{0}.db"; + //private const string _inMemoryConnectionStringTemplate = "DataSource=:memory:"; + private const string _inMemoryConnectionStringTemplate = @"DataSource=test_database_{0}.db"; private static string _inMemoryConnectionString = string.Empty; - private const string _testSolutionFile = @"../../../Database/Design/test.solution.nox.yaml"; + private const string _testSolutionFile = @"./test.solution.nox.yaml"; private readonly SqliteConnection _connection; - protected SampleWebAppDbContext DbContext; + protected TestDatabaseWebAppDbContext DbContext; protected SqliteTestBase() { @@ -25,16 +25,16 @@ protected SqliteTestBase() DbContext = CreateDbContext(_connection); } - private static SampleWebAppDbContext CreateDbContext(SqliteConnection connection) + private static TestDatabaseWebAppDbContext CreateDbContext(SqliteConnection connection) { var databaseConfigurator = new SqliteDatabaseConfigurator(); var solution = new NoxSolutionBuilder() .UseYamlFile(_testSolutionFile) .Build(); - var options = new DbContextOptionsBuilder() + var options = new DbContextOptionsBuilder() .UseSqlite(connection) .Options; - var dbContext = new SampleWebAppDbContext(options, solution, databaseConfigurator); + var dbContext = new TestDatabaseWebAppDbContext(options, solution, databaseConfigurator); dbContext.Database.EnsureCreated(); return dbContext; } diff --git a/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj b/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj index f1007b32a8..a2f5675bd1 100644 --- a/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj +++ b/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj @@ -81,7 +81,9 @@ - + + Always + Always From 8ad8be9a2dff4fa345bcd041f0be31edb8293188 Mon Sep 17 00:00:00 2001 From: Dmytro Dorodnykh Date: Wed, 5 Jul 2023 13:39:07 +0300 Subject: [PATCH 6/9] fix relative path --- tests/Nox.Generator.Tests/Database/SqliteTestBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs b/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs index 00e23b92e0..7a2998941d 100644 --- a/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs +++ b/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs @@ -12,7 +12,7 @@ public abstract class SqliteTestBase : IDisposable //private const string _inMemoryConnectionStringTemplate = "DataSource=:memory:"; private const string _inMemoryConnectionStringTemplate = @"DataSource=test_database_{0}.db"; private static string _inMemoryConnectionString = string.Empty; - private const string _testSolutionFile = @"./test.solution.nox.yaml"; + private const string _testSolutionFile = @"./Database/Design/test.solution.nox.yaml"; private readonly SqliteConnection _connection; protected TestDatabaseWebAppDbContext DbContext; From a10a0baeedb03d27f540c7be28d009a02d233b8b Mon Sep 17 00:00:00 2001 From: Dmytro Dorodnykh Date: Wed, 5 Jul 2023 13:40:23 +0300 Subject: [PATCH 7/9] rename sqlite test file --- .../{EntityFrameworkSqliteTests.cs => SqliteIntegrationTests.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/Nox.Generator.Tests/Database/{EntityFrameworkSqliteTests.cs => SqliteIntegrationTests.cs} (100%) diff --git a/tests/Nox.Generator.Tests/Database/EntityFrameworkSqliteTests.cs b/tests/Nox.Generator.Tests/Database/SqliteIntegrationTests.cs similarity index 100% rename from tests/Nox.Generator.Tests/Database/EntityFrameworkSqliteTests.cs rename to tests/Nox.Generator.Tests/Database/SqliteIntegrationTests.cs From 5f43db94f0f4c0ea931f1a2f04338afcf8e6a9dc Mon Sep 17 00:00:00 2001 From: Dmytro Dorodnykh Date: Wed, 5 Jul 2023 13:42:34 +0300 Subject: [PATCH 8/9] fix space vs tabs --- tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj b/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj index a2f5675bd1..5522aa9b93 100644 --- a/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj +++ b/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj @@ -35,8 +35,8 @@ - - + + From 45e8dcfafda5ec1db4f8c792efcb985f8d5962e0 Mon Sep 17 00:00:00 2001 From: Dmytro Dorodnykh Date: Wed, 5 Jul 2023 13:46:34 +0300 Subject: [PATCH 9/9] rename test --- tests/Nox.Generator.Tests/Database/SqliteIntegrationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Nox.Generator.Tests/Database/SqliteIntegrationTests.cs b/tests/Nox.Generator.Tests/Database/SqliteIntegrationTests.cs index 92f4777469..7fcd9dc9c6 100644 --- a/tests/Nox.Generator.Tests/Database/SqliteIntegrationTests.cs +++ b/tests/Nox.Generator.Tests/Database/SqliteIntegrationTests.cs @@ -7,7 +7,7 @@ namespace Nox.Generator.Test.DatabaseTests; -public class EntityFrameworkSqliteTests : SqliteTestBase +public class SqliteIntegrationTests : SqliteTestBase { [Fact] public void GeneratedEntity_CanSaveAndReadFields_AllTypes()