Rank: Advanced Member
Groups: Registered
Joined: 9/21/2016(UTC) Posts: 31 Location: Austria
Thanks: 8 times Was thanked: 8 time(s) in 7 post(s)
|
Today we added a SuppressMessage to method and a using: using System.Diagnostics.CodeAnalysis; And as soon as I add the using ncrunch starts to failing running the tests with this error: NCrunch was unable to retrieve a meaningful result from this test due to an unexpected error - was the execution process terminated? When I remove this using and add the SuppressMessage like this [System.Diagnostics.CodeAnalysis.SuppressMessage] Ncrunch is working fine --> however I can't do this becaue we have code cleanup enabled that will create the using again. It's a .net 5.0 solution and the same error occurrs with this version NCrunch_VS2019_4.7.0.3.msi At the moment we can't reproduce it in a sample project, we only have a more detailed log from nCrunch, I know it's not much, any idea how I can provide you more information? https://drive.google.com...Ob6eSi/view?usp=sharing
Here is the class Code:
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Upper.PrintProcessingManager.Domain.DataProvider;
using Upper.PrintProcessingManager.Domain.Excel.Print;
using Upper.PrintProcessingManager.Domain.Gateways;
using Upper.PrintProcessingManager.Domain.Gateways.MediaManager;
using Upper.PrintProcessingManager.Domain.Services.DocumentGeneration.Calculator;
namespace Upper.PrintProcessingManager.Domain.Services.DocumentGeneration.ExcelDataGeneration
{
public class PackageDetailsPrintDeliveryDataGenerator
{
private readonly ICirculationAmountCalculator _circulationAmountCalculator;
private readonly ITranslationService _translationService;
public PackageDetailsPrintDeliveryDataGenerator(ICirculationAmountCalculator circulationAmountCalculator, ITranslationService translationService)
{
_circulationAmountCalculator = circulationAmountCalculator;
_translationService = translationService;
}
[SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "not nullable")]
public PackageDetailsPrintDelivery GeneratePrintDeliveryData(PrintDeliveryProjectDetail projectDetail, DateTime createdAt, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<Branch> branches, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculations, IReadOnlyCollection<HouseCirculation> houseCirculations)
{
return new(createdAt, projectDetail.PrintingCompany, CreatePublications(projectDetail, packageVersions, branches, distributionCirculations, houseCirculations));
}
private IReadOnlyCollection<PrintDeliveryPublication> CreatePublications(PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<Branch> branches, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculations, IReadOnlyCollection<HouseCirculation> houseCirculations)
{
return packageVersions
.Where(packageVersion => packageVersion.BranchPublications.Any(branchPublication => branchPublication.ProjectId == projectDetail.ExternalProjectId))
.GroupBy(key => key.BranchPublications.Single(branchPublication => branchPublication.ProjectId == projectDetail.ExternalProjectId).PublicationShortName)
.Select(group => CreatePublication(group.Key, projectDetail, group.ToList(), branches, distributionCirculations, houseCirculations))
.OrderBy(publication => publication.PublicationShortName)
.ToList();
}
private PrintDeliveryPublication CreatePublication(string publicationShortName, PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<Branch> branches, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculations, IReadOnlyCollection<HouseCirculation> houseCirculations)
{
return new(publicationShortName, CreateProjectName(projectDetail.ProjectName, publicationShortName), 0, CreateRecipientTypes(projectDetail, packageVersions, branches, distributionCirculations, houseCirculations));
}
private IReadOnlyCollection<PrintDeliveryRecipientType> CreateRecipientTypes(PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<Branch> branches, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculations, IReadOnlyCollection<HouseCirculation> houseCirculations)
{
List<PrintDeliveryRecipientType> printDeliveryRecipientTypes = new();
IReadOnlyCollection<PackageVersion> packagedDeliveries = packageVersions
.Where(packageVersion => packageVersion.BranchPublications.Count > 1)
.ToList();
if (packagedDeliveries.Any())
{
printDeliveryRecipientTypes.Add(CreateRecipientType(RecipientType.PrintProcessor, projectDetail, packagedDeliveries, branches, distributionCirculations, houseCirculations));
}
IReadOnlyCollection<PackageVersion> soloDeliveries = packageVersions
.Where(packageVersion => packageVersion.BranchPublications.Count == 1)
.ToList();
if (soloDeliveries.Any())
{
printDeliveryRecipientTypes.Add(CreateRecipientType(RecipientType.Distributor, projectDetail, soloDeliveries, branches, distributionCirculations, houseCirculations));
}
if (packageVersions.Any())
{
printDeliveryRecipientTypes.Add(CreateRecipientType(RecipientType.Branch, projectDetail, packageVersions, branches, distributionCirculations, houseCirculations));
}
return printDeliveryRecipientTypes;
}
private PrintDeliveryRecipientType CreateRecipientType(RecipientType recipientType, PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<Branch> branches, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculations, IReadOnlyCollection<HouseCirculation> houseCirculations)
{
return new(recipientType, CreateBranches(recipientType, projectDetail, packageVersions, branches, distributionCirculations, houseCirculations));
}
private IReadOnlyCollection<PrintDeliveryBranch> CreateBranches(RecipientType recipientType, PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<Branch> branches, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculations, IReadOnlyCollection<HouseCirculation> houseCirculations)
{
return packageVersions.GroupBy(
packageVersion => new
{
packageVersion.BranchPublications.Single(BranchPublication => projectDetail.ExternalProjectId == BranchPublication.ProjectId).BranchId,
packageVersion.CountryId
})
.Select(branchGroup => CreateBranch(recipientType, branchGroup.Key.BranchId, branchGroup.Key.CountryId, projectDetail, branchGroup.ToList(), branches, distributionCirculations, houseCirculations))
.OrderBy(branch => branch.BranchName)
.ThenBy(branch => branch.TargetCountryId)
.ToList();
}
private PrintDeliveryBranch CreateBranch(RecipientType recipientType, string branchId, string countryId, PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<Branch> branches, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculations, IReadOnlyCollection<HouseCirculation> houseCirculations)
{
IReadOnlyCollection<PrintDeliveryDistributionInformation> printDeliveryDistributionInformation = recipientType switch
{
RecipientType.Distributor => CreateGroupedSoloDistributionInformation(projectDetail, packageVersions, distributionCirculations),
RecipientType.PrintProcessor => CreateGroupedPackagedDistributionInformation(projectDetail, packageVersions, distributionCirculations),
RecipientType.Branch => CreateHouseCirculationDistributionInformation(branchId, countryId, projectDetail, packageVersions, houseCirculations),
_ => throw new ArgumentOutOfRangeException(nameof(recipientType))
};
return new PrintDeliveryBranch(branches.Single(branch => branch.BranchId == branchId).Name, countryId, printDeliveryDistributionInformation);
}
private static IReadOnlyCollection<PrintDeliveryDistributionInformation> CreateHouseCirculationDistributionInformation(string branchId, string countryId, PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<HouseCirculation> houseCirculations)
{
DateTime earliestToDistributorDate = packageVersions
.Select(packageVersion => GetDistributionScenario(projectDetail, packageVersion))
.Min(distributionScenario => distributionScenario.ToDistributorDate);
int amount = houseCirculations.Single(houseCirculation => houseCirculation.BranchId == branchId
&& houseCirculation.CountryId == countryId
&& houseCirculation.ProjectId == projectDetail.ExternalProjectId)
.Amount;
return new[]
{
new PrintDeliveryDistributionInformation(amount, ExcelDataGenerationResource.HouseCirculationFixedName, null, earliestToDistributorDate, null, null)
};
}
private IReadOnlyCollection<PrintDeliveryDistributionInformation> CreateGroupedSoloDistributionInformation(PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculations)
{
return packageVersions.GroupBy(packageVersion =>
{
TourCirculationDetail tourCirculationDetail = distributionCirculations.Single(distributionCirculation => distributionCirculation.DistributionSet.Id == packageVersion.DistributionSetId)
.DistributorCirculationDetails.Single(distributor => distributor.DistributorId == packageVersion.DistributorId)
.TourCirculationDetails.Single(tour => tour.TourId == packageVersion.TourId);
return new
{
packageVersion.DistributorId,
packageVersion.DistributorName,
GetDistributionScenario(projectDetail, packageVersion)
.ToDistributorDate,
tourCirculationDetail
.DeliveryAddress,
tourCirculationDetail
.PackagingShortname
};
})
.Select(group => CreateToDistributorDistributionInformation(group.Key.DistributorName, group.Key.ToDistributorDate, group.Key.DeliveryAddress, group.Key.PackagingShortname, group.ToList(), distributionCirculations))
.ToList();
}
private IReadOnlyCollection<PrintDeliveryDistributionInformation> CreateGroupedPackagedDistributionInformation(PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculationCollectionResults)
{
return packageVersions.GroupBy(packageVersion =>
{
PrintDeliveryDistributionScenario distributionScenario = GetDistributionScenario(projectDetail, packageVersion);
return new
{
distributionScenario.ToPrintProcessorDate,
distributionScenario.PrintProcessorName
};
})
.Select(group => CreateToPrintProcessorDistributionInformation(group.Key.PrintProcessorName, group.Key.ToPrintProcessorDate, group.ToList(), distributionCirculationCollectionResults))
.ToList();
}
private PrintDeliveryDistributionInformation CreateToDistributorDistributionInformation(string distributorName, DateTime toDistributorDate, DeliveryAddress deliveryAddress, string packagingShortname, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculationCollectionResults)
{
PrintDeliveryAddress address = new(deliveryAddress.Name,
deliveryAddress.AdditionalInformation,
deliveryAddress.CountryId,
deliveryAddress.ZipCode,
deliveryAddress.City,
deliveryAddress.Street,
_translationService.TranslatePackaging(packagingShortname));
int amount = _circulationAmountCalculator.GetTourCirculationAmount(packageVersions, distributionCirculationCollectionResults);
return new PrintDeliveryDistributionInformation(amount, distributorName, null, toDistributorDate, "", address);
}
private PrintDeliveryDistributionInformation CreateToPrintProcessorDistributionInformation(string printProcessorName, DateTime toPrintProcessorDate, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculationCollectionResults)
{
int amount = _circulationAmountCalculator.GetTourCirculationAmount(packageVersions, distributionCirculationCollectionResults);
return new PrintDeliveryDistributionInformation(amount, printProcessorName, toPrintProcessorDate, null, null, null);
}
private static PrintDeliveryDistributionScenario GetDistributionScenario(PrintDeliveryProjectDetail projectDetail, PackageVersion packageVersion)
{
return projectDetail.DistributionScenarios
.Single(scenario => scenario.ExternalX3ScenarioId == packageVersion.BranchPublications
.Single(branchPublication => branchPublication.ProjectId == projectDetail.ExternalProjectId)
.ExternalX3DistributionScenarioId);
}
private static string CreateProjectName(string projectName, string publicationShortname)
{
return $"{projectName} ({publicationShortname})";
}
}
}
|