Skip to content

Instantly share code, notes, and snippets.

View stormwild's full-sized avatar
🏠
Working from home

Alexander R Torrijos stormwild

🏠
Working from home
View GitHub Profile
@stormwild
stormwild / ANSI.md
Created April 20, 2025 11:53 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@stormwild
stormwild / Program.cs
Created October 1, 2024 09:05 — forked from dj-nitehawk/Program.cs
Showing deprecated endpoint versions in Swagger
var bld = WebApplication.CreateBuilder();
bld.Services
.AddFastEndpoints()
.SwaggerDocument(o =>
{
o.DocumentSettings = s =>
{
s.DocumentName = "Initial Release";
s.Version = "v0";
};
@stormwild
stormwild / 1-BaseQuestion.cs
Created October 1, 2024 09:04 — forked from dj-nitehawk/1-BaseQuestion.cs
Validator inheritance for polymorphic DTOs.
[
JsonPolymorphic(TypeDiscriminatorPropertyName = "_t"),
JsonDerivedType(typeof(MultiChoiceQuestionRequest), "mcq"),
JsonDerivedType(typeof(RatingQuestionRequest), "rq")
]
public class BaseQuestionRequest
{
public int Id { get; set; }
}
@stormwild
stormwild / Program.cs
Created October 1, 2024 09:03 — forked from dj-nitehawk/Program.cs
Request DTO inheritance with Validator composition
public class BaseRequest
{
public string? Id { get; init; }
}
public class BaseRequestValidator : Validator<BaseRequest>
{
public BaseRequestValidator()
{
RuleFor(x => x.Id)
@stormwild
stormwild / Endpoint.cs
Created October 1, 2024 09:02 — forked from dj-nitehawk/Endpoint.cs
Unit testing an endpoint that publishes an event
[HttpGet("publish"), AllowAnonymous]
sealed class MyEndpoint : EndpointWithoutRequest
{
public override async Task HandleAsync(CancellationToken c)
{
var evnt = new MyEvent { Message = "hello!" };
await PublishAsync(evnt);
await SendAsync("all good!");
}
}
@stormwild
stormwild / Program.cs
Created October 1, 2024 09:02 — forked from dj-nitehawk/Program.cs
Unit testing an endpoint that executes a command
sealed class MyRequest
{
public int Id { get; set; }
}
public sealed class MyCommand : ICommand<int>
{
public string Identity { get; set; }
}
@stormwild
stormwild / AppFixture.cs
Created October 1, 2024 09:02 — forked from dj-nitehawk/AppFixture.cs
Integration testing with TestContainers & AppFixture
using Testcontainers.MongoDb;
public class Sut : AppFixture<Program>
{
const string Database = "TestingDB";
const string RootUsername = "root";
const string RootPassword = "password";
MongoDbContainer _container = null!;
@stormwild
stormwild / Program.cs
Created October 1, 2024 09:01 — forked from dj-nitehawk/Program.cs
Customizing Swagger Middleware & UI Paths
app.UseSwaggerGen(
s =>
{
//where to serve swagger.json files from
s.Path = "/PREFIX/swagger/{documentName}/swagger.json";
//api endpoint server base path customization
s.PostProcess = (document, request) =>
{
document.Servers.Clear();
@stormwild
stormwild / AddCustomHeader.cs
Created October 1, 2024 09:01 — forked from dj-nitehawk/AddCustomHeader.cs
Customizing Swagger Spec With An IOperationProcessor
internal sealed class AddCustomHeader : IOperationProcessor
{
public bool Process(OperationProcessorContext context)
{
var hdrParameter = new OpenApiParameter()
{
Name = "x-custom",
Kind = OpenApiParameterKind.Header,
IsRequired = true,
Type = JsonObjectType.String,
@stormwild
stormwild / Program.cs
Created October 1, 2024 09:01 — forked from dj-nitehawk/Program.cs
Storing `IJobStorageRecord` and `IEventStorageRecord` via EntityFramework Core
using FastEndpoints;
using MessagePack;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
public class JobRecord : IJobStorageRecord
{
public Guid Id { get; set; }
public string QueueID { get; set; }
public object Command { get; set; }