Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 4b26049

Browse files
committed
feat(enrolling): use factory to create domain object
1 parent 0f0dddb commit 4b26049

7 files changed

Lines changed: 21 additions & 13 deletions

File tree

src/Services/Enrolling/Enrolling.API/Application/Commands/EnrollmentApplicationCommandHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public async Task<bool> Handle(
3131
throw new ArgumentNullException(nameof(command));
3232
}
3333

34-
var enrollment = new Enrollment(command.Name, command.Email, command.Mobile);
34+
var enrollment = Enrollment.CreateNew(command.Name, command.Email, command.Mobile);
3535
await _context.Enrollments.AddAsync(enrollment, cancellationToken)
3636
.ConfigureAwait(false);
3737
await _context.SaveChangesAsync(cancellationToken)

src/Services/Enrolling/Enrolling.API/Enrolling.API.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PackageReference Include="MediatR" Version="9.0.0"/>
1515
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0"/>
1616
<!-- For validating inputs -->
17-
<PackageReference Include="FluentValidation.AspNetCore" Version="10.2.3"/>
17+
<PackageReference Include="FluentValidation.AspNetCore" Version="10.3.0"/>
1818
<!-- Polly is a .NET resilience and transient-fault-handling library that
1919
allows developers to express policies such as Retry, Circuit Breaker, Timeout,
2020
Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. -->
@@ -26,7 +26,7 @@
2626
<!-- Swagger -->
2727
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4"/>
2828
<!-- Need this package for generating migration files -->
29-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.7">
29+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0-preview.6.21352.1">
3030
<PrivateAssets>all</PrivateAssets>
3131
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
3232
</PackageReference>

src/Services/Enrolling/Enrolling.API/graphql/Mutation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public async Task<Enrollment> AddEnrollmentAsync(
2929
throw new ArgumentNullException(nameof(context));
3030
}
3131

32-
var enrollment = new Enrollment(
32+
var enrollment = Enrollment.CreateNew(
3333
input.Name,
3434
input.Email,
3535
input.Mobile);

src/Services/Enrolling/Enrolling.Domain/AggregatesModel/EnrollmentAggregate/Enrollment.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace OpenCodeFoundation.ESchool.Services.Enrolling.Domain.AggregatesModel.E
66
public class Enrollment
77
: Entity, IAggregateRoot
88
{
9-
public Enrollment(
9+
private Enrollment(
1010
string name,
1111
string emailAddress,
1212
string mobileNumber)
@@ -24,5 +24,13 @@ public Enrollment(
2424
public string EmailAddress { get; private set; }
2525

2626
public string MobileNumber { get; private set; }
27+
28+
public static Enrollment CreateNew(
29+
string name,
30+
string emailAddress,
31+
string mobileNumber)
32+
{
33+
return new(name, emailAddress, mobileNumber);
34+
}
2735
}
2836
}

src/Services/Enrolling/Enrolling.FunctionalTests/Enrolling.FunctionalTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.7"/>
8+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.0-preview.6.21355.2"/>
99
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0"/>
1010
<PackageReference Include="xunit" Version="2.4.1"/>
1111
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"/>

src/Services/Enrolling/Enrolling.Infrastructure/Enrolling.Infrastructure.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<ProjectReference Include="..\Enrolling.Domain\Enrolling.Domain.csproj"/>
99
</ItemGroup>
1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.7"/>
12-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.7"/>
11+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0-preview.6.21352.1"/>
12+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0-preview.6.21352.1"/>
1313
</ItemGroup>
1414
</Project>

src/Services/Enrolling/Enrolling.UnitTests/Domain/EnrollmentAggregateTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void NewApplicationShouldSuccessWithValidInput()
1414
.WithDefaults()
1515
.Build();
1616

17-
var enrollment = new Enrollment(dto.Name!, dto.Email!, dto.Mobile!);
17+
var enrollment = Enrollment.CreateNew(dto.Name!, dto.Email!, dto.Mobile!);
1818

1919
Assert.NotNull(enrollment);
2020
Assert.Equal(dto.Name, enrollment.Name);
@@ -30,18 +30,18 @@ public void ShouldThrowExceptionIfNameIsEmpty()
3030
.WithEmptyName()
3131
.Build();
3232

33-
Assert.Throws<ArgumentNullException>(() => new Enrollment(dto.Name!, dto.Email!, dto.Mobile!));
33+
Assert.Throws<ArgumentNullException>(() => Enrollment.CreateNew(dto.Name!, dto.Email!, dto.Mobile!));
3434
}
3535

3636
[Fact]
37-
public void ShouldThrowExceptionEmtpyEmail()
37+
public void ShouldThrowExceptionEmptyEmail()
3838
{
3939
var dto = new EnrollmentDtoBuilder()
4040
.WithDefaults()
4141
.WithEmail(string.Empty)
4242
.Build();
4343

44-
Assert.Throws<ArgumentNullException>(() => new Enrollment(dto.Name!, dto.Email!, dto.Mobile!));
44+
Assert.Throws<ArgumentNullException>(() => Enrollment.CreateNew(dto.Name!, dto.Email!, dto.Mobile!));
4545
}
4646

4747
[Fact]
@@ -52,7 +52,7 @@ public void ShouldThrowExceptionEmptyMobile()
5252
.WithMobile(string.Empty)
5353
.Build();
5454

55-
Assert.Throws<ArgumentNullException>(() => new Enrollment(dto.Name!, dto.Email!, dto.Mobile!));
55+
Assert.Throws<ArgumentNullException>(() => Enrollment.CreateNew(dto.Name!, dto.Email!, dto.Mobile!));
5656
}
5757
}
5858
}

0 commit comments

Comments
 (0)