Пример #1
0
        public async Task GetDefaultModelIdAsyncTest()
        {
            ITable table          = Substitute.For <ITable>();
            var    modelsRegistry = new ModelsRegistry(table);

            // Default model not present in Models
            var knownModelId = Guid.NewGuid();

            table.GetEntityAsync <ModelIdTableEntity>(ModelsRegistry.DefaultModelIdKeyName, CancellationToken.None,
                                                      nameof(ModelIdTableEntity.ModelId))
            .Returns(Task.FromResult(new ModelIdTableEntity(ModelsRegistry.DefaultModelIdKeyName, knownModelId)));
            var model = await modelsRegistry.GetDefaultModelAsync(CancellationToken.None);

            Assert.IsNull(model);

            // Default model present in Models
            table.GetEntityAsync <ModelTableEntity>(knownModelId.ToString(), CancellationToken.None, Arg.Any <string[]>())
            .Returns(Task.FromResult(new ModelTableEntity(knownModelId)));
            model = await modelsRegistry.GetDefaultModelAsync(CancellationToken.None);

            Assert.IsNotNull(model);
            Assert.AreEqual(knownModelId, model.Id);
        }
Пример #2
0
        public async Task <IHttpActionResult> GetDefaultModel(CancellationToken cancellationToken)
        {
            // set the model id to context
            ContextManager.ModelId = "default";

            Trace.TraceVerbose("Trying to read the default model from the registry");
            ModelsRegistry modelsRegistry = WebAppContext.ModelsRegistry;
            Model          defaultModel   = await modelsRegistry.GetDefaultModelAsync(cancellationToken);

            if (defaultModel == null)
            {
                Trace.TraceInformation("A default model is not defined");
                return(NotFound());
            }

            return(Ok(defaultModel));
        }