Skip to content

Commit 5817edb

Browse files
committed
Fixed build in exercises
1 parent c35b657 commit 5817edb

File tree

8 files changed

+158
-25
lines changed

8 files changed

+158
-25
lines changed

Workshops/IntroductionToEventSourcing/10-OptimisticConcurrency.Marten/10-OptimisticConcurrency.Marten.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,4 @@
1414
<PackageReference Include="Marten.AspNetCore" />
1515
<PackageReference Include="Marten" />
1616
</ItemGroup>
17-
18-
<ItemGroup>
19-
<ProjectReference Include="..\..\..\Core\Core.csproj" />
20-
</ItemGroup>
2117
</Project>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System.Numerics;
2+
using System.Runtime.CompilerServices;
3+
4+
namespace Core.Validation;
5+
6+
public static class ValidationExtensions
7+
{
8+
public static T NotNull<T>(this T? value, [CallerArgumentExpression("value")] string? paramName = null)
9+
where T : struct
10+
{
11+
if (value == null)
12+
throw new ArgumentNullException(paramName);
13+
14+
return value.Value;
15+
}
16+
17+
public static T NotNull<T>(this T? value, [CallerArgumentExpression("value")] string? paramName = null)
18+
where T : class
19+
{
20+
if (value == null)
21+
throw new ArgumentNullException(paramName);
22+
23+
return value;
24+
}
25+
26+
public static string NotEmpty(this string? value, [CallerArgumentExpression("value")] string? paramName = null)
27+
=> !string.IsNullOrWhiteSpace(value) ? value : throw new ArgumentOutOfRangeException(paramName);
28+
29+
public static Guid NotEmpty(this Guid? value, [CallerArgumentExpression("value")] string? paramName = null)
30+
=> value!= null && value != Guid.Empty ? value.Value : throw new ArgumentOutOfRangeException(paramName);
31+
32+
33+
public static T NotEmpty<T>(this T value, [CallerArgumentExpression("value")] string? paramName = null)
34+
where T : struct
35+
=> NotEmpty((T?)value, paramName);
36+
37+
public static T Has<T>(this T value, Action<T> assert)
38+
{
39+
assert(value);
40+
return value;
41+
}
42+
43+
public static T NotEmpty<T>(this T? value, [CallerArgumentExpression("value")] string? paramName = null)
44+
where T : struct
45+
{
46+
var notNullValue = value.NotNull(paramName);
47+
48+
if (Equals(notNullValue, default(T)))
49+
throw new ArgumentOutOfRangeException(paramName);
50+
51+
return notNullValue;
52+
}
53+
54+
public static T GreaterOrEqualThan<T>(this T value, T valueToCompare, [CallerArgumentExpression("value")] string? paramName = null)
55+
where T : IComparable<T>
56+
{
57+
if (value.CompareTo(valueToCompare) < 0)
58+
throw new ArgumentOutOfRangeException(paramName);
59+
60+
return value;
61+
62+
}
63+
64+
public static T Positive<T>(this T value, [CallerArgumentExpression("value")] string? paramName = null)
65+
where T : INumber<T>
66+
{
67+
if (value == null || value.CompareTo(Convert.ChangeType(0, typeof(T))) <= 0)
68+
throw new ArgumentOutOfRangeException(paramName);
69+
70+
return value;
71+
}
72+
}

Workshops/IntroductionToEventSourcing/10-OptimisticConcurrency.Marten/Immutable/ShoppingCarts/Api.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public static WebApplication ConfigureImmutableShoppingCarts(this WebApplication
2424

2525
shoppingCarts.MapPost("",
2626
async (
27-
HttpContext context,
2827
IDocumentSession session,
2928
Guid clientId,
3029
CancellationToken ct) =>
@@ -40,7 +39,6 @@ await session.Add<ShoppingCart>(shoppingCartId,
4039

4140
productItems.MapPost("",
4241
async (
43-
HttpContext context,
4442
IProductPriceCalculator pricingCalculator,
4543
IDocumentSession session,
4644
Guid shoppingCartId,
@@ -64,7 +62,6 @@ await session.GetAndUpdate<ShoppingCart>(shoppingCartId,
6462

6563
productItems.MapDelete("{productId:guid}",
6664
async (
67-
HttpContext context,
6865
IDocumentSession session,
6966
Guid shoppingCartId,
7067
[FromRoute] Guid productId,
@@ -89,7 +86,6 @@ await session.GetAndUpdate<ShoppingCart>(shoppingCartId,
8986

9087
shoppingCart.MapPost("confirm",
9188
async (
92-
HttpContext context,
9389
IDocumentSession session,
9490
Guid shoppingCartId,
9591
[FromIfMatchHeader] string eTag,
@@ -104,7 +100,6 @@ await session.GetAndUpdate<ShoppingCart>(shoppingCartId,
104100

105101
shoppingCart.MapDelete("",
106102
async (
107-
HttpContext context,
108103
IDocumentSession session,
109104
Guid shoppingCartId,
110105
[FromIfMatchHeader] string eTag,
@@ -119,7 +114,6 @@ await session.GetAndUpdate<ShoppingCart>(shoppingCartId,
119114

120115
shoppingCart.MapGet("",
121116
async Task<IResult> (
122-
HttpContext context,
123117
IQuerySession session,
124118
Guid shoppingCartId,
125119
CancellationToken ct) =>

Workshops/IntroductionToEventSourcing/10-OptimisticConcurrency.Marten/Mixed/ShoppingCarts/Api.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public static WebApplication ConfigureMixedShoppingCarts(this WebApplication app
2121

2222
shoppingCarts.MapPost("",
2323
async (
24-
HttpContext context,
2524
IDocumentSession session,
2625
Guid clientId,
2726
CancellationToken ct
@@ -38,7 +37,6 @@ await session.Add<MixedShoppingCart>(shoppingCartId,
3837

3938
productItems.MapPost("",
4039
async (
41-
HttpContext context,
4240
IProductPriceCalculator pricingCalculator,
4341
IDocumentSession session,
4442
Guid shoppingCartId,
@@ -57,7 +55,6 @@ await session.GetAndUpdate<MixedShoppingCart>(shoppingCartId,
5755

5856
productItems.MapDelete("{productId:guid}",
5957
async (
60-
HttpContext context,
6158
IDocumentSession session,
6259
Guid shoppingCartId,
6360
[FromRoute] Guid productId,
@@ -83,7 +80,6 @@ await session.GetAndUpdate<MixedShoppingCart>(shoppingCartId,
8380

8481
shoppingCart.MapPost("confirm",
8582
async (
86-
HttpContext context,
8783
IDocumentSession session,
8884
Guid shoppingCartId,
8985
[FromIfMatchHeader] string eTag,
@@ -98,7 +94,6 @@ await session.GetAndUpdate<MixedShoppingCart>(shoppingCartId,
9894

9995
shoppingCart.MapDelete("",
10096
async (
101-
HttpContext context,
10297
IDocumentSession session,
10398
Guid shoppingCartId,
10499
[FromIfMatchHeader] string eTag,
@@ -113,7 +108,6 @@ await session.GetAndUpdate<MixedShoppingCart>(shoppingCartId,
113108

114109
shoppingCart.MapGet("",
115110
async Task<IResult> (
116-
HttpContext context,
117111
IQuerySession session,
118112
Guid shoppingCartId,
119113
[FromIfMatchHeader] string eTag,

Workshops/IntroductionToEventSourcing/10-OptimisticConcurrency.Marten/Mutable/ShoppingCarts/Api.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ await session.Add(shoppingCartId,
3737

3838
productItems.MapPost("",
3939
async (
40-
HttpContext context,
4140
IProductPriceCalculator pricingCalculator,
4241
IDocumentSession session,
4342
Guid shoppingCartId,
@@ -56,7 +55,6 @@ await session.GetAndUpdate<MutableShoppingCart>(shoppingCartId,
5655

5756
productItems.MapDelete("{productId:guid}",
5857
async (
59-
HttpContext context,
6058
IDocumentSession session,
6159
Guid shoppingCartId,
6260
[FromRoute] Guid productId,
@@ -82,7 +80,6 @@ await session.GetAndUpdate<MutableShoppingCart>(shoppingCartId,
8280

8381
shoppingCart.MapPost("confirm",
8482
async (
85-
HttpContext context,
8683
IDocumentSession session,
8784
Guid shoppingCartId,
8885
[FromIfMatchHeader] string eTag,
@@ -97,7 +94,6 @@ await session.GetAndUpdate<MutableShoppingCart>(shoppingCartId,
9794

9895
shoppingCart.MapDelete("",
9996
async (
100-
HttpContext context,
10197
IDocumentSession session,
10298
Guid shoppingCartId,
10399
[FromIfMatchHeader] string eTag,
@@ -112,7 +108,6 @@ await session.GetAndUpdate<MutableShoppingCart>(shoppingCartId,
112108

113109
shoppingCart.MapGet("",
114110
async Task<IResult> (
115-
HttpContext context,
116111
IQuerySession session,
117112
Guid shoppingCartId,
118113
CancellationToken ct) =>

Workshops/IntroductionToEventSourcing/11-OptimisticConcurrency.EventStoreDB/11-OptimisticConcurrency.EventStoreDB.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
<PackageReference Include="EventStore.Client.Grpc.Streams" />
1414
</ItemGroup>
1515

16-
<ItemGroup>
17-
<ProjectReference Include="..\..\..\Core\Core.csproj" />
18-
</ItemGroup>
19-
2016
<ItemGroup>
2117
<Content Update="appsettings.json">
2218
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Core.Configuration;
2+
3+
public static class ConfigurationExtensions
4+
{
5+
public static T GetRequiredConfig<T>(this IConfiguration configuration, string configurationKey) =>
6+
configuration.GetRequiredSection(configurationKey).Get<T>()
7+
?? throw new InvalidOperationException(
8+
$"{typeof(T).Name} configuration wasn't found for '${configurationKey}' key");
9+
10+
public static string GetRequiredConnectionString(this IConfiguration configuration, string configurationKey) =>
11+
configuration.GetConnectionString(configurationKey)
12+
?? throw new InvalidOperationException(
13+
$"Configuration string with name '${configurationKey}' was not found");
14+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System.Numerics;
2+
using System.Runtime.CompilerServices;
3+
4+
namespace Core.Validation;
5+
6+
public static class ValidationExtensions
7+
{
8+
public static T NotNull<T>(this T? value, [CallerArgumentExpression("value")] string? paramName = null)
9+
where T : struct
10+
{
11+
if (value == null)
12+
throw new ArgumentNullException(paramName);
13+
14+
return value.Value;
15+
}
16+
17+
public static T NotNull<T>(this T? value, [CallerArgumentExpression("value")] string? paramName = null)
18+
where T : class
19+
{
20+
if (value == null)
21+
throw new ArgumentNullException(paramName);
22+
23+
return value;
24+
}
25+
26+
public static string NotEmpty(this string? value, [CallerArgumentExpression("value")] string? paramName = null)
27+
=> !string.IsNullOrWhiteSpace(value) ? value : throw new ArgumentOutOfRangeException(paramName);
28+
29+
public static Guid NotEmpty(this Guid? value, [CallerArgumentExpression("value")] string? paramName = null)
30+
=> value!= null && value != Guid.Empty ? value.Value : throw new ArgumentOutOfRangeException(paramName);
31+
32+
33+
public static T NotEmpty<T>(this T value, [CallerArgumentExpression("value")] string? paramName = null)
34+
where T : struct
35+
=> NotEmpty((T?)value, paramName);
36+
37+
public static T Has<T>(this T value, Action<T> assert)
38+
{
39+
assert(value);
40+
return value;
41+
}
42+
43+
public static T NotEmpty<T>(this T? value, [CallerArgumentExpression("value")] string? paramName = null)
44+
where T : struct
45+
{
46+
var notNullValue = value.NotNull(paramName);
47+
48+
if (Equals(notNullValue, default(T)))
49+
throw new ArgumentOutOfRangeException(paramName);
50+
51+
return notNullValue;
52+
}
53+
54+
public static T GreaterOrEqualThan<T>(this T value, T valueToCompare, [CallerArgumentExpression("value")] string? paramName = null)
55+
where T : IComparable<T>
56+
{
57+
if (value.CompareTo(valueToCompare) < 0)
58+
throw new ArgumentOutOfRangeException(paramName);
59+
60+
return value;
61+
62+
}
63+
64+
public static T Positive<T>(this T value, [CallerArgumentExpression("value")] string? paramName = null)
65+
where T : INumber<T>
66+
{
67+
if (value == null || value.CompareTo(Convert.ChangeType(0, typeof(T))) <= 0)
68+
throw new ArgumentOutOfRangeException(paramName);
69+
70+
return value;
71+
}
72+
}

0 commit comments

Comments
 (0)