forked from ardalis/pluralsight-ddd-fundamentals
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Get with Spec to IRepository
- Loading branch information
Showing
23 changed files
with
200 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
{ | ||
public class ListPatientRequest : BaseRequest | ||
{ | ||
public int ClientId { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
FrontDesk/src/FrontDesk.Core/Specifications/Client/ClientIncludePatientsSpecification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Ardalis.Specification; | ||
using FrontDesk.Core.Aggregates; | ||
|
||
namespace FrontDesk.Core.Specifications | ||
{ | ||
public class ClientByIdIncludePatientsSpecification : Specification<Client> | ||
{ | ||
public ClientByIdIncludePatientsSpecification(int clientId) | ||
{ | ||
Query | ||
.Include(client => client.Patients) | ||
.Where(client => client.Id == clientId) | ||
.OrderBy(client => client.FullName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
FrontDesk/tests/IntegrationTests/ClientTests/EfRepositoryAddWithPatient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using FrontDesk.Infrastructure.Data; | ||
using UnitTests.Builders; | ||
using Xunit; | ||
using FrontDesk.Core.Aggregates; | ||
using FrontDesk.Core.Specifications; | ||
|
||
namespace IntegrationTests.ClientTests | ||
{ | ||
public class EfRepositoryAddWithPatient : BaseEfRepoTestFixture | ||
{ | ||
private readonly EfRepository _repository; | ||
|
||
public EfRepositoryAddWithPatient() | ||
{ | ||
_repository = GetRepository(); | ||
} | ||
|
||
[Fact] | ||
public async Task AddsPatientAndSetsId() | ||
{ | ||
var client = await AddClient(); | ||
var patient = client.Patients.First(); | ||
|
||
var clientWithPatientsSpec = new ClientByIdIncludePatientsSpecification(client.Id); | ||
var clientFromDb = (await _repository.ListAsync<FrontDesk.Core.Aggregates.Client, int>(clientWithPatientsSpec)).First(); | ||
var newPatient = clientFromDb.Patients.First(); | ||
|
||
Assert.Equal(patient, newPatient); | ||
Assert.True(newPatient?.Id > 0); | ||
} | ||
|
||
private async Task<FrontDesk.Core.Aggregates.Client> AddClient() | ||
{ | ||
var client = new ClientBuilder().Id(2).Build(); | ||
var patient = new PatientBuilder().Id(3).Build(); | ||
client.Patients.Add(patient); | ||
|
||
await _repository.AddAsync<FrontDesk.Core.Aggregates.Client, int>(client); | ||
|
||
return client; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
FrontDesk/tests/IntegrationTests/Patient/EfRepositoryAdd.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.