Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use some target typed new #267

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Core/Exceptions/AggregateNotFoundException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ private AggregateNotFoundException(string typeName, string id): base($"{typeName
public static AggregateNotFoundException For<T>(Guid id) =>
For<T>(id.ToString());

public static AggregateNotFoundException For<T>(string id) =>
new AggregateNotFoundException(typeof(T).Name, id);
public static AggregateNotFoundException For<T>(string id) => new(typeof(T).Name, id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ECommerce.Core.Controllers;
public static class HttpExtensions
{
public static CreatedResult Created(this Controller controller, Guid id) =>
new CreatedResult($"api/{controller.ControllerContext.ActionDescriptor.ControllerName}/{id}", id);
new($"api/{controller.ControllerContext.ActionDescriptor.ControllerName}/{id}", id);

public static OkResult OkWithLocation(this Controller controller, string location)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record CreateProduct(
public static class CreateProductHandler
{
public static Product Handle(CreateProduct command) =>
new Product
new()
{
Id = command.Id,
Sku = command.Sku,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record CreateProductRequest(
)
{
public CreateProduct ToCommand(Guid id) =>
new CreateProduct(
new(
id,
Sku ?? throw new ArgumentNullException(nameof(Sku)),
Name ?? throw new ArgumentNullException(nameof(Name)),
Expand All @@ -30,7 +30,7 @@ public record UpdateProductRequest(
)
{
public UpdateProduct ToCommand(Guid id) =>
new UpdateProduct(
new(
id,
Name ?? throw new ArgumentNullException(nameof(Name)),
Description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ECommerce.Core.Controllers;
public static class HttpExtensions
{
public static CreatedResult Created(this Controller controller, Guid id) =>
new CreatedResult($"api/{controller.ControllerContext.ActionDescriptor.ControllerName}/{id}", id);
new($"api/{controller.ControllerContext.ActionDescriptor.ControllerName}/{id}", id);

public static OkResult OkWithLocation(this Controller controller, string location)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record CreateProduct(
public static class CreateProductHandler
{
public static Product Handle(CreateProduct command) =>
new Product
new()
{
Id = command.Id,
Sku = command.Sku,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record CreateProductRequest(
)
{
public CreateProduct ToCommand(Guid id) =>
new CreateProduct(
new(
id,
Sku ?? throw new ArgumentNullException(nameof(Sku)),
Name ?? throw new ArgumentNullException(nameof(Name)),
Expand All @@ -30,7 +30,7 @@ public record UpdateProductRequest(
)
{
public UpdateProduct ToCommand(Guid id) =>
new UpdateProduct(
new(
id,
Name ?? throw new ArgumentNullException(nameof(Name)),
Description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ECommerce.Core.Controllers;
public static class HttpExtensions
{
public static CreatedResult Created(this Controller controller, Guid id) =>
new CreatedResult($"api/{controller.ControllerContext.ActionDescriptor.ControllerName}/{id}", id);
new($"api/{controller.ControllerContext.ActionDescriptor.ControllerName}/{id}", id);

public static OkResult OkWithLocation(this Controller controller, string location)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record CreateProduct(
public static class CreateProductHandler
{
public static Product Handle(CreateProduct command) =>
new Product
new()
{
Id = command.Id,
Sku = command.Sku,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public record CreateProductRequest(
)
{
public CreateProduct ToCommand(Guid id) =>
new CreateProduct(
new(
id,
Sku ?? throw new ArgumentNullException(nameof(Sku)),
Name ?? throw new ArgumentNullException(nameof(Name)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public record UpdateProductRequest(
)
{
public UpdateProduct ToCommand(Guid id) =>
new UpdateProduct(
new(
id,
Name ?? throw new ArgumentNullException(nameof(Name)),
Description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record CreateProduct(
public static class CreateProductHandler
{
public static Product Handle(CreateProduct command) =>
new Product
new()
{
Id = command.Id,
Sku = command.Sku,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public record CreateProductRequest(
)
{
public CreateProduct ToCommand(Guid id) =>
new CreateProduct(
new(
id,
Sku ?? throw new ArgumentNullException(nameof(Sku)),
Name ?? throw new ArgumentNullException(nameof(Name)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public record UpdateProductRequest(
)
{
public UpdateProduct ToCommand(Guid id) =>
new UpdateProduct(
new(
id,
Name ?? throw new ArgumentNullException(nameof(Name)),
Description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public record OpenShoppingCartRequest(
)
{
public OpenShoppingCart ToCommand(Guid cartId) =>
new OpenShoppingCart(
new(
cartId,
ClientId ?? throw new ArgumentNullException(nameof(cartId))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,8 @@ public record GroupCheckout(
CheckoutStatus Status = CheckoutStatus.Initiated
)
{
public static GroupCheckoutInitiated Initiate(
Guid groupCheckoutId,
Guid clerkId,
Guid[] guestStayIds,
DateTimeOffset initiatedAt
) =>
new GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStayIds, initiatedAt);
public static GroupCheckoutInitiated Initiate(Guid groupCheckoutId, Guid clerkId, Guid[] guestStayIds, DateTimeOffset initiatedAt) =>
new(groupCheckoutId, clerkId, guestStayIds, initiatedAt);

public GuestCheckoutsInitiated? RecordGuestCheckoutsInitiation(
Guid[] initiatedGuestStayIds,
Expand Down Expand Up @@ -128,7 +123,7 @@ DateTimeOffset now
.ToArray();

public static GroupCheckout Create(GroupCheckoutInitiated @event) =>
new GroupCheckout(
new(
@event.GroupCheckOutId,
@event.GuestStayIds.ToDictionary(id => id, _ => CheckoutStatus.Pending)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public record GuestStayAccount(
{
public bool IsSettled => Balance == 0;

public static GuestCheckedIn CheckIn(Guid guestStayId, DateTimeOffset now) =>
new GuestCheckedIn(guestStayId, now);
public static GuestCheckedIn CheckIn(Guid guestStayId, DateTimeOffset now) => new(guestStayId, now);

public ChargeRecorded RecordCharge(decimal amount, DateTimeOffset now)
{
Expand Down Expand Up @@ -97,8 +96,7 @@ public PaymentRecorded RecordPayment(decimal amount, DateTimeOffset now)
);
}

public static GuestStayAccount Create(GuestCheckedIn @event) =>
new GuestStayAccount(@event.GuestStayId);
public static GuestStayAccount Create(GuestCheckedIn @event) => new(@event.GuestStayId);

public GuestStayAccount Apply(ChargeRecorded @event) =>
this with { Balance = Balance - @event.Amount };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,8 @@ public record GroupCheckout(
CheckoutStatus Status = CheckoutStatus.Initiated
)
{
public static GroupCheckoutInitiated Initiate(
Guid groupCheckoutId,
Guid clerkId,
Guid[] guestStayIds,
DateTimeOffset initiatedAt
) =>
new GroupCheckoutInitiated(groupCheckoutId, clerkId, guestStayIds, initiatedAt);
public static GroupCheckoutInitiated Initiate(Guid groupCheckoutId, Guid clerkId, Guid[] guestStayIds, DateTimeOffset initiatedAt) =>
new(groupCheckoutId, clerkId, guestStayIds, initiatedAt);

public Maybe<GuestCheckoutsInitiated> RecordGuestCheckoutsInitiation(
Guid[] initiatedGuestStayIds,
Expand Down Expand Up @@ -127,7 +122,7 @@ DateTimeOffset now
.ToArray();

public static GroupCheckout Create(GroupCheckoutInitiated @event) =>
new GroupCheckout(
new(
@event.GroupCheckoutId,
@event.GuestStayIds.ToDictionary(id => id, _ => CheckoutStatus.Pending)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public record GuestStayAccount(
{
public bool IsSettled => Balance == 0;

public static GuestCheckedIn CheckIn(Guid guestStayId, DateTimeOffset now) =>
new GuestCheckedIn(guestStayId, now);
public static GuestCheckedIn CheckIn(Guid guestStayId, DateTimeOffset now) => new(guestStayId, now);

public ChargeRecorded RecordCharge(decimal amount, DateTimeOffset now)
{
Expand Down Expand Up @@ -97,8 +96,7 @@ public PaymentRecorded RecordPayment(decimal amount, DateTimeOffset now)
);
}

public static GuestStayAccount Create(GuestCheckedIn @event) =>
new GuestStayAccount(@event.GuestStayId);
public static GuestStayAccount Create(GuestCheckedIn @event) => new(@event.GuestStayId);

public GuestStayAccount Apply(ChargeRecorded @event) =>
this with { Balance = Balance - @event.Amount };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Guid CreatedById
);

public static ProjectCreated Handle(CreateBacklogProject command) =>
new ProjectCreated(
new(
ProjectId: command.ProjectId,
Name: "Backlog",
StartDate: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Guid CreatedById
);

public static WorkspaceCreated Handle(CreateWorkspace command) =>
new WorkspaceCreated(
new(
WorkspaceId: command.WorkspaceId,
Name: command.Name,
TaskPrefix: command.TaskPrefix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public class Dummy

public string Name { get; private set; }

public static Dummy Create(string name) =>
new Dummy(ObjectId.GenerateNewId().ToString(), name);
public static Dummy Create(string name) => new(ObjectId.GenerateNewId().ToString(), name);

[BsonConstructor]
private Dummy(string id, string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,12 @@ public static ChemicalReactionEvent.Initiated Initiate(string id, List<ReactionP

public record NotStarted: ChemicalReaction
{
public ChemicalReactionEvent.Started Start(DateTimeOffset now) =>
new ChemicalReactionEvent.Started(now);
public ChemicalReactionEvent.Started Start(DateTimeOffset now) => new(now);
}

public record InProgress: ChemicalReaction
{
public ChemicalReactionEvent.Completed Stop(DateTimeOffset now) =>
new ChemicalReactionEvent.Completed(now);
public ChemicalReactionEvent.Completed Stop(DateTimeOffset now) => new(now);
}

public record Completed: ChemicalReaction;
Expand Down
4 changes: 2 additions & 2 deletions Sample/Tickets/Tickets.Api.Tests/Config/TestConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Tickets.Api.Tests.Config;
public static class TestConfiguration
{
public static Dictionary<string, string> Get(string fixtureName) =>
new Dictionary<string, string>
new()
{
{
"EventStore:ConnectionString",
Expand All @@ -13,4 +13,4 @@ public static class TestConfiguration
{"EventStore:ReadModelSchema", $"{fixtureName}Read"},
{"EventStore:ShouldRecreateDatabase", "true"}
};
}
}
4 changes: 2 additions & 2 deletions Sample/Tickets/Tickets.Tests/Builders/ReservationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public ReservationBuilder Tentative()
return this;
}

public static ReservationBuilder Create() => new ReservationBuilder();
public static ReservationBuilder Create() => new();

public Reservation Build()
{
var reservation = build();
((IAggregate)reservation).DequeueUncommittedEvents();
return reservation;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public record ShoppingCart(
){

public static ShoppingCart Create(ShoppingCartOpened opened) =>
new ShoppingCart(
new(
opened.ShoppingCartId,
opened.ClientId,
ShoppingCartStatus.Pending,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Price UnitPrice

public class ProductItems(ImmutableDictionary<ProductIdWithPrice, Quantity> Items)
{
public static ProductItems Empty => new ProductItems(ImmutableDictionary<ProductIdWithPrice, Quantity>.Empty);
public static ProductItems Empty => new(ImmutableDictionary<ProductIdWithPrice, Quantity>.Empty);

public ProductItems Add(PricedProductItem productItem) =>
new(Items.Set(Key(productItem), currentQuantity => currentQuantity + productItem.Quantity));
Expand Down