Ejemplo n.º 1
0
        public void InvocationContextGetsApiServicesCorrectly()
        {
            var api        = new TestApi();
            var apiContext = api.Context;
            var context    = new InvocationContext(apiContext);

            Assert.Same(api.ApiService, context.GetApiService <IServiceA>());
        }
Ejemplo n.º 2
0
        public void InvocationContextGetsApiServicesCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var context   = new InvocationContext(provider);

            Assert.Same(TestApi.ApiService, context.GetApiService <IServiceA>());
        }
Ejemplo n.º 3
0
        public void InvocationContext_GetsApiServicesCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var context   = new InvocationContext(provider);

            context.GetApiService <IServiceA>().Should().BeSameAs(TestApi.ApiService);
        }
 public void InvocationContextGetsApiServicesCorrectly()
 {
     var container = new RestierContainerBuilder(typeof(TestApi));
     var provider = container.BuildContainer();
     var api = provider.GetService<ApiBase>();
     var apiContext = api.Context;
     var context = new InvocationContext(apiContext);
     Assert.Same(TestApi.ApiService, context.GetApiService<IServiceA>());
 }
Ejemplo n.º 5
0
        public void NewInvocationContextIsConfiguredCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();
            var context   = new InvocationContext(provider);

            Assert.Same(api, context.GetApiService <ApiBase>());
        }
Ejemplo n.º 6
0
        public void InvocationContext_IsConfiguredCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();
            var context   = new InvocationContext(provider);

            context.GetApiService <ApiBase>().Should().BeSameAs(api);
        }
Ejemplo n.º 7
0
        public void InvocationContextGetsHookPointsCorrectly()
        {
            var hook          = new HookA();
            var configuration = new ServiceCollection()
                                .CutoffPrevious <IHookA>(hook)
                                .BuildApiConfiguration();
            var apiContext = new ApiContext(configuration);
            var context    = new InvocationContext(apiContext);

            Assert.Same(hook, context.GetApiService <IHookA>());
        }
Ejemplo n.º 8
0
        public void InvocationContext_GetsApiServicesCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));

            container.Services.AddRestierCoreServices(typeof(TestApi))
            .AddRestierConventionBasedServices(typeof(TestApi))
            .AddTestStoreApiServices()
            .AddChainedService <IServiceA>((sp, next) => TestApi.ApiService);
            var provider = container.BuildContainer();
            var api      = provider.GetService <ApiBase>();
            var context  = new InvocationContext(api);

            context.GetApiService <IServiceA>().Should().BeSameAs(TestApi.ApiService);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Asynchronously produces a base model.
        /// </summary>
        /// <param name="context">
        /// The model context.
        /// </param>
        /// <param name="cancellationToken">
        /// A cancellation token.
        /// </param>
        /// <returns>
        /// A task that represents the asynchronous
        /// operation whose result is the base model.
        /// </returns>
        public Task <IEdmModel> GetModelAsync(
            InvocationContext context,
            CancellationToken cancellationToken)
        {
            Ensure.NotNull(context, "context");

            var    model         = new EdmModel();
            var    dbContext     = context.GetApiService <DbContext>();
            var    elementMap    = new Dictionary <IAnnotatable, IEdmElement>();
            var    entityTypes   = dbContext.Model.GetEntityTypes();
            string namespaceName = CalcNamespace(dbContext, entityTypes);

            var entityContainer = new EdmEntityContainer(
                namespaceName, "Container");
            Dictionary <Type, PropertyInfo> dbSetProperties = GetDbSetPropeties(dbContext);

            // TODO GitHubIssue#36 : support complex and entity inheritance
            foreach (var efEntityType in entityTypes)
            {
                if (elementMap.ContainsKey(efEntityType))
                {
                    continue;
                }

                List <EdmStructuralProperty> concurrencyProperties;
                var entityType = ModelProducer.CreateEntityType(
                    efEntityType, model, out concurrencyProperties);
                model.AddElement(entityType);

                PropertyInfo propInfo;
                if (dbSetProperties.TryGetValue(efEntityType.ClrType, out propInfo))
                {
                    var entitySet = entityContainer.AddEntitySet(propInfo.Name, entityType);
                    if (concurrencyProperties != null)
                    {
                        model.SetOptimisticConcurrencyAnnotation(entitySet, concurrencyProperties);
                    }
                }

                elementMap.Add(efEntityType, entityType);
            }

            CreateNavigations(entityContainer, entityTypes, elementMap);

            // TODO GitHubIssue#36 : support function imports
            model.AddElement(entityContainer);

            return(Task.FromResult <IEdmModel>(model));
        }
Ejemplo n.º 10
0
        public void InvocationContext_GetsApiServicesCorrectly()
        {
            var container = new RestierContainerBuilder((configureApis) =>
            {
                configureApis.AddRestierApi <TestApi>(services =>
                {
                    services.AddTestStoreApiServices()
                    .AddChainedService <IServiceA>((sp, next) => TestApi.ApiService);
                });
            });
            var provider = container.BuildContainer();
            var api      = provider.GetService <ApiBase>();
            var context  = new InvocationContext(api);

            context.GetApiService <IServiceA>().Should().BeSameAs(TestApi.ApiService);
        }