Skip to content

Commit

Permalink
Refactored current attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
joaofx committed Mar 6, 2024
1 parent 9f7c42a commit 0ed2857
Show file tree
Hide file tree
Showing 113 changed files with 529 additions and 953 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.Extensions.Options;
using Miru.Currentable;
using Miru.Userfy;

namespace Corpo.Skeleton.Features;

public class CurrentHandler(
Current current,
AppDbContext db,
ICurrentUser currentUser,
IOptions<AppOptions> appOptions)
: ICurrentHandler
{
private readonly AppOptions _appOptions = appOptions.Value;

public async Task Handle<TRequest>(TRequest request, CancellationToken ct)
{
if (current.Loaded == false)
{
current.IsAuthenticated = currentUser.IsAuthenticated;

if (currentUser.IsAuthenticated)
{
current.User = await db.Users.ByIdAsync(currentUser.Id, ct);
}

current.AppOptions = _appOptions;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

<turbo-stream action="update" target="result">
<template>
<pre>@Model.Inspect()</pre>
@* <pre>@Model.Inspect()</pre> *@
</template>
</turbo-stream>
3 changes: 2 additions & 1 deletion samples/Corpo.Skeleton/src/Corpo.Skeleton/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Extensions.Hosting;
using Miru.Behaviors.BelongsToUser;
using Miru.Behaviors.TimeStamp;
using Miru.Currentable;
using Miru.Hosting;
using Miru.Queuing;
using Miru.Sqlite;
Expand All @@ -22,7 +23,7 @@ public void ConfigureServices(IServiceCollection services)

.AddDefaultPipeline<Startup>()

.AddCurrentAttributes<Current, CurrentAttributes>()
.AddCurrent<Current, CurrentHandler>()

.AddEfCoreSqlite<AppDbContext>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ public class CategoryEditPageTest : PageTest
[Test]
public void Can_edit_category()
{
var category = _.MakeSaving<Category>();

var category = _.Make<Category>();
_.Save(category);

_.Visit(new CategoryEdit.Query { Id = category.Id });

_.Form<CategoryEdit.Command>((f, command) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ public class CategoryListPageTest : PageTest
[Test]
public void Can_list_categories()
{
var categories = _.MakeManySaving<Category>();

var categories = _.MakeMany<Category>();
_.Save(categories);

_.Visit<CategoryList>();

_.ShouldHaveText("Category");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ public class CategoryShowPageTest : PageTest
[Test]
public void Can_show_category()
{
var category = _.MakeSaving<Category>();

var category = _.Make<Category>();
_.Save(category);

_.Visit(new CategoryShow.Query { Id = category.Id });

_.ShouldHaveText(category.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ public class TeamEditPageTest : PageTest
[Test]
public void Can_edit_team()
{
var team = _.MakeSaving<Team>();

var team = _.Make<Team>();
_.Save(team);

_.Visit(new TeamEdit.Query { Id = team.Id });

_.Form<TeamEdit.Command>((f, command) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
using Corpo.Skeleton.Domain;
using Corpo.Skeleton.Features.Teams;
using Miru;
using Miru.PageTesting;
using Miru.Testing;
using NUnit.Framework;

namespace Corpo.Skeleton.PageTests.Pages.Teams
namespace Corpo.Skeleton.PageTests.Pages.Teams;

public class TeamListPageTest : PageTest
{
public class TeamListPageTest : PageTest
[Test]
public void Can_list_teams()
{
[Test]
public void Can_list_teams()
{
var teams = _.MakeManySaving<Team>();
var teams = _.MakeMany<Team>();
_.Save(teams);

_.Visit<TeamList>();
_.Visit<TeamList>();

_.ShouldHaveText("Teams");
_.ShouldHaveText("Teams");

_.Display<TeamList.Result>(x =>
{
x.ShouldHave(m => m.Teams[0].Name, teams.At(0).Name);
});
}
_.Display<TeamList.Result>(x =>
{
x.ShouldHave(m => m.Teams[0].Name, teams.At(0).Name);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ public class TicketEditPageTest : PageTest
public void Can_edit_ticket()
{
// arrange
var ticket = _.MakeSaving<Ticket>();

var ticket = _.Make<Ticket>();
_.Save(ticket);

_.Visit(new TicketEdit.Query { Id = ticket.Id });

// act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public class CategoryEditTest : FeatureTest
public async Task Can_edit_category()
{
// arrange
var category = _.MakeSaving<Category>();
var category = _.Make<Category>();
await _.SaveAsync(category);

var command = _.Make<CategoryEdit.Command>(m => m.Id = category.Id);

// act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public class CategoryListTest : FeatureTest
public async Task Can_list_categories()
{
// arrange
var categories = _.MakeManySaving<Category>();
var categories = _.MakeMany<Category>(2);
await _.SaveAsync(categories);

// act
var result = await _.SendAsync(new CategoryList.Query());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public class CategoryShowTest : FeatureTest
public async Task Can_show_categories()
{
// arrange
var category = _.MakeSaving<Category>();
var category = _.Make<Category>();
await _.SaveAsync(category);

// act
var response = await _.SendAsync(new CategoryShow.Query { Id = category.Id });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public class TeamEditTest : FeatureTest
public async Task Can_edit_team()
{
// arrange
var team = _.MakeSaving<Team>();
var team = _.Make<Team>();
await _.SaveAsync(team);

var command = _.Make<TeamEdit.Command>(m => m.Id = team.Id);

// act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ public class TeamListTest : FeatureTest
public async Task Can_list_teams()
{
// arrange
var teams = _.MakeManySaving<Team>();

var teams = _.MakeMany<Team>();
await _.SaveAsync(teams);

// act
var result = await _.SendAsync(new TeamList.Query());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@

<div class="row justify-content-center mt-4">
<div class="col-md-8 alert alert-info" id="result">
<pre>@Model.Inspect()</pre>
@* <pre>@Model.Inspect()</pre> *@
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<template>
<div class="col-md-8 alert alert-warning" id="result">
<pre>Response at: @DateTime.Now</pre>
<pre>@Model.Inspect()</pre>
@* <pre>@Model.Inspect()</pre> *@
</div>
</template>
</turbo-stream>
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@

<div class="row justify-content-center mt-4">
<div class="col-md-8 alert alert-info" id="result">
<pre>@Model.Inspect()</pre>
@* <pre>@Model.Inspect()</pre> *@
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<template>
<div class="col-md-8 alert alert-warning" id="result">
<pre>Response at: @DateTime.Now</pre>
<pre>@Model.Inspect()</pre>
@* <pre>@Model.Inspect()</pre> *@
</div>
</template>
</turbo-stream>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<template>
<div class="col-md-8 alert alert-warning" id="result">
<pre>Response at: @DateTime.Now</pre>
<pre>@Model.Inspect()</pre>
@* <pre>@Model.Inspect()</pre> *@
</div>
</template>
</turbo-stream>
2 changes: 1 addition & 1 deletion scripts/StubsExport/SolutionStubExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override void Export()

private void SaveMapForNewSolution()
{
File.WriteAllText(Params.StubDir / "_New.yml", NewSolutionFiles.ToYml());
File.WriteAllText(Params.StubDir / "_New.yml", Yml.ToYml(NewSolutionFiles));

NewSolutionFiles.Clear();

Expand Down
25 changes: 25 additions & 0 deletions src/Miru.Core/Console2.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Diagnostics;
using Baseline;

namespace Miru.Core;

Expand Down Expand Up @@ -81,4 +83,27 @@ public static void BreakLine()
{
Console.WriteLine();
}

public static void Measure(Action action, string taskName = "Task")
{
Console.WriteLine($"{taskName} started");

var timer = new Stopwatch();
timer.Start();

action();

timer.Stop();
Console.WriteLine($"{taskName} executed in {timer.ElapsedMilliseconds} ms");
}

public static T Dump<T>(T value, string prefix = null)
{
if (prefix.IsNotEmpty())
Console.Write(prefix);

Console.WriteLine($"{value.GetType().GetName()}: {Environment.NewLine}{Yml.Dump(value)}");

return value;
}
}
2 changes: 1 addition & 1 deletion src/Miru.Core/Makers/NewMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static void New(this Maker m, string name)
m.Directory();
Console.WriteLine();

var map = Maker.ReadEmbedded("_New.yml").FromYml<Dictionary<string, string>>();
var map = Yml.FromYml<Dictionary<string, string>>(Maker.ReadEmbedded("_New.yml"));

foreach (var (key, stub) in map)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Miru.Core/Templates/CommandPageTest.stub
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ public class {{ input.Name }}{{ input.Action }}PageTest : PageTest
public void Can_{{ string.downcase input.Action }}_{{ string.downcase input.Name }}()
{
// arrange
var {{ string.downcase input.Name }} = _.MakeSaving<{{ input.Name }}>();

var {{ string.downcase input.Name }} = _.Make<{{ input.Name }}>();
_.Save({{ string.downcase input.Name }});

_.Visit(new {{ input.Name }}{{ input.Action }}.Query { Id = {{ string.downcase input.Name }}.Id });

// act
Expand Down
5 changes: 3 additions & 2 deletions src/Miru.Core/Templates/Crud-Edit-FeaturePageTest.stub
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ public class {{ input.Name }}{{ input.Action }}PageTest : PageTest
[Test]
public void Can_{{ string.downcase input.Action }}_{{ string.downcase input.Name }}()
{
var {{ string.downcase input.Name }} = _.MakeSaving<{{ input.Name }}>();

var {{ string.downcase input.Name }} = _.Make<{{ input.Name }}>();
_.Save({{ string.downcase input.Name }});

_.Visit(new {{ input.Name }}{{ input.Action }}.Query { Id = {{ string.downcase input.Name }}.Id });

_.Form<{{ input.Name }}{{ input.Action }}.Command>((f, command) =>
Expand Down
4 changes: 3 additions & 1 deletion src/Miru.Core/Templates/Crud-Edit-FeatureTest.stub
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public class {{ input.Name }}{{ input.Action }}Test : FeatureTest
public async Task Can_{{ string.downcase input.Action }}_{{ string.downcase input.Name }}()
{
// arrange
var {{ string.downcase input.Name }} = _.MakeSaving<{{ input.Name }}>();
var {{ string.downcase input.Name }} = _.Make<{{ input.Name }}>();
await _.SaveAsync({{ string.downcase input.Name }});

var command = _.Make<{{ input.Name }}{{ input.Action }}.Command>(m => m.Id = {{ string.downcase input.Name }}.Id);

// act
Expand Down
Loading

0 comments on commit 0ed2857

Please sign in to comment.