public void ValidateConstruction_WhenValidatorReturnsFalse_ShouldThrowArgumentNullExceptionWithListOfErrors()
        {
            // Arrange
            EngineSettings                nullEngineSettings               = Substitute.For <EngineSettings>();
            ICalculationsRepository       mockCalculationRepository        = Substitute.For <ICalculationsRepository>();
            ICalculatorResiliencePolicies mockCalculatorResiliencePolicies = Substitute.For <ICalculatorResiliencePolicies>();
            var mockMessengerPolicy = Policy.NoOpAsync();
            var mockProviderResultsRepositoryPolicy = Policy.NoOpAsync();

            mockCalculatorResiliencePolicies.CacheProvider.Returns((Policy)null);
            mockCalculatorResiliencePolicies.Messenger.Returns(mockMessengerPolicy);
            mockCalculatorResiliencePolicies.ProviderSourceDatasetsRepository.Returns((Policy)null);
            mockCalculatorResiliencePolicies.ProviderResultsRepository.Returns(mockProviderResultsRepositoryPolicy);
            mockCalculatorResiliencePolicies.CalculationsRepository.Returns((Policy)null);
            IValidator <ICalculatorResiliencePolicies> validator = new CalculatorResiliencePoliciesValidator();

            // Act
            Action validateAction = () =>
            {
                CalculationEngineServiceValidator.ValidateConstruction(validator, nullEngineSettings, mockCalculatorResiliencePolicies, mockCalculationRepository);
            };

            // Assert
            validateAction
            .Should()
            .ThrowExactly <ArgumentNullException>()
            .And.Message
            .Should().Contain("CacheProvider")
            .And.Contain("ProviderSourceDatasetsRepository")
            .And.Contain("CalculationRepository");
        }
        public void ValidateConstruction_WhenEverythingIsSetupCorrectly_ShouldReturnWithoutThrowingException()
        {
            // Arrange
            EngineSettings                mockEngineSettings               = Substitute.For <EngineSettings>();
            ICalculationsRepository       mockCalculationRepository        = Substitute.For <ICalculationsRepository>();
            ICalculatorResiliencePolicies mockCalculatorResiliencePolicies = Substitute.For <ICalculatorResiliencePolicies>();
            IValidator <ICalculatorResiliencePolicies> validator           = Substitute.For <IValidator <ICalculatorResiliencePolicies> >();

            validator.Validate(mockCalculatorResiliencePolicies).Returns(new ValidationResult());

            // Act
            CalculationEngineServiceValidator.ValidateConstruction(validator, mockEngineSettings, mockCalculatorResiliencePolicies, mockCalculationRepository);
        }
        public CalculationEngineService(
            ILogger logger,
            ICalculationEngine calculationEngine,
            ICacheProvider cacheProvider,
            IMessengerService messengerService,
            IProviderSourceDatasetsRepository providerSourceDatasetsRepository,
            ITelemetry telemetry,
            IProviderResultsRepository providerResultsRepository,
            ICalculationsRepository calculationsRepository,
            EngineSettings engineSettings,
            ICalculatorResiliencePolicies resiliencePolicies,
            IValidator <ICalculatorResiliencePolicies> calculatorResiliencePoliciesValidator,
            IDatasetAggregationsRepository datasetAggregationsRepository,
            IFeatureToggle featureToggle,
            IJobsApiClient jobsApiClient)
        {
            _calculatorResiliencePoliciesValidator = calculatorResiliencePoliciesValidator;

            CalculationEngineServiceValidator.ValidateConstruction(_calculatorResiliencePoliciesValidator,
                                                                   engineSettings, resiliencePolicies, calculationsRepository);

            _logger            = logger;
            _calculationEngine = calculationEngine;
            _cacheProvider     = cacheProvider;
            _messengerService  = messengerService;
            _providerSourceDatasetsRepository = providerSourceDatasetsRepository;
            _telemetry = telemetry;
            _providerResultsRepository = providerResultsRepository;
            _calculationsRepository    = calculationsRepository;
            _engineSettings            = engineSettings;
            _cacheProviderPolicy       = resiliencePolicies.CacheProvider;
            _messengerServicePolicy    = resiliencePolicies.Messenger;
            _providerSourceDatasetsRepositoryPolicy = resiliencePolicies.ProviderSourceDatasetsRepository;
            _providerResultsRepositoryPolicy        = resiliencePolicies.ProviderResultsRepository;
            _calculationsRepositoryPolicy           = resiliencePolicies.CalculationsRepository;
            _datasetAggregationsRepository          = datasetAggregationsRepository;
            _featureToggle       = featureToggle;
            _jobsApiClient       = jobsApiClient;
            _jobsApiClientPolicy = resiliencePolicies.JobsApiClient;
        }
        public void ValidateConstruction_WhenEngineSettingsIsNull_ShouldThrowException()
        {
            // Arrange
            EngineSettings                nullEngineSettings               = null;
            ICalculationsRepository       mockCalculationRepository        = Substitute.For <ICalculationsRepository>();
            ICalculatorResiliencePolicies mockCalculatorResiliencePolicies = Substitute.For <ICalculatorResiliencePolicies>();
            IValidator <ICalculatorResiliencePolicies> validator           = Substitute.For <IValidator <ICalculatorResiliencePolicies> >();

            validator.Validate(mockCalculatorResiliencePolicies).Returns(new ValidationResult());

            // Act
            Action validateAction = () =>
            {
                CalculationEngineServiceValidator.ValidateConstruction(validator, nullEngineSettings, mockCalculatorResiliencePolicies, mockCalculationRepository);
            };

            // Assert
            validateAction
            .Should()
            .ThrowExactly <ArgumentNullException>()
            .And.Message
            .Should()
            .Contain("Parameter name: engineSettings");
        }