Exemple #1
0
        /// <summary>
        /// Creates a new instance of the host with the given
        /// </summary>
        /// <param name="options">Settings for the microservice (location of rabbit, queue names etc)</param>
        /// <param name="auditor">Optional override for the value specified in <see cref="GlobalOptions.CohortExtractorOptions"/></param>
        /// <param name="fulfiller">Optional override for the value specified in <see cref="GlobalOptions.CohortExtractorOptions"/></param>
        public CohortExtractorHost(GlobalOptions options, IAuditExtractions auditor, IExtractionRequestFulfiller fulfiller)
            : base(options)
        {
            _consumerOptions = options.CohortExtractorOptions;
            _consumerOptions.Validate();

            _auditor   = auditor;
            _fulfiller = fulfiller;
        }
Exemple #2
0
        public void UnitTest_Reflection_RejectorTypeNames(bool supplyRejectorName)
        {
            CohortExtractorOptions opts = new CohortExtractorOptions();

            opts.RequestFulfillerType = typeof(FromCataloguesExtractionRequestFulfiller).FullName;
            opts.RejectorType         = supplyRejectorName ? typeof(TestRejector).FullName : null;
            opts.Validate();

            var fulfiller = CreateRequestFulfiller(opts);

            Assert.IsInstanceOf(supplyRejectorName ? typeof(TestRejector): typeof(RejectNone), fulfiller.Rejectors.Single());
        }
Exemple #3
0
        public void UnitTest_Reflection_AuditorAndFulfillerTypeNames(Test testCase, bool fullName)
        {
            CohortExtractorOptions opts = new CohortExtractorOptions();

            //override
            switch (testCase)
            {
            case Test.Normal:
                opts.AuditorType          = fullName ? typeof(NullAuditExtractions).FullName : typeof(NullAuditExtractions).Name;
                opts.RequestFulfillerType = fullName ? typeof(FromCataloguesExtractionRequestFulfiller).FullName : typeof(FromCataloguesExtractionRequestFulfiller).Name;
                opts.Validate();
                break;

            case Test.NoAuditor:

                //no auditor is not a problem because it will just return NullAuditExtractions anyway
                opts.AuditorType          = "";
                opts.RequestFulfillerType = fullName ? typeof(FromCataloguesExtractionRequestFulfiller).FullName : typeof(FromCataloguesExtractionRequestFulfiller).Name;
                opts.Validate();
                break;

            case Test.NoFulfiller:
                opts.AuditorType          = fullName ? typeof(NullAuditExtractions).FullName : typeof(NullAuditExtractions).Name;
                opts.RequestFulfillerType = null;     //lets use null here just to cover both "" and null

                //no fulfiller is a problem!
                var ex = Assert.Throws <Exception>(() => opts.Validate());
                StringAssert.Contains("No RequestFulfillerType set on CohortExtractorOptions", ex.Message);

                break;

            default:
                throw new ArgumentOutOfRangeException("testCase");
            }

            //if user has not provided the full name
            if (!fullName)
            {
                //if no auditor is provided
                if (testCase == Test.NoAuditor)
                {
                    Assert.IsInstanceOf <NullAuditExtractions>(CreateAuditor(opts)); //this one gets created
                }
                else
                {
                    Assert.Throws <TypeLoadException>(() => CreateAuditor(opts)); //if an invalid auditor (not full name, we expect TypeLoadException)
                }
                //if no fulfiller is provided
                if (testCase == Test.NoFulfiller)
                {
                    Assert.IsNull(CreateRequestFulfiller(opts)); //we expect null to be returned
                }
                else
                {
                    Assert.Throws <TypeLoadException>(() => CreateRequestFulfiller(opts)); //if an invalid fulfiller (not full name we expect TypeLoadException)
                }
            }
            else
            {
                Assert.IsNotNull(CreateAuditor(opts));

                if (testCase == Test.NoFulfiller)
                {
                    Assert.IsNull(CreateRequestFulfiller(opts)); //we expect null to be returned
                }
                else
                {
                    Assert.IsNotNull(CreateRequestFulfiller(opts));
                }
            }
        }