-
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.
Added fixes while testing against CRM build environment data
- Loading branch information
Showing
6 changed files
with
202 additions
and
4 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
59 changes: 59 additions & 0 deletions
59
...cordSystem/tests/TeachingRecordSystem.Core.Tests/Jobs/SyncAllInductionsFromCrmJobTests.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,59 @@ | ||
using Microsoft.Extensions.Options; | ||
using TeachingRecordSystem.Core.Dqt.Models; | ||
using TeachingRecordSystem.Core.Jobs; | ||
using TeachingRecordSystem.Core.Services.TrsDataSync; | ||
using TeachingRecordSystem.Core.Tests.Services.TrsDataSync; | ||
|
||
namespace TeachingRecordSystem.Core.Tests.Jobs; | ||
|
||
[CollectionDefinition(nameof(TrsDataSyncTestCollection), DisableParallelization = true)] | ||
public class SyncAllInductionsFromCrmJobTests : SyncFromCrmJobTestBase, IAsyncLifetime | ||
{ | ||
public SyncAllInductionsFromCrmJobTests(SyncFromCrmJobFixture jobFixture) : base(jobFixture) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task SyncInductionsAsync_WithExistingDqtInduction_UpdatesPersonRecord() | ||
{ | ||
// Arrange | ||
var inductionStatus = dfeta_InductionStatus.Pass; | ||
var inductionStartDate = Clock.Today.AddYears(-1); | ||
var inductionCompletedDate = Clock.Today.AddDays(-5); | ||
var options = Options.Create(new TrsDataSyncServiceOptions() | ||
{ | ||
CrmConnectionString = "dummy", | ||
ModelTypes = [TrsDataSyncHelper.ModelTypes.Person], | ||
PollIntervalSeconds = 60, | ||
IgnoreInvalidData = false, | ||
RunService = false | ||
}); | ||
|
||
var person = await TestData.CreatePersonAsync( | ||
p => p.WithTrn() | ||
.WithQts() | ||
.WithDqtInduction(inductionStatus, null, inductionStartDate, inductionCompletedDate) | ||
.WithSyncOverride(false)); | ||
|
||
// Act | ||
var job = new SyncAllInductionsFromCrmJob( | ||
CrmServiceClientProvider, | ||
Helper, | ||
options); | ||
|
||
await job.ExecuteAsync(createMigratedEvent: false, dryRun: false, CancellationToken.None); | ||
|
||
// Assert | ||
await DbFixture.WithDbContextAsync(async dbContext => | ||
{ | ||
var updatedPerson = await dbContext.Persons.SingleOrDefaultAsync(p => p.DqtContactId == person.ContactId); | ||
Assert.Equal(inductionStatus.ToInductionStatus(), updatedPerson!.InductionStatus); | ||
Assert.Equal(inductionStartDate, updatedPerson.InductionStartDate); | ||
Assert.Equal(inductionCompletedDate, updatedPerson.InductionCompletedDate); | ||
}); | ||
} | ||
|
||
Task IAsyncLifetime.DisposeAsync() => Task.CompletedTask; | ||
|
||
Task IAsyncLifetime.InitializeAsync() => JobFixture.DbFixture.DbHelper.ClearDataAsync(); | ||
} |
63 changes: 63 additions & 0 deletions
63
TeachingRecordSystem/tests/TeachingRecordSystem.Core.Tests/Jobs/SyncFromCrmJobFixture.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,63 @@ | ||
using Microsoft.PowerPlatform.Dataverse.Client; | ||
using TeachingRecordSystem.Core.Dqt; | ||
using TeachingRecordSystem.Core.Services.TrsDataSync; | ||
|
||
namespace TeachingRecordSystem.Core.Tests.Jobs; | ||
|
||
public class SyncFromCrmJobFixture : IAsyncLifetime | ||
{ | ||
public SyncFromCrmJobFixture( | ||
DbFixture dbFixture, | ||
IOrganizationServiceAsync2 organizationService, | ||
ReferenceDataCache referenceDataCache, | ||
FakeTrnGenerator trnGenerator) | ||
{ | ||
DbFixture = dbFixture; | ||
Clock = new(); | ||
|
||
Helper = new TrsDataSyncHelper( | ||
dbFixture.GetDataSource(), | ||
organizationService, | ||
referenceDataCache, | ||
Clock); | ||
|
||
TestData = new TestData( | ||
dbFixture.GetDbContextFactory(), | ||
organizationService, | ||
referenceDataCache, | ||
Clock, | ||
trnGenerator, | ||
TestDataSyncConfiguration.Sync(Helper)); | ||
|
||
CrmServiceClientProvider = new TestCrmServiceClientProvider(organizationService); | ||
} | ||
|
||
public TestableClock Clock { get; } | ||
|
||
public DbFixture DbFixture { get; } | ||
|
||
public TrsDataSyncHelper Helper { get; } | ||
|
||
public TestData TestData { get; } | ||
|
||
public ICrmServiceClientProvider CrmServiceClientProvider { get; } | ||
|
||
Task IAsyncLifetime.DisposeAsync() => Task.CompletedTask; | ||
|
||
Task IAsyncLifetime.InitializeAsync() => DbFixture.DbHelper.ClearDataAsync(); | ||
|
||
private class TestCrmServiceClientProvider : ICrmServiceClientProvider | ||
{ | ||
private readonly IOrganizationServiceAsync2 _organizationService; | ||
|
||
public TestCrmServiceClientProvider(IOrganizationServiceAsync2 organizationService) | ||
{ | ||
_organizationService = organizationService; | ||
} | ||
|
||
public IOrganizationServiceAsync2 GetClient(string name) | ||
{ | ||
return _organizationService; | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
TeachingRecordSystem/tests/TeachingRecordSystem.Core.Tests/Jobs/SyncFromCrmJobTestBase.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,24 @@ | ||
using TeachingRecordSystem.Core.Dqt; | ||
using TeachingRecordSystem.Core.Services.TrsDataSync; | ||
|
||
namespace TeachingRecordSystem.Core.Tests.Jobs; | ||
|
||
public abstract class SyncFromCrmJobTestBase : IClassFixture<SyncFromCrmJobFixture> | ||
{ | ||
public SyncFromCrmJobTestBase(SyncFromCrmJobFixture jobFixture) | ||
{ | ||
JobFixture = jobFixture; | ||
} | ||
|
||
public SyncFromCrmJobFixture JobFixture { get; } | ||
|
||
protected TestableClock Clock => JobFixture.Clock; | ||
|
||
protected DbFixture DbFixture => JobFixture.DbFixture; | ||
|
||
protected TrsDataSyncHelper Helper => JobFixture.Helper; | ||
|
||
protected TestData TestData => JobFixture.TestData; | ||
|
||
public ICrmServiceClientProvider CrmServiceClientProvider => JobFixture.CrmServiceClientProvider; | ||
} |
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