public void GetYesNoResponse_NegativeCases(string inputValue)
        {
            TextReader testTextReader = new StringReader(inputValue);
            var        inputManager   = new ConsoleInputManager(testTextReader);

            Assert.IsFalse(inputManager.GetYesNoResponse());
        }
예제 #2
0
        /// <summary>
        /// Initialize the server with the given port, or ask for a port from the command line.
        /// </summary>
        /// <param name="args">The command line arguments.</param>
        public void Initialize(string[] args)
        {
            var consoleInputManager = new ConsoleInputManager();

            Logger.SetLogger(new ConsoleLogger(consoleInputManager));

            if (args.Length < 1)
            {
                Logger.Get().Error(this, "Please provide a port in the arguments");
                return;
            }

            if (string.IsNullOrEmpty(args[0]) || !ParsePort(args[0], out var port))
            {
                Logger.Get().Error(this, "Invalid port, should be an integer between 0 and 65535");
                return;
            }

            var gameSettings = ConfigManager.LoadGameSettings(out var existed);

            if (!existed)
            {
                ConfigManager.SaveGameSettings(gameSettings);
            }

            StartServer(port, gameSettings, consoleInputManager);
        }
예제 #3
0
        /// <summary>
        /// Will start the server with the given port and game settings.
        /// </summary>
        /// <param name="port">The port of the server.</param>
        /// <param name="gameSettings">The game settings for the server.</param>
        /// <param name="consoleInputManager">The input manager for command-line input.</param>
        private void StartServer(
            int port,
            GameSettings gameSettings,
            ConsoleInputManager consoleInputManager
            )
        {
            Logger.Get().Info(this, $"Starting server v{Version.String}");

            var packetManager = new PacketManager();

            var netServer = new NetServer(packetManager);

            var serverManager = new ConsoleServerManager(netServer, gameSettings, packetManager);

            serverManager.Initialize();
            serverManager.Start(port);

            consoleInputManager.ConsoleInputEvent += input => {
                if (!serverManager.TryProcessCommand(new ConsoleCommandSender(), "/" + input))
                {
                    Logger.Get().Info(this, $"Unknown command: {input}");
                }
            };
            consoleInputManager.StartReading();
        }
예제 #4
0
        public void Test_ListSupportedCommands_NoPicker()
        {
            var mgr     = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier());
            var invoker = new CommandInvoker(mgr);

            invoker.ExecuteCommand(typeof(ExecuteCommandListSupportedCommands), null);
        }
예제 #5
0
        public void TestIPluginCohortCompiler_PopulatesCacheCorrectly()
        {
            var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier())
            {
                DisallowInput = true
            };

            // create a cohort config
            var cic = new CohortIdentificationConfiguration(CatalogueRepository, "mycic");

            cic.QueryCachingServer_ID = externalDatabaseServer.ID;
            cic.SaveToDatabase();

            // this special Catalogue will be detected by ExamplePluginCohortCompiler and interpreted as an API call
            var myApi = new Catalogue(CatalogueRepository, ExamplePluginCohortCompiler.ExampleAPIName);

            // add it to the cohort config
            cic.CreateRootContainerIfNotExists();

            // create a use of the API as an AggregateConfiguration
            var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(activator, new CatalogueCombineable(myApi), cic.RootCohortAggregateContainer);

            Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible);
            cmd.Execute();

            // run the cic
            var source = new CohortIdentificationConfigurationSource();

            source.PreInitialize(cic, new ThrowImmediatelyDataLoadEventListener());
            var dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken());

            // 5 random chi numbers
            Assert.AreEqual(5, dt.Rows.Count);

            // test stale
            cmd.AggregateCreatedIfAny.Description = "2";
            cmd.AggregateCreatedIfAny.SaveToDatabase();

            // run the cic again
            source = new CohortIdentificationConfigurationSource();
            source.PreInitialize(cic, new ThrowImmediatelyDataLoadEventListener());
            dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken());

            // because the rules changed to generate 2 chis only there should be a new result
            Assert.AreEqual(2, dt.Rows.Count);

            var results = new[] { (string)dt.Rows[0][0], (string)dt.Rows[1][0] };

            // run the cic again with no changes, the results should be unchanged since there is no config changed
            // I.e. no new chis should be generated and the cached values returned
            source = new CohortIdentificationConfigurationSource();
            source.PreInitialize(cic, new ThrowImmediatelyDataLoadEventListener());
            dt = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken());

            Assert.AreEqual(2, dt.Rows.Count);
            var results2 = new[] { (string)dt.Rows[0][0], (string)dt.Rows[1][0] };

            Assert.AreEqual(results[0], results2[0]);
            Assert.AreEqual(results[1], results2[1]);
        }
예제 #6
0
        public void TestDisallowInput()
        {
            var manager = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier());
            manager.DisallowInput = true;

            Assert.Throws<InputDisallowedException>(()=>manager.GetString("bob", null));
        }
예제 #7
0
        public int Run(IRDMPPlatformRepositoryServiceLocator repositoryLocator, IDataLoadEventListener listener,
                       ICheckNotifier checkNotifier, GracefulCancellationToken token)
        {
            _input    = new ConsoleInputManager(repositoryLocator, checkNotifier);
            _listener = listener;
            _invoker  = new CommandInvoker(_input);
            _invoker.CommandImpossible += (s, c) => Console.WriteLine($"Command Impossible:{c.Command.ReasonCommandImpossible}");
            _invoker.CommandCompleted  += (s, c) => Console.WriteLine("Command Completed");

            _commands = _invoker.GetSupportedCommands().ToDictionary(
                k => BasicCommandExecution.GetCommandName(k.Name),
                v => v, StringComparer.CurrentCultureIgnoreCase);

            _picker =
                _options.CommandArgs != null && _options.CommandArgs.Any() ?
                new CommandLineObjectPicker(_options.CommandArgs, repositoryLocator) :
                null;

            if (string.IsNullOrWhiteSpace(_options.CommandName))
            {
                RunCommandExecutionLoop(repositoryLocator);
            }
            else
            {
                RunCommand(_options.CommandName);
            }

            return(0);
        }
        public void GetDirection_NegativeCases(string inputValue)
        {
            TextReader testTextReader = new StringReader(inputValue);
            var        inputManager   = new ConsoleInputManager(testTextReader);
            var        directionValue = inputManager.GetDirection();

            Assert.IsFalse(directionValue.HasValue);
        }
예제 #9
0
파일: RunUITests.cs 프로젝트: rkm/RDMP
        public void Test_IsSupported_BasicActivator(Type t)
        {
            IBasicActivateItems basic = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier());

            var commandCaller = new CommandInvoker(basic);

            Assert.IsTrue(commandCaller.IsSupported(t));
        }
        public void GetDirection_PositiveCases(string inputVal, PlayerDirection expectedDirection)
        {
            TextReader testTextReader = new StringReader(inputVal);
            var        inputManager   = new ConsoleInputManager(testTextReader);
            var        directionValue = inputManager.GetDirection();

            Assert.IsTrue(directionValue.HasValue);
            Assert.AreEqual(expectedDirection, directionValue.Value);
        }
예제 #11
0
        public void Test_Delete_WithPicker()
        {
            var mgr     = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier());
            var invoker = new CommandInvoker(mgr);

            WhenIHaveA <Catalogue>();

            var picker = new CommandLineObjectPicker(new[] { "Catalogue:*" }, RepositoryLocator);

            invoker.ExecuteCommand(typeof(ExecuteCommandDelete), picker);
        }
        public void TestImportTree_FromCohortIdentificationConfiguration_ToSelectedDatasets_PreserveOperation()
        {
            var sds = WhenIHaveA <SelectedDataSets>();

            var cata = sds.ExtractableDataSet.Catalogue;

            var cic = new CohortIdentificationConfiguration(Repository, "my cic");

            cic.CreateRootContainerIfNotExists();

            var ac = new AggregateConfiguration(Repository, cata, "myagg");

            ac.CreateRootContainerIfNotExists();
            cic.RootCohortAggregateContainer.AddChild(ac, 1);

            var filterToImport = new AggregateFilter(Repository, "MyFilter")
            {
                WhereSQL = "true"
            };
            var root = ac.RootFilterContainer;

            root.AddChild(filterToImport);
            root.Operation = FilterContainerOperation.OR;
            root.SaveToDatabase();

            // add 2 subcontainers, these should also get cloned and should preserve the Operation correctly
            root.AddChild(new AggregateFilterContainer(Repository, FilterContainerOperation.AND));
            root.AddChild(new AggregateFilterContainer(Repository, FilterContainerOperation.OR));

            //there should be no root container
            Assert.IsNull(sds.RootFilterContainer);

            //run the command
            var mgr = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier());

            mgr.DisallowInput = true;
            var cmd = new ExecuteCommandImportFilterContainerTree(mgr, sds, ac);

            Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible);
            cmd.Execute();

            sds.ClearAllInjections();
            Assert.AreEqual(FilterContainerOperation.OR, sds.RootFilterContainer.Operation);
            Assert.IsNotNull(sds.RootFilterContainer);
            Assert.AreEqual(1, sds.RootFilterContainer.GetFilters().Length);

            var subContainers = sds.RootFilterContainer.GetSubContainers();

            Assert.AreEqual(2, subContainers.Length);
            Assert.AreEqual(1, subContainers.Count(e => e.Operation == FilterContainerOperation.AND));
            Assert.AreEqual(1, subContainers.Count(e => e.Operation == FilterContainerOperation.OR));
        }
예제 #13
0
        public void Test_Generic_WithPicker()
        {
            var mgr     = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier());
            var invoker = new CommandInvoker(mgr);

            WhenIHaveA <Catalogue>();

            invoker.ExecuteCommand(typeof(GenericTestCommand <DatabaseEntity>), GetPicker("Catalogue:*"));
            invoker.ExecuteCommand(typeof(GenericTestCommand <Type>), GetPicker("Pipeline"));
            invoker.ExecuteCommand(typeof(GenericTestCommand <DiscoveredDatabase, bool>),
                                   GetPicker(
                                       "DatabaseType:MicrosoftSqlServer:Name:imaging:Server=localhost\\sqlexpress;Database=master;Trusted_Connection=True;",
                                       "true"));
        }
예제 #14
0
        static void Main(string[] args)
        {
            ConsoleInputManager inputManager = new ConsoleInputManager();

            UpperRightCoordinateModel upperRightCoordinate = inputManager.Get <UpperRightCoordinateModel>(new UpperRightInputMessage(), new UpperRightInputValidation(), new UpperRightInputParser());

            MarsRoverPositionModel marsRoverPosition = inputManager.Get <MarsRoverPositionModel>(new MarsRoverPositionInputMessage(), new MarsRoverPositionInputValidation(), new MarsRoverPositionInputParser());

            List <char> roverInstructions = inputManager.Get <List <char> >(new RoverInstructionInputMessage(), new RoverInstructionInputValidation(), new RoverInstructionInputParser());

            MarsRoverManager MarsRoverManager = new MarsRoverManager(marsRoverPosition, upperRightCoordinate);

            var result = MarsRoverManager.Run(roverInstructions);

            Console.WriteLine(result.ToString());

            Console.ReadLine();
        }
예제 #15
0
        public void TestImportTree_FromSelectedDatasets_ToCohortIdentificationConfiguration()
        {
            // Import From Selected Dataset
            var sds = WhenIHaveA <SelectedDataSets>();

            sds.CreateRootContainerIfNotExists();

            var filterToImport = new DeployedExtractionFilter(Repository, "MyFilter", (FilterContainer)sds.RootFilterContainer)
            {
                WhereSQL = "true"
            };

            filterToImport.SaveToDatabase();

            var cata = sds.ExtractableDataSet.Catalogue;

            // Into an Aggregate Configuration
            var cic = new CohortIdentificationConfiguration(Repository, "my cic");

            cic.CreateRootContainerIfNotExists();
            var ac = new AggregateConfiguration(Repository, cata, "myagg");

            cic.RootCohortAggregateContainer.AddChild(ac, 1);

            //there should be no root container
            Assert.IsNull(ac.RootFilterContainer);

            //run the command
            var mgr = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier());

            mgr.DisallowInput = true;
            var cmd = new ExecuteCommandImportFilterContainerTree(mgr, ac, sds);

            Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible);
            cmd.Execute();

            ac.ClearAllInjections();
            Assert.IsNotNull(ac.RootFilterContainer);
            Assert.AreEqual(1, ac.RootFilterContainer.GetFilters().Length);
            Assert.AreEqual("MyFilter", ac.RootFilterContainer.GetFilters()[0].Name);
            Assert.AreEqual("true", ac.RootFilterContainer.GetFilters()[0].WhereSQL);

            Assert.AreNotEqual(filterToImport.GetType(), ac.RootFilterContainer.GetFilters()[0].GetType());
        }
예제 #16
0
        public int Run(IRDMPPlatformRepositoryServiceLocator repositoryLocator, IDataLoadEventListener listener,
                       ICheckNotifier checkNotifier, GracefulCancellationToken token)
        {
            _input = new ConsoleInputManager(repositoryLocator, checkNotifier);
            // if there is a single command we are running then disable user input
            // but allow it if the input is ./rdmp cmd (i.e. run in a loop prompting for commands)
            _input.DisallowInput = !string.IsNullOrWhiteSpace(_options.CommandName);

            _listener = listener;
            _invoker  = new CommandInvoker(_input);
            _invoker.CommandImpossible += (s, c) => Console.WriteLine($"Command Impossible:{c.Command.ReasonCommandImpossible}");
            _invoker.CommandCompleted  += (s, c) => Console.WriteLine("Command Completed");

            _commands = _invoker.GetSupportedCommands().ToDictionary(
                k => BasicCommandExecution.GetCommandName(k.Name),
                v => v, StringComparer.CurrentCultureIgnoreCase);

            _picker =
                _options.CommandArgs != null && _options.CommandArgs.Any() ?
                new CommandLineObjectPicker(_options.CommandArgs, _input) :
                null;

            if (!string.IsNullOrWhiteSpace(_options.File) && _options.Script == null)
            {
                throw new Exception("Command line option File was provided but Script property was null.  The host API failed to deserialize the file or correctly use the ExecuteCommandOptions class");
            }

            if (_options.Script != null)
            {
                RunScript(_options.Script, repositoryLocator);
            }
            else
            if (string.IsNullOrWhiteSpace(_options.CommandName))
            {
                RunCommandExecutionLoop(repositoryLocator);
            }
            else
            {
                RunCommand(_options.CommandName);
            }

            return(0);
        }
예제 #17
0
        public void TestIPluginCohortCompiler_APIsCantHavePatientIndexTables()
        {
            var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier())
            {
                DisallowInput = true
            };

            // create a cohort config
            var cic = new CohortIdentificationConfiguration(CatalogueRepository, "mycic");

            cic.QueryCachingServer_ID = externalDatabaseServer.ID;
            cic.SaveToDatabase();

            // this special Catalogue will be detected by ExamplePluginCohortCompiler and interpreted as an API call
            var myApi = new Catalogue(CatalogueRepository, ExamplePluginCohortCompiler.ExampleAPIName);

            // add it to the cohort config
            cic.CreateRootContainerIfNotExists();

            // We need something in the root container otherwise the cic won't build
            var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(activator, new CatalogueCombineable(myApi), cic.RootCohortAggregateContainer);

            Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible);
            cmd.Execute();
            var regularAggregate = cmd.AggregateCreatedIfAny;

            // The thing we are wanting to test - creating a use of the API as a patient index table
            var cmd2 = new ExecuteCommandAddCatalogueToCohortIdentificationAsPatientIndexTable(
                activator, new CatalogueCombineable(myApi), cic);

            Assert.IsFalse(cmd2.IsImpossible, cmd2.ReasonCommandImpossible);
            cmd2.Execute();

            var joinables = cic.GetAllJoinables();

            // make them join one another
            var ex = Assert.Throws <NotSupportedException>(() =>
                                                           new JoinableCohortAggregateConfigurationUse(CatalogueRepository, regularAggregate, joinables[0]));

            Assert.AreEqual("API calls cannot join with PatientIndexTables (The API call must be self contained)", ex.Message);
        }
예제 #18
0
        public void Test(DatabaseType dbType)
        {
            var db = GetCleanedServer(dbType);

            var dt = new DataTable();

            dt.Columns.Add("fff");
            dt.Rows.Add("1");
            dt.Rows.Add("1");
            dt.Rows.Add("2");
            dt.Rows.Add("2");
            dt.Rows.Add("2");

            var tbl = db.CreateTable("MyTable", dt);

            Import(tbl, out ITableInfo tblInfo, out _);

            Assert.AreEqual(5, tbl.GetRowCount());

            var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier())
            {
                DisallowInput = true
            };

            var cmd = new ExecuteCommandAlterTableMakeDistinct(activator, tblInfo, 700, true);

            Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible);

            cmd.Execute();

            Assert.AreEqual(2, tbl.GetRowCount());

            tbl.CreatePrimaryKey(tbl.DiscoverColumn("fff"));

            cmd = new ExecuteCommandAlterTableMakeDistinct(activator, tblInfo, 700, true);

            var ex = Assert.Throws <Exception>(() => cmd.Execute());

            Assert.AreEqual("Table 'MyTable' has primary key columns so cannot contain duplication", ex.Message);
        }
예제 #19
0
        static void Main(string[] args)
        {
            var _outputManager = new ConsoleOutputManager();
            var _inputManager  = new ConsoleInputManager(_outputManager);
            var _safeExecutor  = new SafeExecuteManager(_outputManager);

            var menu    = new MenuManager(_outputManager, _inputManager);
            var counter = new SumCounter();

            //ToTestRecalculating(counter, menu);

            var values = menu.AskForCalculatingValues();

            _safeExecutor.ExecuteWithExceptionHandling(() =>
            {
                counter.CalculateSumAsync((int)values.start, (int)values.limit).ContinueWith(result => menu.DisplayResultMessage(values, result.Result));
            });

            menu.DisplayStartingCalculatingMessage();

            Console.ReadLine();
        }
예제 #20
0
        public void TestIPluginCohortCompiler_TestCloneCic()
        {
            var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier())
            {
                DisallowInput = true
            };

            // create a cohort config
            var cic = new CohortIdentificationConfiguration(CatalogueRepository, "mycic");

            cic.QueryCachingServer_ID = externalDatabaseServer.ID;
            cic.SaveToDatabase();

            // this special Catalogue will be detected by ExamplePluginCohortCompiler and interpreted as an API call
            var myApi = new Catalogue(CatalogueRepository, ExamplePluginCohortCompiler.ExampleAPIName);

            // add it to the cohort config
            cic.CreateRootContainerIfNotExists();

            // create a use of the API as an AggregateConfiguration
            var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(activator, new CatalogueCombineable(myApi), cic.RootCohortAggregateContainer);

            Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible);
            cmd.Execute();
            cmd.AggregateCreatedIfAny.Description = "33";
            cmd.AggregateCreatedIfAny.SaveToDatabase();

            // clone the cic
            var cmd2 = new ExecuteCommandCloneCohortIdentificationConfiguration(activator, cic);

            Assert.IsFalse(cmd2.IsImpossible, cmd2.ReasonCommandImpossible);
            cmd2.Execute();

            var cloneAc = cmd2.CloneCreatedIfAny.RootCohortAggregateContainer.GetAggregateConfigurations()[0];

            Assert.AreEqual("33", cloneAc.Description);
        }
예제 #21
0
 public ConsoleLogger(ConsoleInputManager consoleInputManager)
 {
     _consoleInputManager = consoleInputManager;
 }
        public void TestAddTag_WithArchive(DatabaseType type)
        {
            var db = GetCleanedServer(type);

            // Create a nice template with lots of columns
            var template = new ImageTableTemplate();

            template.TableName = "Fish";
            template.Columns   = new[]
            {
                new ImageColumnTemplate {
                    IsPrimaryKey = true, AllowNulls = true, ColumnName = "RelativeFileArchiveURI"
                },
                new ImageColumnTemplate {
                    IsPrimaryKey = false, AllowNulls = true, ColumnName = "SeriesInstanceUID"
                },
                new ImageColumnTemplate {
                    IsPrimaryKey = false, AllowNulls = true, ColumnName = "StudyDate"
                },
            };

            // use it to create a table
            var            tbl = db.ExpectTable(template.TableName);
            IAtomicCommand cmd = new ExecuteCommandCreateNewImagingDataset(RepositoryLocator, tbl, template);

            Assert.IsFalse(cmd.IsImpossible);
            cmd.Execute();

            Assert.IsTrue(tbl.Exists());

            // import RDMP reference to the table
            var importer = new TableInfoImporter(CatalogueRepository, tbl);

            importer.DoImport(out TableInfo ti, out ColumnInfo[] cols);

            var forward = new ForwardEngineerCatalogue(ti, cols);

            forward.ExecuteForwardEngineering(out Catalogue catalogue, out _, out _);

            // Create an archive table and backup trigger like we would have if this were the target of a data load
            var triggerImplementerFactory = new TriggerImplementerFactory(type);
            var implementer = triggerImplementerFactory.Create(tbl);

            implementer.CreateTrigger(new ThrowImmediatelyCheckNotifier());

            var archive = tbl.Database.ExpectTable(tbl.GetRuntimeName() + "_Archive");

            Assert.IsTrue(archive.Exists());

            var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier())
            {
                DisallowInput = true
            };

            // Test the actual commands
            cmd = new ExecuteCommandAddTag(activator, catalogue, "ffffff", "int");
            Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible);
            cmd.Execute();

            cmd = new ExecuteCommandAddTag(activator, catalogue, "EchoTime", null);
            Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible);
            cmd.Execute();

            var ex = Assert.Throws <Exception>(() => new ExecuteCommandAddTag(activator, catalogue, "StudyDate", null).Execute());

            StringAssert.StartsWith("Failed check with message: There is already a column called 'StudyDate' in TableInfo ", ex.Message);

            cmd = new ExecuteCommandAddTag(activator, catalogue, "SeriesDate", null);
            Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible);
            cmd.Execute();

            Assert.AreEqual("int", tbl.DiscoverColumn("ffffff").DataType.SQLType);
            Assert.AreEqual("decimal(38,19)", tbl.DiscoverColumn("EchoTime").DataType.SQLType);
            Assert.AreEqual(typeof(DateTime), tbl.DiscoverColumn("SeriesDate").DataType.GetCSharpDataType());

            Assert.AreEqual("int", archive.DiscoverColumn("ffffff").DataType.SQLType);
            Assert.AreEqual("decimal(38,19)", archive.DiscoverColumn("EchoTime").DataType.SQLType);
            Assert.AreEqual(typeof(DateTime), archive.DiscoverColumn("SeriesDate").DataType.GetCSharpDataType());
        }
예제 #23
0
        public void TestIPluginCohortCompiler_AsPatientIndexTable()
        {
            var activator = new ConsoleInputManager(RepositoryLocator, new ThrowImmediatelyCheckNotifier())
            {
                DisallowInput = true
            };

            // Create a regular normal boring old table that will join into the results of the API call
            var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer);

            using DataTable dt = new DataTable();
            dt.Columns.Add("chi");
            dt.Rows.Add("0101010101");

            var tbl   = db.CreateTable("RegularBoringOldTable", dt);
            var cata  = (Catalogue)Import(tbl);
            var eiChi = cata.GetAllExtractionInformation()[0];

            eiChi.IsExtractionIdentifier = true;
            eiChi.SaveToDatabase();

            // create a cohort config
            var cic = new CohortIdentificationConfiguration(CatalogueRepository, "mycic");

            cic.QueryCachingServer_ID = externalDatabaseServer.ID;
            cic.SaveToDatabase();

            // this special Catalogue will be detected by ExamplePluginCohortCompiler and interpreted as an API call
            var myApi = new Catalogue(CatalogueRepository, ExamplePluginCohortCompiler.ExampleAPIName);

            // add it to the cohort config
            cic.CreateRootContainerIfNotExists();

            // Add the regular table
            var cmd = new ExecuteCommandAddCatalogueToCohortIdentificationSetContainer(activator, new CatalogueCombineable(cata), cic.RootCohortAggregateContainer);

            Assert.IsFalse(cmd.IsImpossible, cmd.ReasonCommandImpossible);
            cmd.Execute();
            var regularAggregate = cmd.AggregateCreatedIfAny;

            // The thing we are wanting to test - creating a use of the API as a patient index table
            var cmd2 = new ExecuteCommandAddCatalogueToCohortIdentificationAsPatientIndexTable(
                activator, new CatalogueCombineable(myApi), cic);

            Assert.IsFalse(cmd2.IsImpossible, cmd2.ReasonCommandImpossible);
            cmd2.Execute();

            var joinables = cic.GetAllJoinables();

            Assert.AreEqual(1, joinables.Length);

            // make them join one another
            new JoinableCohortAggregateConfigurationUse(CatalogueRepository, regularAggregate, joinables[0]);

            // run the cic again
            var source = new CohortIdentificationConfigurationSource();

            source.PreInitialize(cic, new ThrowImmediatelyDataLoadEventListener());
            var result = source.GetChunk(new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken());

            Assert.AreEqual(1, result.Rows.Count);
        }