Skip to content

Commit

Permalink
Used array initialiser instead of List constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Apr 30, 2024
1 parent 366aeae commit 7cb33aa
Show file tree
Hide file tree
Showing 61 changed files with 131 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace EventStoreDB.Integration.Tests.Commands;
public class EventStoreDBAsyncCommandBusTests
{
private readonly EventStoreDBAsyncCommandBus martenAsyncCommandBus;
private readonly List<Guid> userIds = new();
private readonly List<Guid> userIds = [];
private readonly EventListener eventListener = new();
private readonly CancellationToken ct = new CancellationTokenSource().Token;
private readonly EventStoreClient eventStoreClient;
Expand Down
2 changes: 1 addition & 1 deletion Core.EventStoreDB/Events/EventStoreDBExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ CancellationToken cancellationToken
);

if (await readResult.ReadState.ConfigureAwait(false) == ReadState.StreamNotFound)
return new List<object>();
return [];

return await readResult
.Select(@event => @event.Deserialize()!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class OptimisticConcurrencyMiddleware
private readonly RequestDelegate next;

private readonly string[] SupportedMethods =
{
[
HttpMethod.Post.Method, HttpMethod.Put.Method, HttpMethod.Delete.Method
};
];

public OptimisticConcurrencyMiddleware(
RequestDelegate next
Expand Down
4 changes: 2 additions & 2 deletions Core.WebApi/Swagger/MetadataOperationFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Core.WebApi.Swagger;
public class MetadataOperationFilter: IOperationFilter
{
private static readonly string[] StateChangeMethods =
{
[
HttpMethod.Post.Method, HttpMethod.Put.Method, HttpMethod.Delete.Method
};
];

public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
Expand Down
2 changes: 1 addition & 1 deletion Core/Events/EventBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private async Task Publish<TEvent>(EventEnvelope<TEvent> eventEnvelope, Cancella
public Task Publish(IEventEnvelope eventEnvelope, CancellationToken ct)
{
return (Task)GetGenericPublishFor(eventEnvelope)
.Invoke(this, new object[] { eventEnvelope, ct })!;
.Invoke(this, [eventEnvelope, ct])!;
}

private static MethodInfo GetGenericPublishFor(IEventEnvelope @event) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public override async Task InitializeAsync()
}

private MartenAsyncCommandBus martenAsyncCommandBus = default!;
private readonly List<Guid> userIds = new();
private readonly List<Guid> userIds = [];
private readonly EventListener eventListener = new();
private IProjectionCoordinator asyncDaemon = default!;
private readonly CancellationToken ct = new CancellationTokenSource().Token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void Apply(TemperatureMeasurementStarted @event)
{
Id = @event.MeasurementId;
Started = @event.StartedAt;
Mesurements = new List<decimal>();
Mesurements = [];
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public TEntity Delete(TEntity entity)

public ValueTask<TEntity?> FindByIdAsync(Guid id, CancellationToken ct)
{
return dbContext.Set<TEntity>().FindAsync(new object?[] { id }, ct);
return dbContext.Set<TEntity>().FindAsync([id], ct);
}

public Task SaveChangesAsync(CancellationToken ct)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void Delete(TEntity entity)
public ValueTask<TEntity?> FindByIdAsync(Guid id, CancellationToken cancellationToken = default)
{
return dbContext.Set<TEntity>().FindAsync(
new object?[] { id },
[id],
cancellationToken: cancellationToken
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Delete(TEntity entity)
public ValueTask<TEntity?> FindByIdAsync(Guid id, CancellationToken cancellationToken = default)
{
return dbContext.Set<TEntity>().FindAsync(
new object?[] { id },
[id],
cancellationToken: cancellationToken
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class DbContextExtensions
public static ValueTask<TEntity?> FindById<TEntity>(this DbContext dbContext, Guid id, CancellationToken ct)
where TEntity : class =>
dbContext.Set<TEntity>().FindAsync(
new object?[] { id },
[id],
cancellationToken: ct
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class DbContextExtensions
public static ValueTask<TEntity?> FindById<TEntity>(this DbContext dbContext, Guid id, CancellationToken ct)
where TEntity : class =>
dbContext.Set<TEntity>().FindAsync(
new object?[] { id },
[id],
cancellationToken: ct
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class DbContextExtensions
public static ValueTask<TEntity?> FindById<TEntity>(this DbContext dbContext, Guid id, CancellationToken ct)
where TEntity : class =>
dbContext.Set<TEntity>().FindAsync(
new object?[] { id },
[id],
cancellationToken: ct
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class DbContextExtensions
public static ValueTask<TEntity?> FindById<TEntity>(this DbContext dbContext, Guid id, CancellationToken ct)
where TEntity : class =>
dbContext.Set<TEntity>().FindAsync(
new object?[] { id },
[id],
cancellationToken: ct
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class DbContextExtensions
public static ValueTask<TEntity?> FindById<TEntity>(this DbContext dbContext, Guid id, CancellationToken ct)
where TEntity : class =>
dbContext.Set<TEntity>().FindAsync(
new object?[] { id },
[id],
cancellationToken: ct
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class DbContextExtensions
public static ValueTask<TEntity?> FindById<TEntity>(this DbContext dbContext, Guid id, CancellationToken ct)
where TEntity : class =>
dbContext.Set<TEntity>().FindAsync(
new object?[] { id },
[id],
cancellationToken: ct
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public InitializeOrderTests(TestWebApplicationFactory<Program> fixture)

private readonly Guid ClientId = Guid.NewGuid();

private readonly List<PricedProductItemRequest> ProductItems = new()
{
private readonly List<PricedProductItemRequest> ProductItems =
[
new PricedProductItemRequest { ProductId = Guid.NewGuid(), Quantity = 10, UnitPrice = 3 },
new PricedProductItemRequest { ProductId = Guid.NewGuid(), Quantity = 3, UnitPrice = 7 }
};
];

private decimal TotalPrice => ProductItems.Sum(pi => pi.Quantity!.Value * pi.UnitPrice!.Value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public SendPackageTests(TestWebApplicationFactory<Program> fixture)

private readonly DateTime TimeBeforeSending = DateTime.UtcNow;

private readonly List<ProductItem> ProductItems = new()
{
private readonly List<ProductItem> ProductItems =
[
new ProductItem { ProductId = Guid.NewGuid(), Quantity = 10 },
new ProductItem { ProductId = Guid.NewGuid(), Quantity = 3 }
};
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ string TenantName

public class AdminStorage
{
public static readonly string[] TenantNames = { "FB", "Google", "Twitter" };
public static readonly string[] TenantNames = ["FB", "Google", "Twitter"];

public List<AdminGrantedInTenant> AdminsInTenants = new();
public List<AdminAdded> GlobalAdmins = new();
public List<AdminGrantedInTenant> AdminsInTenants = [];
public List<AdminAdded> GlobalAdmins = [];
}

public class IsAdmin: IEventFilter<UserAdded>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ string TenantName

public class AdminStorage
{
public static readonly string[] TenantNames = { "FB", "Google", "Twitter" };
public static readonly string[] TenantNames = ["FB", "Google", "Twitter"];

public List<AdminGrantedInTenant> AdminsInTenants = new();
public List<AdminAdded> GlobalAdmins = new();
public List<AdminGrantedInTenant> AdminsInTenants = [];
public List<AdminAdded> GlobalAdmins = [];
}

public class IsAdmin: IEventFilter<UserAdded>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ string TenantName

public class AdminStorage
{
public static readonly string[] TenantNames = { "FB", "Google", "Twitter" };
public static readonly string[] TenantNames = ["FB", "Google", "Twitter"];

public List<AdminGrantedInTenant> AdminsInTenants = new();
public List<AdminAdded> GlobalAdmins = new();
public List<AdminGrantedInTenant> AdminsInTenants = [];
public List<AdminAdded> GlobalAdmins = [];
}

public class IsAdmin: IEventFilter<UserAdded>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ string TenantName

public static class AdminPipeline
{
public static readonly string[] TenantNames = { "FB", "Google", "Twitter" };
public static readonly string[] TenantNames = ["FB", "Google", "Twitter"];

public static List<AdminGrantedInTenant> AdminsInTenants = new();
public static List<AdminAdded> GlobalAdmins = new();
public static List<AdminGrantedInTenant> AdminsInTenants = [];
public static List<AdminAdded> GlobalAdmins = [];

public static bool IsAdmin(UserAdded @event) =>
@event.IsAdmin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ string TenantName

public static class AdminPipeline
{
public static readonly string[] TenantNames = { "FB", "Google", "Twitter" };
public static readonly string[] TenantNames = ["FB", "Google", "Twitter"];

public static List<AdminGrantedInTenant> AdminsInTenants = new();
public static List<AdminAdded> GlobalAdmins = new();
public static List<AdminGrantedInTenant> AdminsInTenants = [];
public static List<AdminAdded> GlobalAdmins = [];

public static bool IsAdmin(UserAdded @event) =>
@event.IsAdmin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ string TenantName

public static class AdminPipeline
{
public static readonly string[] TenantNames = { "FB", "Google", "Twitter" };
public static readonly string[] TenantNames = ["FB", "Google", "Twitter"];

public static List<AdminGrantedInTenant> AdminsInTenants = new();
public static List<AdminAdded> GlobalAdmins = new();
public static List<AdminGrantedInTenant> AdminsInTenants = [];
public static List<AdminAdded> GlobalAdmins = [];

public static bool IsAdmin(UserAdded @event) =>
@event.IsAdmin;
Expand Down
2 changes: 1 addition & 1 deletion Sample/EventPipelines/EventPipelines/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class EventHandlersBuilder
{
private readonly List<IEventHandler> eventHandlers = new();
private readonly List<IEventHandler> eventHandlers = [];

private EventHandlersBuilder()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static class EventStoreDBExtensions
);

if (await readResult.ReadState == ReadState.StreamNotFound)
return new List<object>();
return [];

return await readResult
.Select(@event => @event.Deserialize()!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public class UpdateProjection<TView, TEvent, TDbContext>: IEventHandler<EventEnv
public async Task Handle(EventEnvelope<TEvent> eventEnvelope, CancellationToken ct)
{
var viewId = getViewId(eventEnvelope.Data);
var view = await dbContext.FindAsync<TView>(new [] {viewId}, ct);
var view = await dbContext.FindAsync<TView>([viewId], ct);

if (view == null)
throw new InvalidOperationException($"{typeof(TView).Name} with id {viewId} wasn't found");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public ProductItemsList Remove(PricedProductItem productItem)
);

public static ProductItemsList Empty() =>
new(new List<PricedProductItem>());
new([]);

public override string ToString() =>
$"[{string.Join(", ", items.Select(pi => pi.ToString()))}]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ List<EventData> events
.CorrelationId;

var i = 1;
List<EventData> productItemsAdded = new();
List<EventData> productItemsAdded = [];

while (i < events.Count)
{
Expand All @@ -58,9 +58,10 @@ List<EventData> events
productItemsAdded
);

return new List<EventData>(
new[] { mergedEvent }.Union(events.Skip(i))
);
return
[
..new[] { mergedEvent }.Union(events.Skip(i))
];
}

private EventData ToShoppingCartInitializedWithProducts(
Expand All @@ -72,8 +73,9 @@ List<EventData> productItemsAdded

var newEvent = new ShoppingCartInitializedWithProducts(
shoppingCartInitializedJson.GetProperty("ShoppingCartId").GetGuid(),
shoppingCartInitializedJson.GetProperty("ClientId").GetGuid(), new List<V1.PricedProductItem>(
productItemsAdded.Select(pi =>
shoppingCartInitializedJson.GetProperty("ClientId").GetGuid(), [

..productItemsAdded.Select(pi =>
{
var pricedProductItem = JsonDocument.Parse(pi.Data).RootElement.GetProperty("ProductItem");
var productItem = pricedProductItem.GetProperty("ProductItem");
Expand All @@ -83,7 +85,8 @@ List<EventData> productItemsAdded
productItem.GetProperty("Quantity").GetInt32()),
pricedProductItem.GetProperty("UnitPrice").GetDecimal());
})
)

]
);

return new EventData("shopping_cart_initialized_v2", JsonSerializer.Serialize(newEvent),
Expand All @@ -92,7 +95,7 @@ List<EventData> productItemsAdded

public class StreamTransformations
{
private readonly List<Func<List<EventData>, List<EventData>>> jsonTransformations = new();
private readonly List<Func<List<EventData>, List<EventData>>> jsonTransformations = [];

public List<EventData> Transform(List<EventData> events)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public void Apply(IncidentClosed closed, CustomerIncidentsSummary current)
public class CustomerIncidentsSummaryGrouper: IAggregateGrouper<Guid>
{
private readonly Type[] eventTypes =
{
[
typeof(IncidentResolved), typeof(ResolutionAcknowledgedByCustomer),
typeof(IncidentClosed)
};
];

public async Task Group(IQuerySession session, IEnumerable<IEvent> events, ITenantSliceGroup<Guid> grouping)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ await API
RESPONSE_BODY(
API.Incident with
{
Notes = new[]
{
Notes =
[
new IncidentNote(IncidentNoteType.FromAgent, agentId, content, visibleToCustomer)
},
],
Version = 2
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ await API
API.Incident with
{
Notes =
new[] { new IncidentNote(IncidentNoteType.FromCustomer, customerId, content, true) },
[new IncidentNote(IncidentNoteType.FromCustomer, customerId, content, true)],
Version = 2
}
)
Expand Down

0 comments on commit 7cb33aa

Please sign in to comment.