From 902a2d3aa4cbe6989081c6ac90d50ea5179ec974 Mon Sep 17 00:00:00 2001 From: "Angel D. Munoz" Date: Sun, 1 Oct 2023 00:58:23 -0600 Subject: [PATCH] Fix tests and annotations --- src/Migrondi.Core/Database.fs | 3 ++- src/Migrondi.Core/Database.fsi | 5 +++++ src/Migrondi.Core/Migrondi.Core.fsproj | 4 +++- src/Migrondi.Tests/Database.Async.fs | 12 +++++------- src/Migrondi.Tests/Database.fs | 9 ++++----- src/Migrondi.Tests/FileSystem.fs | 10 ++++++++-- src/Migrondi.Tests/Migrondi.Tests.fsproj | 2 +- 7 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/Migrondi.Core/Database.fs b/src/Migrondi.Core/Database.fs index 0ec00db..fd2a3b8 100644 --- a/src/Migrondi.Core/Database.fs +++ b/src/Migrondi.Core/Database.fs @@ -150,6 +150,7 @@ type DatabaseService = [] ?cancellationToken: CancellationToken -> Task + [] module Queries = let createTable driver tableName = @@ -181,7 +182,7 @@ CREATE TABLE dbo.%s{tableName}( ); GO""" -module MigrationsImpl = +module internal MigrationsImpl = let inline private (=>) (a: string) b = a, box b diff --git a/src/Migrondi.Core/Database.fsi b/src/Migrondi.Core/Database.fsi index 0aa1279..2fb6320 100644 --- a/src/Migrondi.Core/Database.fsi +++ b/src/Migrondi.Core/Database.fsi @@ -1,6 +1,7 @@ namespace Migrondi.Core.Database open System.Collections.Generic +open System.Data open System.Runtime.InteropServices open System.Threading open System.Threading.Tasks @@ -135,6 +136,10 @@ type DatabaseService = migrations: Migration seq * [] ?cancellationToken: CancellationToken -> Task +module internal MigrationsImpl = + + val getConnection: connectionString: string * driver: MigrondiDriver -> IDbConnection + [] type DatabaseServiceFactory = /// diff --git a/src/Migrondi.Core/Migrondi.Core.fsproj b/src/Migrondi.Core/Migrondi.Core.fsproj index 4fb698d..35b410e 100644 --- a/src/Migrondi.Core/Migrondi.Core.fsproj +++ b/src/Migrondi.Core/Migrondi.Core.fsproj @@ -13,8 +13,10 @@ True true - Migrondi.Tests + + + diff --git a/src/Migrondi.Tests/Database.Async.fs b/src/Migrondi.Tests/Database.Async.fs index 6b71db2..3e7eded 100644 --- a/src/Migrondi.Tests/Database.Async.fs +++ b/src/Migrondi.Tests/Database.Async.fs @@ -5,6 +5,8 @@ open System.Threading.Tasks open Microsoft.VisualStudio.TestTools.UnitTesting +open Microsoft.Extensions.Logging + open RepoDb open FsToolkit.ErrorHandling @@ -14,9 +16,6 @@ open Migrondi.Core.Database open Migrondi.Tests.Database -open Serilog -open Serilog.Extensions.Logging - [] type DatabaseAsyncTests() = @@ -24,11 +23,10 @@ type DatabaseAsyncTests() = let dbName = Guid.NewGuid() let config = DatabaseData.getConfig dbName - let baseLogger = - LoggerConfiguration().MinimumLevel.Debug().WriteTo.Console().CreateLogger() + let loggerFactory = + LoggerFactory.Create(fun builder -> builder.SetMinimumLevel(LogLevel.Debug).AddSimpleConsole() |> ignore) - let loggerFactory = new SerilogLoggerFactory(baseLogger) - let logger = loggerFactory.CreateLogger("Migrondi:Tests.Database.Async") + let logger = loggerFactory.CreateLogger("Migrondi:Tests.Database") let databaseEnv = DatabaseServiceFactory.GetInstance(logger, DatabaseData.getConfig dbName) diff --git a/src/Migrondi.Tests/Database.fs b/src/Migrondi.Tests/Database.fs index d0c3b85..d5c536b 100644 --- a/src/Migrondi.Tests/Database.fs +++ b/src/Migrondi.Tests/Database.fs @@ -8,11 +8,11 @@ open RepoDb open FsToolkit.ErrorHandling +open Microsoft.Extensions.Logging + open Migrondi.Core open Migrondi.Core.Database -open Serilog -open Serilog.Extensions.Logging module DatabaseData = open System.Data @@ -91,10 +91,9 @@ type DatabaseTests() = let dbName = Guid.NewGuid() let config = DatabaseData.getConfig dbName - let baseLogger = - LoggerConfiguration().MinimumLevel.Debug().WriteTo.Console().CreateLogger() + let loggerFactory = + LoggerFactory.Create(fun builder -> builder.SetMinimumLevel(LogLevel.Debug).AddSimpleConsole() |> ignore) - let loggerFactory = new SerilogLoggerFactory(baseLogger) let logger = loggerFactory.CreateLogger("Migrondi:Tests.Database") let databaseEnv = diff --git a/src/Migrondi.Tests/FileSystem.fs b/src/Migrondi.Tests/FileSystem.fs index 173210f..cb867c1 100644 --- a/src/Migrondi.Tests/FileSystem.fs +++ b/src/Migrondi.Tests/FileSystem.fs @@ -1,6 +1,5 @@ module Migrondi.Tests.FileSystem - open System open System.IO open System.Threading.Tasks @@ -8,10 +7,11 @@ open Microsoft.VisualStudio.TestTools.UnitTesting open FSharp.UMX +open Microsoft.Extensions.Logging + open Migrondi.Core open Migrondi.Core.Serialization open Migrondi.Core.FileSystem -open Migrondi.Core.FileSystem.Units open FsToolkit.ErrorHandling @@ -77,9 +77,15 @@ type FileSystemTests() = let serializer = SerializerServiceFactory.GetInstance() + let loggerFactory = + LoggerFactory.Create(fun builder -> builder.SetMinimumLevel(LogLevel.Debug).AddSimpleConsole() |> ignore) + + let logger = loggerFactory.CreateLogger("Migrondi:Tests.Database") + let fileSystem = FileSystemServiceFactory.GetInstance( serializer, + logger, baseUri, Uri("fs-migrations/", UriKind.Relative) ) diff --git a/src/Migrondi.Tests/Migrondi.Tests.fsproj b/src/Migrondi.Tests/Migrondi.Tests.fsproj index 7c0aa81..5886c65 100644 --- a/src/Migrondi.Tests/Migrondi.Tests.fsproj +++ b/src/Migrondi.Tests/Migrondi.Tests.fsproj @@ -17,7 +17,7 @@ - +