public void Changed_answer_maps_to_linked_field_correctly( CentreAnswersData oldAnswers, CentreAnswersData newAnswers, string expectedLinkedFieldName, int expectedLinkedFieldNumber, string expectedOldValue, string expectedNewValue ) { // Given A.CallTo(() => centreCustomPromptsService.GetPromptNameForCentreAndPromptNumber(A <int> ._, A <int> ._)) .Returns(expectedLinkedFieldName); var expectedResult = new List <LinkedFieldChange> { new LinkedFieldChange( expectedLinkedFieldNumber, expectedLinkedFieldName, expectedOldValue, expectedNewValue ) }; // When var result = LinkedFieldHelper.GetLinkedFieldChanges( oldAnswers, newAnswers, jobGroupsDataService, centreCustomPromptsService ); // Then result.Should().BeEquivalentTo(expectedResult); }
public void SynchroniseUserChangesWithGroups( DelegateUser delegateAccountWithOldDetails, AccountDetailsData newDelegateDetails, CentreAnswersData newCentreAnswers ) { var changedLinkedFields = LinkedFieldHelper.GetLinkedFieldChanges( delegateAccountWithOldDetails.GetCentreAnswersData(), newCentreAnswers, jobGroupsDataService, centreCustomPromptsService ); var allSynchronisedGroupsAtCentre = GetSynchronisedGroupsForCentre(delegateAccountWithOldDetails.CentreId).ToList(); foreach (var changedAnswer in changedLinkedFields) { var groupToRemoveDelegateFrom = allSynchronisedGroupsAtCentre.SingleOrDefault( g => g.LinkedToField == changedAnswer.LinkedFieldNumber && GroupLabelMatchesAnswer(g.GroupLabel, changedAnswer.OldValue, changedAnswer.LinkedFieldName) ); var groupToAddDelegateTo = allSynchronisedGroupsAtCentre.SingleOrDefault( g => g.LinkedToField == changedAnswer.LinkedFieldNumber && GroupLabelMatchesAnswer(g.GroupLabel, changedAnswer.NewValue, changedAnswer.LinkedFieldName) ); using var transaction = new TransactionScope(); if (groupToRemoveDelegateFrom != null) { RemoveDelegateFromGroup(delegateAccountWithOldDetails.Id, groupToRemoveDelegateFrom.GroupId); } if (groupToAddDelegateTo != null) { groupsDataService.AddDelegateToGroup( delegateAccountWithOldDetails.Id, groupToAddDelegateTo.GroupId, clockService.UtcNow, 1 ); EnrolDelegateOnGroupCourses( delegateAccountWithOldDetails, newDelegateDetails, groupToAddDelegateTo.GroupId ); } transaction.Complete(); } }