private IExtractionRequestFulfiller CreateRequestFulfiller(CohortExtractorOptions opts) { var c = WhenIHaveA <ExtractionInformation>().CatalogueItem.Catalogue; var t = c.GetTableInfoList(false).Single(); var repo = Repository.CatalogueRepository; foreach (string requiredColumn in new string[] { QueryToExecuteColumnSet.DefaultImagePathColumnName, QueryToExecuteColumnSet.DefaultStudyIdColumnName, QueryToExecuteColumnSet.DefaultSeriesIdColumnName, QueryToExecuteColumnSet.DefaultInstanceIdColumnName, }) { var ei = new ExtractionInformation(repo, new CatalogueItem(repo, c, "a"), new ColumnInfo(repo, requiredColumn, "varchar(10)", (TableInfo)t), requiredColumn); ei.ExtractionCategory = ExtractionCategory.Core; ei.SaveToDatabase(); } c.ClearAllInjections(); Assert.AreEqual(5, c.GetAllExtractionInformation(ExtractionCategory.Any).Length); var f = new MicroserviceObjectFactory(); var fulfiller = f.CreateInstance <IExtractionRequestFulfiller>(opts.RequestFulfillerType, typeof(IExtractionRequestFulfiller).Assembly, new object[] { new[] { c } }); if (fulfiller != null) { fulfiller.Rejectors.Add(f.CreateInstance <IRejector>(opts.RejectorType, typeof(TestRejector).Assembly) ?? new RejectNone()); } return(fulfiller); }
/// <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; }
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()); }
public ExtractionRequestQueueConsumer( CohortExtractorOptions options, IExtractionRequestFulfiller fulfiller, IAuditExtractions auditor, IProjectPathResolver pathResolver, IProducerModel fileMessageProducer, IProducerModel fileMessageInfoProducer) { _options = options; _fulfiller = fulfiller; _auditor = auditor; _resolver = pathResolver; _fileMessageProducer = fileMessageProducer; _fileMessageInfoProducer = fileMessageInfoProducer; }
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)); } } }
private IAuditExtractions CreateAuditor(CohortExtractorOptions opts) { var f = new MicroserviceObjectFactory(); return(f.CreateInstance <IAuditExtractions>(opts.AuditorType, typeof(IAuditExtractions).Assembly)); }