From 34a9012046f4ec9a29f4f766f2d4356fa7a3666d Mon Sep 17 00:00:00 2001 From: Pim Brouwers Date: Fri, 6 Dec 2024 16:47:21 -0500 Subject: [PATCH] validationoption tests fix --- examples/Danom.Samples.sln | 22 +++++ .../Mvc/Danom.Examples.Mvc.csproj | 0 .../Mvc/Features/Home/HomeController.cs | 2 +- .../Mvc/Features/Home/Index.cshtml | 0 .../Mvc/Features/Option/Detail.cshtml | 0 .../Mvc/Features/Option/OptionController.cs | 2 +- .../Mvc/Features/Result/Detail.cshtml | 0 .../Mvc/Features/Result/ResultController.cs | 2 +- .../Mvc/Features/ResultOption/Detail.cshtml | 0 .../ResultOption/ResultOptionController.cs | 2 +- .../Mvc/Features/Shared/Default.cshtml | 0 .../Mvc/Features/_ViewImports.cshtml | 0 .../Mvc/Features/_ViewStart.cshtml | 0 {samples => examples}/Mvc/Program.cs | 0 {samples => examples}/Mvc/appsettings.json | 0 examples/Todo/Danom.Examples.Todo.csproj | 19 ++++ examples/Todo/Features/Shared/Default.cshtml | 11 +++ examples/Todo/Features/Todo/CompleteTodo.cs | 18 ++++ examples/Todo/Features/Todo/CreateTodo.cs | 19 ++++ examples/Todo/Features/Todo/DeleteTodo.cs | 18 ++++ examples/Todo/Features/Todo/GetTodo.cs | 17 ++++ examples/Todo/Features/Todo/Index.cshtml | 29 ++++++ examples/Todo/Features/Todo/ListTodo.cs | 24 +++++ examples/Todo/Features/Todo/TodoController.cs | 62 +++++++++++++ examples/Todo/Features/Todo/TodoModel.cs | 92 +++++++++++++++++++ examples/Todo/Features/Todo/TodoStore.cs | 88 ++++++++++++++++++ examples/Todo/Features/_ViewImports.cshtml | 4 + examples/Todo/Features/_ViewStart.cshtml | 3 + .../Infrastructure/TodoConnectionFactory.cs | 12 +++ examples/Todo/Program.cs | 27 ++++++ .../Todo/appsettings.json | 3 +- .../Danom.Examples.Validation.csproj | 0 {samples => examples}/Validation/Program.cs | 0 samples/Mvc/Properties/launchSettings.json | 14 --- .../ValidationOptionTests.cs | 4 +- 35 files changed, 473 insertions(+), 21 deletions(-) create mode 100644 examples/Danom.Samples.sln rename samples/Mvc/Danom.Samples.Mvc.csproj => examples/Mvc/Danom.Examples.Mvc.csproj (100%) rename {samples => examples}/Mvc/Features/Home/HomeController.cs (82%) rename {samples => examples}/Mvc/Features/Home/Index.cshtml (100%) rename {samples => examples}/Mvc/Features/Option/Detail.cshtml (100%) rename {samples => examples}/Mvc/Features/Option/OptionController.cs (96%) rename {samples => examples}/Mvc/Features/Result/Detail.cshtml (100%) rename {samples => examples}/Mvc/Features/Result/ResultController.cs (96%) rename {samples => examples}/Mvc/Features/ResultOption/Detail.cshtml (100%) rename {samples => examples}/Mvc/Features/ResultOption/ResultOptionController.cs (97%) rename {samples => examples}/Mvc/Features/Shared/Default.cshtml (100%) rename {samples => examples}/Mvc/Features/_ViewImports.cshtml (100%) rename {samples => examples}/Mvc/Features/_ViewStart.cshtml (100%) rename {samples => examples}/Mvc/Program.cs (100%) rename {samples => examples}/Mvc/appsettings.json (100%) create mode 100644 examples/Todo/Danom.Examples.Todo.csproj create mode 100644 examples/Todo/Features/Shared/Default.cshtml create mode 100644 examples/Todo/Features/Todo/CompleteTodo.cs create mode 100644 examples/Todo/Features/Todo/CreateTodo.cs create mode 100644 examples/Todo/Features/Todo/DeleteTodo.cs create mode 100644 examples/Todo/Features/Todo/GetTodo.cs create mode 100644 examples/Todo/Features/Todo/Index.cshtml create mode 100644 examples/Todo/Features/Todo/ListTodo.cs create mode 100644 examples/Todo/Features/Todo/TodoController.cs create mode 100644 examples/Todo/Features/Todo/TodoModel.cs create mode 100644 examples/Todo/Features/Todo/TodoStore.cs create mode 100644 examples/Todo/Features/_ViewImports.cshtml create mode 100644 examples/Todo/Features/_ViewStart.cshtml create mode 100644 examples/Todo/Infrastructure/TodoConnectionFactory.cs create mode 100644 examples/Todo/Program.cs rename samples/Mvc/appsettings.Development.json => examples/Todo/appsettings.json (80%) rename samples/Validation/Danom.Samples.Validation.csproj => examples/Validation/Danom.Examples.Validation.csproj (100%) rename {samples => examples}/Validation/Program.cs (100%) delete mode 100644 samples/Mvc/Properties/launchSettings.json diff --git a/examples/Danom.Samples.sln b/examples/Danom.Samples.sln new file mode 100644 index 0000000..fe8b068 --- /dev/null +++ b/examples/Danom.Samples.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Danom.Examples.Todo", "Todo\Danom.Examples.Todo.csproj", "{47A6898A-F004-47B6-94BD-9C5A064FDCC4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {47A6898A-F004-47B6-94BD-9C5A064FDCC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {47A6898A-F004-47B6-94BD-9C5A064FDCC4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {47A6898A-F004-47B6-94BD-9C5A064FDCC4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {47A6898A-F004-47B6-94BD-9C5A064FDCC4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/samples/Mvc/Danom.Samples.Mvc.csproj b/examples/Mvc/Danom.Examples.Mvc.csproj similarity index 100% rename from samples/Mvc/Danom.Samples.Mvc.csproj rename to examples/Mvc/Danom.Examples.Mvc.csproj diff --git a/samples/Mvc/Features/Home/HomeController.cs b/examples/Mvc/Features/Home/HomeController.cs similarity index 82% rename from samples/Mvc/Features/Home/HomeController.cs rename to examples/Mvc/Features/Home/HomeController.cs index 986b107..8f81f51 100644 --- a/samples/Mvc/Features/Home/HomeController.cs +++ b/examples/Mvc/Features/Home/HomeController.cs @@ -1,4 +1,4 @@ -namespace Danom.Samples.Mvc; +namespace Danom.Examples.Mvc; using Microsoft.AspNetCore.Mvc; diff --git a/samples/Mvc/Features/Home/Index.cshtml b/examples/Mvc/Features/Home/Index.cshtml similarity index 100% rename from samples/Mvc/Features/Home/Index.cshtml rename to examples/Mvc/Features/Home/Index.cshtml diff --git a/samples/Mvc/Features/Option/Detail.cshtml b/examples/Mvc/Features/Option/Detail.cshtml similarity index 100% rename from samples/Mvc/Features/Option/Detail.cshtml rename to examples/Mvc/Features/Option/Detail.cshtml diff --git a/samples/Mvc/Features/Option/OptionController.cs b/examples/Mvc/Features/Option/OptionController.cs similarity index 96% rename from samples/Mvc/Features/Option/OptionController.cs rename to examples/Mvc/Features/Option/OptionController.cs index 8aafc83..fa7e1da 100644 --- a/samples/Mvc/Features/Option/OptionController.cs +++ b/examples/Mvc/Features/Option/OptionController.cs @@ -1,4 +1,4 @@ -namespace Danom.Samples.Mvc; +namespace Danom.Examples.Mvc; using Danom.Mvc; using Microsoft.AspNetCore.Mvc; diff --git a/samples/Mvc/Features/Result/Detail.cshtml b/examples/Mvc/Features/Result/Detail.cshtml similarity index 100% rename from samples/Mvc/Features/Result/Detail.cshtml rename to examples/Mvc/Features/Result/Detail.cshtml diff --git a/samples/Mvc/Features/Result/ResultController.cs b/examples/Mvc/Features/Result/ResultController.cs similarity index 96% rename from samples/Mvc/Features/Result/ResultController.cs rename to examples/Mvc/Features/Result/ResultController.cs index 20e35c8..8ef262d 100644 --- a/samples/Mvc/Features/Result/ResultController.cs +++ b/examples/Mvc/Features/Result/ResultController.cs @@ -1,4 +1,4 @@ -namespace Danom.Samples.Mvc; +namespace Danom.Examples.Mvc; using Danom.Mvc; using Microsoft.AspNetCore.Mvc; diff --git a/samples/Mvc/Features/ResultOption/Detail.cshtml b/examples/Mvc/Features/ResultOption/Detail.cshtml similarity index 100% rename from samples/Mvc/Features/ResultOption/Detail.cshtml rename to examples/Mvc/Features/ResultOption/Detail.cshtml diff --git a/samples/Mvc/Features/ResultOption/ResultOptionController.cs b/examples/Mvc/Features/ResultOption/ResultOptionController.cs similarity index 97% rename from samples/Mvc/Features/ResultOption/ResultOptionController.cs rename to examples/Mvc/Features/ResultOption/ResultOptionController.cs index 0cc46ae..8790a96 100644 --- a/samples/Mvc/Features/ResultOption/ResultOptionController.cs +++ b/examples/Mvc/Features/ResultOption/ResultOptionController.cs @@ -1,4 +1,4 @@ -namespace Danom.Samples.Mvc; +namespace Danom.Examples.Mvc; using Danom.Mvc; using Microsoft.AspNetCore.Mvc; diff --git a/samples/Mvc/Features/Shared/Default.cshtml b/examples/Mvc/Features/Shared/Default.cshtml similarity index 100% rename from samples/Mvc/Features/Shared/Default.cshtml rename to examples/Mvc/Features/Shared/Default.cshtml diff --git a/samples/Mvc/Features/_ViewImports.cshtml b/examples/Mvc/Features/_ViewImports.cshtml similarity index 100% rename from samples/Mvc/Features/_ViewImports.cshtml rename to examples/Mvc/Features/_ViewImports.cshtml diff --git a/samples/Mvc/Features/_ViewStart.cshtml b/examples/Mvc/Features/_ViewStart.cshtml similarity index 100% rename from samples/Mvc/Features/_ViewStart.cshtml rename to examples/Mvc/Features/_ViewStart.cshtml diff --git a/samples/Mvc/Program.cs b/examples/Mvc/Program.cs similarity index 100% rename from samples/Mvc/Program.cs rename to examples/Mvc/Program.cs diff --git a/samples/Mvc/appsettings.json b/examples/Mvc/appsettings.json similarity index 100% rename from samples/Mvc/appsettings.json rename to examples/Mvc/appsettings.json diff --git a/examples/Todo/Danom.Examples.Todo.csproj b/examples/Todo/Danom.Examples.Todo.csproj new file mode 100644 index 0000000..9456d2e --- /dev/null +++ b/examples/Todo/Danom.Examples.Todo.csproj @@ -0,0 +1,19 @@ + + + + net9.0 + enable + enable + + + + + + + + + + + + + diff --git a/examples/Todo/Features/Shared/Default.cshtml b/examples/Todo/Features/Shared/Default.cshtml new file mode 100644 index 0000000..05cc237 --- /dev/null +++ b/examples/Todo/Features/Shared/Default.cshtml @@ -0,0 +1,11 @@ + + + + + + Document + + + @RenderBody() + + diff --git a/examples/Todo/Features/Todo/CompleteTodo.cs b/examples/Todo/Features/Todo/CompleteTodo.cs new file mode 100644 index 0000000..8a391df --- /dev/null +++ b/examples/Todo/Features/Todo/CompleteTodo.cs @@ -0,0 +1,18 @@ +namespace Danom.Examples.Todo; + +using Danom; +using Danom.Validation; + +public sealed record CompleteTodoCommand( + int TodoId); + +public sealed class CompleteTodoCommandHandler( + Func completeTodo) +{ + public Result Handle(CompleteTodoCommand command) => + ValidationResult + .From( + new(TodoId: new(command.TodoId), + CompletedDate: DateTime.UtcNow)) + .Map(completeTodo); +} diff --git a/examples/Todo/Features/Todo/CreateTodo.cs b/examples/Todo/Features/Todo/CreateTodo.cs new file mode 100644 index 0000000..599b1fe --- /dev/null +++ b/examples/Todo/Features/Todo/CreateTodo.cs @@ -0,0 +1,19 @@ +namespace Danom.Examples.Todo; + +using Danom; +using Danom.Validation; + +public sealed record CreateTodoCommand( + string Title, + DateOnly? DueDate); + +public sealed class CreateTodoCommandHandler( + Func createTodo) +{ + public Result Handle(CreateTodoCommand command) => + ValidationResult + .From( + new(Title: command.Title, + DueDate: command.DueDate.ToOption())) + .Map(createTodo); +} diff --git a/examples/Todo/Features/Todo/DeleteTodo.cs b/examples/Todo/Features/Todo/DeleteTodo.cs new file mode 100644 index 0000000..4c769e1 --- /dev/null +++ b/examples/Todo/Features/Todo/DeleteTodo.cs @@ -0,0 +1,18 @@ +namespace Danom.Examples.Todo; + +using Danom; +using Danom.Validation; + +public sealed record DeleteTodoCommand( + int TodoId); + +public sealed class DeleteTodoCommandHandler( + Func deleteTodo) +{ + public Result Handle(DeleteTodoCommand command) => + ValidationResult + .From( + new(TodoId: new(command.TodoId), + DeletedDate: DateTime.UtcNow)) + .Map(deleteTodo); +} diff --git a/examples/Todo/Features/Todo/GetTodo.cs b/examples/Todo/Features/Todo/GetTodo.cs new file mode 100644 index 0000000..1f15adc --- /dev/null +++ b/examples/Todo/Features/Todo/GetTodo.cs @@ -0,0 +1,17 @@ +namespace Danom.Examples.Todo; + +using Danom; +using Danom.Validation; + +public sealed record GetTodoQuery( + int TodoId); + +public sealed class GetTodoQueryHandler( + Func> getTodo) +{ + public Option Handle(GetTodoQuery query) => + ValidationResult + .From(new(query.TodoId)) + .Map(getTodo) + .DefaultWith(Option.None); +} diff --git a/examples/Todo/Features/Todo/Index.cshtml b/examples/Todo/Features/Todo/Index.cshtml new file mode 100644 index 0000000..f963365 --- /dev/null +++ b/examples/Todo/Features/Todo/Index.cshtml @@ -0,0 +1,29 @@ +@model TodoList + +

Todo MVC

+ + + +@if(Model.Incomplete.Any()) +{ +
    + @foreach(var todo in Model.Incomplete) + { +
  • @todo.Title
  • + } +
+} + +@if(Model.Complete.Any()) +{ +

Completed

+ +
    + @foreach(var todo in Model.Complete) + { +
  • @todo.Title (Completed:@todo.CompletedDate.Map(x => x.ToLocalTime().ToString()).DefaultValue("-"))
  • + } +
+} diff --git a/examples/Todo/Features/Todo/ListTodo.cs b/examples/Todo/Features/Todo/ListTodo.cs new file mode 100644 index 0000000..9d6e8a0 --- /dev/null +++ b/examples/Todo/Features/Todo/ListTodo.cs @@ -0,0 +1,24 @@ +namespace Danom.Examples.Todo; + +using Danom; + +public sealed class ListTodoQueryHandler( + Func> getAllTodos) +{ + public Option Handle() + { + var todos = getAllTodos(); + if (todos.Any()) + { + var todoList = new TodoList( + Incomplete: todos.Where(x => x.CompletedDate.IsNone), + Complete: todos.Where(x => x.CompletedDate.IsSome)); + + return Option.Some(todoList); + } + else + { + return Option.None(); + } + } +} diff --git a/examples/Todo/Features/Todo/TodoController.cs b/examples/Todo/Features/Todo/TodoController.cs new file mode 100644 index 0000000..1596912 --- /dev/null +++ b/examples/Todo/Features/Todo/TodoController.cs @@ -0,0 +1,62 @@ +namespace Danom.Examples.Todo; + +using Danom; +using Danom.Mvc; +using Microsoft.AspNetCore.Mvc; + +public sealed class TodoController( + TodoStore todo) : DanomController +{ + [Route("/")] + [Route("/todo")] + public IActionResult Index() + { + var result = new ListTodoQueryHandler(todo.GetAll).Handle(); + return ViewOption(result); + } + + [HttpGet("/todo/create")] + public IActionResult Create() => + View(); + + [HttpPost("/todo/create")] + public IActionResult Create(CreateTodoCommand command) + { + var result = new CreateTodoCommandHandler(todo.Create).Handle(command); + return result.Match( + ok: _ => RedirectToAction(nameof(Index)), + error: e => ViewResultErrors(e)); + } + + [HttpGet("/todo/complete/{id}")] + public IActionResult Complete(GetTodoQuery query) + { + var result = new GetTodoQueryHandler(todo.Get).Handle(query); + return ViewOption(result); + } + + [HttpPost("/todo/complete/{id}")] + public IActionResult Complete(CompleteTodoCommand command) + { + var result = new CompleteTodoCommandHandler(todo.Complete).Handle(command); + return result.Match( + ok: _ => RedirectToAction(nameof(Index)), + error: e => ViewResultErrors(e)); + } + + [HttpGet("/todo/delete/{id}")] + public IActionResult Delete(GetTodoQuery query) + { + var result = new GetTodoQueryHandler(todo.Get).Handle(query); + return ViewOption(result); + } + + [HttpPost("/todo/delete/{id}")] + public IActionResult Delete(DeleteTodoCommand command) + { + var result = new DeleteTodoCommandHandler(todo.Delete).Handle(command); + return result.Match( + ok: _ => RedirectToAction(nameof(Index)), + error: e => ViewResultErrors(e)); + } +} diff --git a/examples/Todo/Features/Todo/TodoModel.cs b/examples/Todo/Features/Todo/TodoModel.cs new file mode 100644 index 0000000..eb17a59 --- /dev/null +++ b/examples/Todo/Features/Todo/TodoModel.cs @@ -0,0 +1,92 @@ +namespace Danom.Examples.Todo; + +using Danom; +using Danom.Validation; +using FluentValidation; + +public sealed class TodoId(int value) +{ + internal readonly int _value = value; + public static explicit operator int(TodoId todoId) => + todoId._value; +} + +public sealed class TodoIdValidator : AbstractValidator +{ + public TodoIdValidator() + { + RuleFor(todoId => (int)todoId).GreaterThan(0); + } +} + +public sealed record Todo( + TodoId TodoId, + string Title, + Option DueDate, + Option CompletedDate); + +public sealed record TodoList( + IEnumerable Incomplete, + IEnumerable Complete); + +// +// Create + +public sealed record CreateTodo( + string Title, + Option DueDate); + +public sealed class CreateTodoValidator : AbstractValidator +{ + public CreateTodoValidator() + { + RuleFor(x => x.Title) + .NotEmpty() + .MaximumLength(256); + + RuleFor(x => x.DueDate) + .Optional(x => + x.GreaterThan(DateOnly.FromDateTime(DateTime.Now.Date))); + } +} + + +// +// Update + +public sealed record CompleteTodo( + TodoId TodoId, + DateTime CompletedDate); + +public sealed class CompleteTodoValidator : AbstractValidator +{ + public CompleteTodoValidator() + { + RuleFor(x => x.TodoId) + .SetValidator(new TodoIdValidator()); + + RuleFor(x => x.CompletedDate) + .NotEmpty() + .GreaterThanOrEqualTo(DateTime.Now); + } +} + + +// +// Delete + +public sealed record DeleteTodo( + TodoId TodoId, + DateTime DeletedDate); + +public sealed class DeleteTodoValidator : AbstractValidator +{ + public DeleteTodoValidator() + { + RuleFor(x => x.TodoId) + .SetValidator(new TodoIdValidator()); + + RuleFor(x => x.DeletedDate) + .NotEmpty(); + } +} diff --git a/examples/Todo/Features/Todo/TodoStore.cs b/examples/Todo/Features/Todo/TodoStore.cs new file mode 100644 index 0000000..1edf93a --- /dev/null +++ b/examples/Todo/Features/Todo/TodoStore.cs @@ -0,0 +1,88 @@ +namespace Danom.Examples.Todo; + +using System.Data; +using Danom; +using Leger; + +public static class TodoReader +{ + public static Todo Map(IDataReader rd) => + new(TodoId: new(rd.ReadInt("todo_id")), + Title: rd.ReadString("title"), + DueDate: rd.ReadNullableDateOnly("due_date").ToOption(), + CompletedDate: rd.ReadNullableDateTime("completed_date").ToOption()); +} +public sealed class TodoStore( + IDbConnectionFactory db) +{ + public IEnumerable GetAll() => + db.Query(""" + SELECT todo_id + , title + , due_date + , completed_date + FROM todo + WHERE deleted_date IS NULL + """, + TodoReader.Map); + + public Option Get(TodoId todoId) => + db.QuerySingle(""" + SELECT todo_id + , title + , due_date + , completed_date + FROM todo + WHERE todo_id = @todo_id + """, + new DbParams("todo_id", (int)todoId), + TodoReader.Map) + .ToOption(); + + public Unit Create(CreateTodo input) + { + db.Execute(""" + INSERT INTO todo (title, due_date) + VALUES (@title, @due_date); + """, + new DbParams() + { + { "title", input.Title }, + { "due_date", input.DueDate.ToNullable() } + }); + + return Unit.Value; + } + + public Unit Complete(CompleteTodo input) + { + db.Execute(""" + UPDATE todo + SET completed_date = @completed_date + WHERE todo_id = @todo_id; + """, + new DbParams() + { + { "todo_id", (int)input.TodoId }, + { "completed_date", input.CompletedDate } + }); + + return Unit.Value; + } + + public Unit Delete(DeleteTodo input) + { + db.Execute(""" + UPDATE todo + SET deleted_date = @deleted_date + WHERE todo_id = @todo_id; + """, + new DbParams() + { + { "todo_id", (int)input.TodoId }, + { "deleted_date", input.DeletedDate } + }); + + return Unit.Value; + } +} diff --git a/examples/Todo/Features/_ViewImports.cshtml b/examples/Todo/Features/_ViewImports.cshtml new file mode 100644 index 0000000..f6c4cc6 --- /dev/null +++ b/examples/Todo/Features/_ViewImports.cshtml @@ -0,0 +1,4 @@ +@using Danom +@using Danom.Examples.Todo + +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/examples/Todo/Features/_ViewStart.cshtml b/examples/Todo/Features/_ViewStart.cshtml new file mode 100644 index 0000000..c9684ef --- /dev/null +++ b/examples/Todo/Features/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "Default"; +} diff --git a/examples/Todo/Infrastructure/TodoConnectionFactory.cs b/examples/Todo/Infrastructure/TodoConnectionFactory.cs new file mode 100644 index 0000000..4842860 --- /dev/null +++ b/examples/Todo/Infrastructure/TodoConnectionFactory.cs @@ -0,0 +1,12 @@ +namespace Danom.Examples.Todo.Infrastructure; + +using System.Data; +using Leger; +using System.Data.SQLite; + +public sealed class TodoConnectionFactory(string connectionString) + : IDbConnectionFactory +{ + public IDbConnection CreateConnection() => + new SQLiteConnection(connectionString); +} diff --git a/examples/Todo/Program.cs b/examples/Todo/Program.cs new file mode 100644 index 0000000..5bd08cb --- /dev/null +++ b/examples/Todo/Program.cs @@ -0,0 +1,27 @@ +using Danom.Examples.Todo; +using Danom.Examples.Todo.Infrastructure; +using Leger; + +var bldr = WebApplication.CreateBuilder(args); + +bldr.Services + .AddScoped(_ => + bldr.Configuration.GetConnectionString("default") is string connectionString ? + new TodoConnectionFactory(connectionString) : + throw new ArgumentNullException("Connection string is missing")) + .AddScoped() + .AddControllersWithViews() + .AddRazorOptions(o => + { + // Enable the use of the Features folder + o.ViewLocationFormats.Add("/Features/Shared/{0}.cshtml"); + o.ViewLocationFormats.Add("/Features/{1}/{0}.cshtml"); + }); + +var wapp = bldr.Build(); + +wapp.MapDefaultControllerRoute(); + +wapp.Run(); + +public sealed class DbConnection diff --git a/samples/Mvc/appsettings.Development.json b/examples/Todo/appsettings.json similarity index 80% rename from samples/Mvc/appsettings.Development.json rename to examples/Todo/appsettings.json index 0c208ae..10f68b8 100644 --- a/samples/Mvc/appsettings.Development.json +++ b/examples/Todo/appsettings.json @@ -4,5 +4,6 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } - } + }, + "AllowedHosts": "*" } diff --git a/samples/Validation/Danom.Samples.Validation.csproj b/examples/Validation/Danom.Examples.Validation.csproj similarity index 100% rename from samples/Validation/Danom.Samples.Validation.csproj rename to examples/Validation/Danom.Examples.Validation.csproj diff --git a/samples/Validation/Program.cs b/examples/Validation/Program.cs similarity index 100% rename from samples/Validation/Program.cs rename to examples/Validation/Program.cs diff --git a/samples/Mvc/Properties/launchSettings.json b/samples/Mvc/Properties/launchSettings.json deleted file mode 100644 index ff2cb39..0000000 --- a/samples/Mvc/Properties/launchSettings.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", - "profiles": { - "https": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "applicationUrl": "https://localhost:5001", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} diff --git a/test/Danom.Validation.Tests/ValidationOptionTests.cs b/test/Danom.Validation.Tests/ValidationOptionTests.cs index a3e4c83..93b87b5 100644 --- a/test/Danom.Validation.Tests/ValidationOptionTests.cs +++ b/test/Danom.Validation.Tests/ValidationOptionTests.cs @@ -12,8 +12,8 @@ public void ReturnsSomeOption_WhenValidationSucceeds() var input = new TestInput { Value = 1 }; var result = ValidationOption.From(input); - AssertOption.IsNone(result); - Assert.False(result.IsSome); + AssertOption.IsSome(result); + Assert.False(result.IsNone); } [Fact]