public async Task Then_UpdateOrganisationStandardVersion(OrganisationStandardVersion version) { _mockOrganisationStandardRepository.Setup(repository => repository.GetOrganisationStandardVersionByOrganisationStandardIdAndVersion(It.IsAny <int>(), It.IsAny <string>())) .ReturnsAsync(version); _mockValidator.Setup(v => v.ValidatorUpdateOrganisationStandardVersionRequest(_request)) .ReturnsAsync(new ValidationResponse()); await _handler.Handle(_request, CancellationToken.None); _mockOrganisationStandardRepository.Verify( repository => repository.UpdateOrganisationStandardVersion(It.Is <OrganisationStandardVersion>(v => v.EffectiveFrom == _request.EffectiveFrom && v.EffectiveTo == _request.EffectiveTo)), Times.Once); }
public void When_Constructed_From_OrganisationStandardVersion_Then_Values_Should_Be_Copied(OrganisationStandardVersion sourceObject) { var objectUnderTest = new MergeOrganisationStandardVersion(sourceObject, "Before"); objectUnderTest.Replicates.Should().Be("Before"); objectUnderTest.StandardUid.Should().Be(sourceObject.StandardUId); objectUnderTest.Version.Should().Be(sourceObject.Version); objectUnderTest.OrganisationStandardId.Should().Be(sourceObject.OrganisationStandardId); objectUnderTest.EffectiveFrom.Should().Be(sourceObject.EffectiveFrom); objectUnderTest.EffectiveTo.Should().Be(sourceObject.EffectiveTo); objectUnderTest.Comments.Should().Be(sourceObject.Comments); objectUnderTest.Status.Should().Be(sourceObject.Status); objectUnderTest.DateVersionApproved.Should().Be(sourceObject.DateVersionApproved); }
public async Task <OrganisationStandardVersion> CreateOrganisationStandardVersion(OrganisationStandardVersion version) { await _unitOfWork.Connection.ExecuteAsync( @"INSERT INTO OrganisationStandardVersion (StandardUId, Version ,OrganisationStandardId, EffectiveFrom, EffectiveTo, DateVersionApproved, Comments, Status) VALUES (@StandardUId, @Version ,@OrganisationStandardId, @EffectiveFrom, @EffectiveTo, @DateVersionApproved, @Comments, @Status)", param : new { version.StandardUId, version.Version, version.OrganisationStandardId, version.EffectiveFrom, version.EffectiveTo, version.DateVersionApproved, version.Comments, version.Status }, transaction : _unitOfWork.Transaction); return(version); }
public async Task <OrganisationStandardVersion> UpdateOrganisationStandardVersion(OrganisationStandardVersion orgStandardVersion) { var sql = @"UPDATE [OrganisationStandardVersion] SET [EffectiveFrom] = @effectiveFrom, [EffectiveTo] = @effectiveTo, [DateVersionApproved] = @dateVersionApproved, [Status] = @status WHERE [OrganisationStandardId] = @orgStandardId AND [Version] = @version"; await _unitOfWork.Connection.ExecuteAsync( sql, param : new { effectiveFrom = orgStandardVersion.EffectiveFrom, effectiveTo = orgStandardVersion.EffectiveTo, dateVersionApproved = orgStandardVersion.DateVersionApproved, Status = orgStandardVersion.Status, orgStandardId = orgStandardVersion.OrganisationStandardId, version = orgStandardVersion.Version }, transaction : _unitOfWork.Transaction); return(orgStandardVersion); }
private void MergeOrganisationStandardsAndVersions(Organisation primaryOrganisation, Organisation secondaryOrganisation, string createdByUser, DateTime secondaryStandardsEffectiveTo) { // Grab the primary contact for the primary organisation because we're going to need it. var primaryContact = _dbContext.Contacts.FirstOrDefault(c => c.EndPointAssessorOrganisationId == primaryOrganisation.EndPointAssessorOrganisationId && c.Email == primaryOrganisation.PrimaryContact); // Read all the standards from the secondary organisation. foreach (var secondaryOrganisationStandard in secondaryOrganisation.OrganisationStandards) { // Does the primary organisation have this standard already? var primaryOrganisationStandard = primaryOrganisation.OrganisationStandards.FirstOrDefault(pos => pos.StandardCode == secondaryOrganisationStandard.StandardCode); if (null == primaryOrganisationStandard) { // No - so add the standard to the primary organisation. primaryOrganisationStandard = new OrganisationStandard() { DateStandardApprovedOnRegister = secondaryOrganisationStandard.DateStandardApprovedOnRegister, OrganisationStandardData = secondaryOrganisationStandard.OrganisationStandardData, Comments = $"This standard/version has been acquired from a merge with {secondaryOrganisation.EndPointAssessorOrganisationId} on {DateTime.UtcNow.ToString("dd MMM yyyy")}. {secondaryOrganisationStandard.Comments}", ContactId = primaryContact?.Id, EffectiveFrom = secondaryOrganisationStandard.EffectiveFrom, EffectiveTo = secondaryOrganisationStandard.EffectiveTo, EndPointAssessorOrganisationId = primaryOrganisation.EndPointAssessorOrganisationId, StandardCode = secondaryOrganisationStandard.StandardCode, StandardReference = secondaryOrganisationStandard.StandardReference, Status = secondaryOrganisationStandard.Status, OrganisationStandardVersions = new List <OrganisationStandardVersion>(), OrganisationStandardDeliveryAreas = new List <OrganisationStandardDeliveryArea>(), }; primaryOrganisationStandard.Comments = primaryOrganisationStandard.Comments.Substring(0, Math.Min(primaryOrganisationStandard.Comments.Length, 500)); primaryOrganisation.OrganisationStandards.Add(primaryOrganisationStandard); } // Now read all the versions for this standard for the secondary organisation. foreach (var secondaryOrganisationStandardVersion in secondaryOrganisationStandard.OrganisationStandardVersions) { // Does the standard version exist for this standard in the primary organisation? var primaryOrganisationStandardVersion = primaryOrganisationStandard.OrganisationStandardVersions.FirstOrDefault(posv => posv.StandardUId == secondaryOrganisationStandardVersion.StandardUId && posv.Version == secondaryOrganisationStandardVersion.Version); if (null == primaryOrganisationStandardVersion) { // No - so add the standard version to the standard for the primary organisation. primaryOrganisationStandardVersion = new OrganisationStandardVersion() { DateVersionApproved = secondaryOrganisationStandardVersion.DateVersionApproved, Comments = $"This standard/version has been acquired from a merge with {secondaryOrganisation.EndPointAssessorOrganisationId} on {DateTime.UtcNow.ToString("dd MMM yyyy")}. {secondaryOrganisationStandardVersion.Comments}", EffectiveFrom = secondaryOrganisationStandardVersion.EffectiveFrom, EffectiveTo = secondaryOrganisationStandardVersion.EffectiveTo, StandardUId = secondaryOrganisationStandardVersion.StandardUId, Status = secondaryOrganisationStandardVersion.Status, Version = secondaryOrganisationStandardVersion.Version, }; primaryOrganisationStandardVersion.Comments = primaryOrganisationStandardVersion.Comments.Substring(0, Math.Min(primaryOrganisationStandardVersion.Comments.Length, 500)); primaryOrganisationStandard.OrganisationStandardVersions.Add(primaryOrganisationStandardVersion); } // Mark the secondary standard version as ending secondaryOrganisationStandardVersion.EffectiveTo = secondaryStandardsEffectiveTo; secondaryOrganisationStandardVersion.Comments = $"This standard version has been merged in to {primaryOrganisation.EndPointAssessorOrganisationId} on {DateTime.UtcNow.ToString("dd MMM yyyy")}. ${secondaryOrganisationStandardVersion.Comments}"; secondaryOrganisationStandardVersion.Comments = secondaryOrganisationStandardVersion.Comments.Substring(0, Math.Min(secondaryOrganisationStandardVersion.Comments.Length, 500)); } foreach (var secondaryOrganisationStandardDeliveryArea in secondaryOrganisationStandard.OrganisationStandardDeliveryAreas) { // Does the primary organisation standard have this delivery area? var primaryOrganisationStandardDeliveryArea = primaryOrganisationStandard.OrganisationStandardDeliveryAreas.FirstOrDefault(posda => posda.DeliveryAreaId == secondaryOrganisationStandardDeliveryArea.DeliveryAreaId); if (null == primaryOrganisationStandardDeliveryArea) { // No - so add the area primaryOrganisationStandardDeliveryArea = new OrganisationStandardDeliveryArea() { DeliveryAreaId = secondaryOrganisationStandardDeliveryArea.DeliveryAreaId, Comments = $"This delivery area has been acquired from a merge with {secondaryOrganisation.EndPointAssessorOrganisationId} on {DateTime.UtcNow.ToString("dd MMM yyyy")}. {secondaryOrganisationStandardDeliveryArea.Comments}", Status = secondaryOrganisationStandardDeliveryArea.Status, OrganisationStandard = primaryOrganisationStandard, DeliveryArea = secondaryOrganisationStandardDeliveryArea.DeliveryArea, }; primaryOrganisationStandardDeliveryArea.Comments = primaryOrganisationStandardDeliveryArea.Comments.Substring(0, Math.Min(primaryOrganisationStandardDeliveryArea.Comments.Length, 500)); primaryOrganisationStandard.OrganisationStandardDeliveryAreas.Add(primaryOrganisationStandardDeliveryArea); } secondaryOrganisationStandardDeliveryArea.Comments = $"This delivery area has been merged in to {primaryOrganisation.EndPointAssessorOrganisationId} on {DateTime.UtcNow.ToString("dd MMM yyyy")}. {secondaryOrganisationStandardDeliveryArea.Comments}"; secondaryOrganisationStandardDeliveryArea.Comments = secondaryOrganisationStandardDeliveryArea.Comments.Substring(0, Math.Min(secondaryOrganisationStandardDeliveryArea.Comments.Length, 500)); } // Now set the effectiveTo and comments @ToDo: need content secondaryOrganisationStandard.EffectiveTo = secondaryStandardsEffectiveTo; secondaryOrganisationStandard.Comments = $"This standard has been merged in to Organisation {primaryOrganisation.EndPointAssessorOrganisationId} on {DateTime.UtcNow.ToString("dd MMM yyyy")}. {secondaryOrganisationStandard.Comments}"; secondaryOrganisationStandard.Comments = secondaryOrganisationStandard.Comments.Substring(0, Math.Min(secondaryOrganisationStandard.Comments.Length, 500)); } }