コード例 #1
0
        public void AddService_Single_ImplementationType_NullShouldThrow()
        {
            var    container  = new RestierContainerBuilder(typeof(TestableEmptyApi));
            Action addService = () => { container.AddService(ODataServiceLifetime.Scoped, typeof(DefaultSubmitHandler), implementationType: null); };

            addService.Should().Throw <ArgumentNullException>();
        }
コード例 #2
0
        public void BuildContainer_HasServices()
        {
            var container = new RestierContainerBuilder();

            container.BuildContainer();
            container.Services.Should().HaveCount(1);
        }
コード例 #3
0
        public async Task ComplexTypeUpdate()
        {
            // Arrange
            var container  = new RestierContainerBuilder(typeof(LibraryApi));
            var provider   = container.BuildContainer();
            var libraryApi = provider.GetService <ApiBase>();

            var item = new DataModificationItem(
                "Readers",
                typeof(Person),
                null,
                RestierEntitySetOperation.Update,
                new Dictionary <string, object> {
                { "Id", new Guid("53162782-EA1B-4712-AF26-8AA1D2AC0461") }
            },
                new Dictionary <string, object>(),
                new Dictionary <string, object> {
                { "Addr", new Dictionary <string, object> {
                      { "Zip", "332" }
                  } }
            });
            var changeSet = new ChangeSet(new[] { item });
            var sc        = new SubmitContext(provider, changeSet);

            // Act
            var changeSetPreparer = libraryApi.GetApiService <IChangeSetInitializer>();
            await changeSetPreparer.InitializeAsync(sc, CancellationToken.None).ConfigureAwait(false);

            var person = item.Resource as Person;

            // Assert
            Assert.NotNull(person);
            Assert.Equal("332", person.Addr.Zip);
        }
コード例 #4
0
        public void ConfigurationRegistersApiServicesCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApiA));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            Assert.Null(api.GetApiService <IServiceA>());
            Assert.Null(api.GetApiService <IServiceB>());

            container = new RestierContainerBuilder(typeof(TestApiB));
            var provider2 = container.BuildContainer();
            var apiB      = provider2.GetService <ApiBase>();

            Assert.Same(TestApiB.serviceA, apiB.GetApiService <IServiceA>());

            var serviceBInstance  = apiB.GetApiService <ServiceB>();
            var serviceBInterface = apiB.GetApiService <IServiceB>();

            Assert.Equal(serviceBInstance, serviceBInterface);

            // AddService will call services.TryAddTransient
            Assert.Same(serviceBInstance, serviceBInterface);

            var serviceBFirst = serviceBInterface as ServiceB;

            Assert.NotNull(serviceBFirst);

            Assert.Same(TestApiB.serviceB, serviceBFirst.InnerHandler);
        }
コード例 #5
0
        public async Task GetModelAsyncRetriableAfterFailure()
        {
            using (var wait = new ManualResetEventSlim(false))
            {
                var container = new RestierContainerBuilder(typeof(TestableEmptyApi));
                container.Services.AddRestierCoreServices(typeof(TestableEmptyApi))
                .AddChainedService <IModelBuilder>((sp, next) => new TestRetryModelBuilder());
                addTestServices(container.Services);

                var provider = container.BuildContainer();

                var tasks = PrepareThreads(6, provider, wait);
                wait.Set();

#pragma warning disable CA2008 // Do not create tasks without passing a TaskScheduler
                await Task.WhenAll(tasks).ContinueWith(t =>
                {
                    t.IsFaulted.Should().BeTrue();
                    tasks.All(e => e.IsFaulted).Should().BeTrue();
                });

#pragma warning restore CA2008 // Do not create tasks without passing a TaskScheduler

                tasks = PrepareThreads(150, provider, wait);

                var models = await Task.WhenAll(tasks);

                models.All(e => ReferenceEquals(e, models[42])).Should().BeTrue();
            }
        }
コード例 #6
0
        public async Task TestEntityFilterReturnsTask()
        {
            var container = new RestierContainerBuilder(typeof(TestEntityFilterReturnsTaskApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            DataModificationItem <Customer> createCustomer = new DataModificationItem <Customer>(
                "Customers",
                typeof(Customer),
                null,
                DataModificationItemAction.Insert,
                null,
                null,
                new Dictionary <string, object>()
            {
                { "CustomerID", "NEW01" },
                { "CompanyName", "New Cust" },
            });

            await api.SubmitAsync(new ChangeSet(new ChangeSetItem[] { createCustomer }));

            NorthwindContext ctx = new NorthwindContext();

#if EF7
            Customer newCustomer = await ctx.Customers.FirstOrDefaultAsync(e => e.CustomerID == "NEW01");
#else
            Customer newCustomer = await ctx.Customers.FindAsync("NEW01");
#endif
            // The "OnInserting" should have been appended by the OnInsertingCustomers filter
            Assert.Equal("New CustOnInserting", newCustomer.CompanyName);

            ctx.Customers.Remove(newCustomer);
            await ctx.SaveChangesAsync();
        }
コード例 #7
0
ファイル: Api.Tests.cs プロジェクト: zengshine/Learn-Space
        public void GenericSourceOfComposableFunctionIsCorrect()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            var arguments = new object[0];

            var source = api.GetQueryableSource <DateTime>("Namespace", "Function", arguments);

            Assert.Equal(typeof(DateTime), source.ElementType);
            Assert.True(source.Expression is MethodCallExpression);
            var methodCall = source.Expression as MethodCallExpression;

            Assert.Null(methodCall.Object);
            Assert.Equal(typeof(DataSourceStub), methodCall.Method.DeclaringType);
            Assert.Equal("GetQueryableSource", methodCall.Method.Name);
            Assert.Equal(typeof(DateTime), methodCall.Method.GetGenericArguments()[0]);
            Assert.Equal(3, methodCall.Arguments.Count);
            Assert.True(methodCall.Arguments[0] is ConstantExpression);
            Assert.Equal("Namespace", (methodCall.Arguments[0] as ConstantExpression).Value);
            Assert.True(methodCall.Arguments[1] is ConstantExpression);
            Assert.Equal("Function", (methodCall.Arguments[1] as ConstantExpression).Value);
            Assert.True(methodCall.Arguments[2] is ConstantExpression);
            Assert.Equal(arguments, (methodCall.Arguments[2] as ConstantExpression).Value);
            Assert.Equal(source.Expression.ToString(), source.ToString());
        }
コード例 #8
0
        public void Constructor_CreatesServiceCollection()
        {
            var container = new RestierContainerBuilder();

            container.Should().NotBeNull();
            container.Services.Should().NotBeNull().And.BeEmpty();
        }
コード例 #9
0
        public void AddService_Single_ServiceType_NullShouldThrow()
        {
            var    container  = new RestierContainerBuilder();
            Action addService = () => { container.AddService(ODataServiceLifetime.Scoped, null, typeof(DefaultSubmitHandler)); };

            addService.Should().Throw <ArgumentNullException>();
        }
コード例 #10
0
        public void AddService_Factory_ServiceType_NullShouldThrow()
        {
            var    container  = new RestierContainerBuilder();
            Action addService = () => { container.AddService(ODataServiceLifetime.Scoped, null, (sp) => new DefaultSubmitExecutor()); };

            addService.Should().Throw <ArgumentNullException>();
        }
コード例 #11
0
        public void ConfigurationRegistersApiServicesCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApiA));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            Assert.Null(api.Context.GetApiService<IServiceA>());
            Assert.Null(api.Context.GetApiService<IServiceB>());

            container = new RestierContainerBuilder(typeof(TestApiB));
            var provider2 = container.BuildContainer();
            var apiB = provider2.GetService<ApiBase>();

            Assert.Same(TestApiB.serviceA, apiB.Context.GetApiService<IServiceA>());

            var serviceBInstance = apiB.Context.GetApiService<ServiceB>();
            var serviceBInterface = apiB.Context.GetApiService<IServiceB>();
            Assert.Equal(serviceBInstance, serviceBInterface);

            // AddService will call services.TryAddTransient
            Assert.Same(serviceBInstance, serviceBInterface);

            var serviceBFirst = serviceBInterface as ServiceB;
            Assert.NotNull(serviceBFirst);

            Assert.Same(TestApiB.serviceB, serviceBFirst.InnerHandler);
        }
コード例 #12
0
        public void AddService_Factory_ImplementationFactory_NullShouldThrow()
        {
            var    container  = new RestierContainerBuilder();
            Action addService = () => { container.AddService(ODataServiceLifetime.Scoped, typeof(DefaultSubmitHandler), implementationFactory: null); };

            addService.Should().Throw <ArgumentNullException>();
        }
コード例 #13
0
 public void DefaultApiBaseCanBeCreatedAndDisposed()
 {
     var container = new RestierContainerBuilder(typeof(TestApi));
     var provider = container.BuildContainer();
     var api = provider.GetService<ApiBase>();
     api.Dispose();
 }
コード例 #14
0
        public void BuildContainer_HasServices()
        {
            var container = new RestierContainerBuilder(typeof(TestableEmptyApi));

            container.BuildContainer();
            container.Services.Should().HaveCount(1);
        }
コード例 #15
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>());
        }
コード例 #16
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);
        }
コード例 #17
0
        public void ThrowOnNoServiceFound()
        {
            var container = new RestierContainerBuilder(typeof(TestApiH));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            Assert.Throws <InvalidOperationException>(() => { api.GetApiService <ISomeService>(); });
        }
コード例 #18
0
        public void NewApiContextIsConfiguredCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            Assert.NotNull(api);
        }
コード例 #19
0
        public void DefaultApiBaseCanBeCreatedAndDisposed()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            api.Dispose();
        }
コード例 #20
0
        public void ServiceChainTest()
        {
            var container = new RestierContainerBuilder(typeof(TestApiC));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var handler = api.Context.GetApiService<IServiceB>();
            Assert.Equal("q2Pre_q1Pre_q1Post_q2Post_", handler.GetStr());
        }
コード例 #21
0
        public void NewApiContextIsConfiguredCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var context = api.Context;
            Assert.NotNull(context.Configuration);
        }
コード例 #22
0
 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>());
 }
コード例 #23
0
        public void ContributorsAreCalledCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApiA));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();
            var value     = api.GetApiService <ISomeService>().Call();

            Assert.Equal("03210", value);
        }
コード例 #24
0
        public void DifferentPropertyBagsDoNotConflict()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            api.SetProperty("Test", 2);
            Assert.Equal(2, api.GetProperty <int>("Test"));
        }
コード例 #25
0
ファイル: Api.Tests.cs プロジェクト: zengshine/Learn-Space
        public void GenericSourceOfEntityContainerElementThrowsIfWrongType()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();
            var arguments = new object[0];

            Assert.Throws <ArgumentException>(() => api.GetQueryableSource <object>("Test", arguments));
        }
コード例 #26
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);
        }
コード例 #27
0
ファイル: Api.Tests.cs プロジェクト: zengshine/Learn-Space
        public void SourceOfComposableFunctionThrowsIfNotMapped()
        {
            var container = new RestierContainerBuilder(typeof(TestApiEmpty));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();
            var arguments = new object[0];

            Assert.Throws <NotSupportedException>(() => api.GetQueryableSource("Namespace", "Function", arguments));
        }
コード例 #28
0
 public void NewInvocationContextIsConfiguredCorrectly()
 {
     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(apiContext, context.ApiContext);
 }
コード例 #29
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>());
        }
コード例 #30
0
        public void DifferentPropertyBagsDoNotConflict()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var context = api.Context;
            context.SetProperty("Test", 2);
            Assert.Equal(2, context.GetProperty<int>("Test"));
        }
コード例 #31
0
        public void ConventionBasedMethodNameFactory_ExecuteMethod_Authorize()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();

            var context = new OperationContext((string test) => { return(null); }, "TestMethod", null, true, null, provider);
            var name    = ConventionBasedMethodNameFactory.GetFunctionMethodName(context, RestierPipelineState.Authorization, RestierOperationMethod.Execute);

            Assert.Equal("CanExecuteTestMethod", name);
        }
コード例 #32
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private RestierContainerBuilder GetContainerBuilder()
        {
            var container = new RestierContainerBuilder();

            container.Services
            .AddRestierCoreServices()
            .AddRestierConventionBasedServices(typeof(LibraryApi))
            .AddRestierDefaultServices();
            return(container);
        }
コード例 #33
0
        public void ServiceChainTest()
        {
            var container = new RestierContainerBuilder(typeof(TestApiC));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            var handler = api.GetApiService <IServiceB>();

            Assert.Equal("q2Pre_q1Pre_q1Post_q2Post_", handler.GetStr());
        }
コード例 #34
0
ファイル: Api.Tests.cs プロジェクト: zengshine/Learn-Space
        public async Task ApiSubmitAsyncCorrectlyForwardsCall()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            var submitResult = await api.SubmitAsync();

            Assert.NotNull(submitResult.CompletedChangeSet);
        }
コード例 #35
0
ファイル: Api.Tests.cs プロジェクト: zengshine/Learn-Space
        public void SourceQueryProviderCannotExecute()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            var source = api.GetQueryableSource <string>("Test");

            Assert.Throws <NotSupportedException>(() => source.Provider.Execute(null));
        }
コード例 #36
0
        public void ApiAndApiContextCanBeInjectedByDI()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            var svc = api.GetApiService <IService>();

            Assert.Same(svc.Api, api);
        }
コード例 #37
0
ファイル: Api.Tests.cs プロジェクト: zengshine/Learn-Space
        public void SourceQueryableCannotEnumerate()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider  = container.BuildContainer();
            var api       = provider.GetService <ApiBase>();

            var source = api.GetQueryableSource <string>("Test");

            Assert.Throws <NotSupportedException>(() => (source as IEnumerable).GetEnumerator());
        }
コード例 #38
0
        public void CachedConfigurationIsCachedCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApiA));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var configuration = api.Context.Configuration;

            ApiBase anotherApi = provider.GetService<ApiBase>();
            var cached = anotherApi.Context.Configuration;
            Assert.Same(configuration, cached);
        }
コード例 #39
0
        public void ApiAndApiContextCanBeInjectedByDI()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var context = api.Context;
            var svc = context.GetApiService<IService>();

            Assert.Same(svc.Api, api);
            Assert.Same(svc.Context, context);

            api.Dispose();
            Assert.Throws<ObjectDisposedException>(() => api.Context);
        }
コード例 #40
0
        public void PropertyBagsAreDisposedCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var scope = provider.GetRequiredService<IServiceScopeFactory>().CreateScope();
            var scopedProvider  = scope.ServiceProvider;
            var api = scopedProvider.GetService<ApiBase>();
            var context = api.Context;

            Assert.NotNull(context.GetApiService<MyPropertyBag>());
            Assert.Equal(1, MyPropertyBag.InstanceCount);

            var scopedProvider2 = provider.GetRequiredService<IServiceScopeFactory>().CreateScope().ServiceProvider;
            var api2 = scopedProvider2.GetService<ApiBase>();
            var context2 = api2.Context;

            Assert.NotNull(context2.GetApiService<MyPropertyBag>());
            Assert.Equal(2, MyPropertyBag.InstanceCount);

            scope.Dispose();

            Assert.Equal(1, MyPropertyBag.InstanceCount);
        }
コード例 #41
0
        public void PropertyBagManipulatesPropertiesCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();
            var context =api.Context;

            Assert.False(context.HasProperty("Test"));
            Assert.Null(context.GetProperty("Test"));
            Assert.Null(context.GetProperty<string>("Test"));
            Assert.Equal(default(int), context.GetProperty<int>("Test"));

            context.SetProperty("Test", "Test");
            Assert.True(context.HasProperty("Test"));
            Assert.Equal("Test", context.GetProperty("Test"));
            Assert.Equal("Test", context.GetProperty<string>("Test"));

            context.ClearProperty("Test");
            Assert.False(context.HasProperty("Test"));
            Assert.Null(context.GetProperty("Test"));
            Assert.Null(context.GetProperty<string>("Test"));
            Assert.Equal(default(int), context.GetProperty<int>("Test"));
        }
コード例 #42
0
        public void ThrowOnNoServiceFound()
        {
            var container = new RestierContainerBuilder(typeof(TestApiH));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            Assert.Throws<InvalidOperationException>(() => { api.Context.GetApiService<ISomeService>(); });
        }
コード例 #43
0
ファイル: Api.Tests.cs プロジェクト: chinadragon0515/RESTier
        public void GenericApiSourceOfEntityContainerElementIsCorrect()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var arguments = new object[0];

            var source = api.GetQueryableSource<string>("Test", arguments);
            Assert.Equal(typeof(string), source.ElementType);
            Assert.True(source.Expression is MethodCallExpression);
            var methodCall = source.Expression as MethodCallExpression;
            Assert.Null(methodCall.Object);
            Assert.Equal(typeof(DataSourceStub), methodCall.Method.DeclaringType);
            Assert.Equal("GetQueryableSource", methodCall.Method.Name);
            Assert.Equal(typeof(string), methodCall.Method.GetGenericArguments()[0]);
            Assert.Equal(2, methodCall.Arguments.Count);
            Assert.True(methodCall.Arguments[0] is ConstantExpression);
            Assert.Equal("Test", (methodCall.Arguments[0] as ConstantExpression).Value);
            Assert.True(methodCall.Arguments[1] is ConstantExpression);
            Assert.Equal(arguments, (methodCall.Arguments[1] as ConstantExpression).Value);
            Assert.Equal(source.Expression.ToString(), source.ToString());
        }
コード例 #44
0
        public async Task GetModelAsyncRetriableAfterFailure()
        {
            using (var wait = new ManualResetEventSlim(false))
            {
                var container = new RestierContainerBuilder(typeof(TestApiC));
                var provider = container.BuildContainer();

                var tasks = PrepareThreads(6, provider, wait);
                wait.Set();

                await Task.WhenAll(tasks).ContinueWith(t =>
                {
                    Assert.True(t.IsFaulted);
                    Assert.True(tasks.All(e => e.IsFaulted));
                });

                tasks = PrepareThreads(150, provider, wait);

                var models = await Task.WhenAll(tasks);
                Assert.True(models.All(e => object.ReferenceEquals(e, models[42])));
            }
        }
コード例 #45
0
        public async Task ModelBuilderShouldBeCalledOnlyOnceIfSucceeded()
        {
            using (var wait = new ManualResetEventSlim(false))
            {
                for (int i = 0; i < 2; i++)
                {
                    var container = new RestierContainerBuilder(typeof(TestApiB));
                    var provider = container.BuildContainer();
                    var tasks = PrepareThreads(50, provider, wait);
                    wait.Set();

                    var models = await Task.WhenAll(tasks);
                    Assert.True(models.All(e => object.ReferenceEquals(e, models[42])));
                }
            }
        }
コード例 #46
0
        public async Task GetModelUsingDefaultModelHandler()
        {
            var container = new RestierContainerBuilder(typeof(TestApiA));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();
            var context = api.Context;

            var model = await context.GetModelAsync();
            Assert.Equal(4, model.SchemaElements.Count());
            Assert.NotNull(model.SchemaElements
                .SingleOrDefault(e => e.Name == "TestName"));
            Assert.NotNull(model.SchemaElements
                .SingleOrDefault(e => e.Name == "TestName2"));
            Assert.NotNull(model.SchemaElements
                .SingleOrDefault(e => e.Name == "TestName3"));
            Assert.NotNull(model.EntityContainer);
            Assert.NotNull(model.EntityContainer.Elements
                .SingleOrDefault(e => e.Name == "TestEntitySet"));
            Assert.NotNull(model.EntityContainer.Elements
                .SingleOrDefault(e => e.Name == "TestEntitySet2"));
            Assert.NotNull(model.EntityContainer.Elements
                .SingleOrDefault(e => e.Name == "TestEntitySet3"));
        }
コード例 #47
0
 public void ContributorsAreCalledCorrectly()
 {
     var container = new RestierContainerBuilder(typeof(TestApiA));
     var provider = container.BuildContainer();
     var api = provider.GetService<ApiBase>();
     var value = api.Context.GetApiService<ISomeService>().Call();
     Assert.Equal("03210", value);
 }
コード例 #48
0
ファイル: Api.Tests.cs プロジェクト: chinadragon0515/RESTier
        public async Task ApiQueryAsyncWithQueryReturnsResults()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var request = new QueryRequest(api.GetQueryableSource<string>("Test"));
            var result = await api.Context.QueryAsync(request);
            var results = result.Results.Cast<string>();

            Assert.True(results.SequenceEqual(new[] {"Test"}));
        }
コード例 #49
0
        public void MultiInjectionViaConstructor()
        {
            var container = new RestierContainerBuilder(typeof(TestApiG));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("0122", value);

            // Test expression compilation
            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("0122", value);
            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("0122", value);
        }
コード例 #50
0
        public void DefaultValueInConstructorUsedIfNoService()
        {
            var container = new RestierContainerBuilder(typeof(TestApiF));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("42", value);

            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("42", value);
            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("42", value);
        }
コード例 #51
0
        public void ServiceInjectedViaProperty()
        {
            var container = new RestierContainerBuilder(typeof(TestApiE));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var expected = "Text42";
            var value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal(expected, value);

            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal(expected, value);

            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal(expected, value);

            Assert.NotEqual(
                api.Context.GetApiService<ISomeService>(),
                api.Context.GetApiService<ISomeService>());
        }
コード例 #52
0
ファイル: Api.Tests.cs プロジェクト: chinadragon0515/RESTier
        public async Task ApiSubmitAsyncCorrectlyForwardsCall()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var submitResult = await api.SubmitAsync();
            Assert.NotNull(submitResult.CompletedChangeSet);
        }
コード例 #53
0
        public void NextInjectedWithInheritedField()
        {
            var container = new RestierContainerBuilder(typeof(TestApiI));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("4200", value);

            // Test expression compilation
            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("4200", value);
            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("4200", value);
        }
コード例 #54
0
ファイル: Api.Tests.cs プロジェクト: chinadragon0515/RESTier
        public void SourceQueryProviderCannotExecute()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();
            var context = api.Context;

            var source = context.GetQueryableSource<string>("Test");
            Assert.Throws<NotSupportedException>(() => source.Provider.Execute(null));
        }
コード例 #55
0
ファイル: Api.Tests.cs プロジェクト: chinadragon0515/RESTier
        public void GenericSourceOfComposableFunctionIsCorrect()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();
            var context = api.Context;
            var arguments = new object[0];

            var source = context.GetQueryableSource<DateTime>("Namespace", "Function", arguments);
            Assert.Equal(typeof(DateTime), source.ElementType);
            Assert.True(source.Expression is MethodCallExpression);
            var methodCall = source.Expression as MethodCallExpression;
            Assert.Null(methodCall.Object);
            Assert.Equal(typeof(DataSourceStub), methodCall.Method.DeclaringType);
            Assert.Equal("GetQueryableSource", methodCall.Method.Name);
            Assert.Equal(typeof(DateTime), methodCall.Method.GetGenericArguments()[0]);
            Assert.Equal(3, methodCall.Arguments.Count);
            Assert.True(methodCall.Arguments[0] is ConstantExpression);
            Assert.Equal("Namespace", (methodCall.Arguments[0] as ConstantExpression).Value);
            Assert.True(methodCall.Arguments[1] is ConstantExpression);
            Assert.Equal("Function", (methodCall.Arguments[1] as ConstantExpression).Value);
            Assert.True(methodCall.Arguments[2] is ConstantExpression);
            Assert.Equal(arguments, (methodCall.Arguments[2] as ConstantExpression).Value);
            Assert.Equal(source.Expression.ToString(), source.ToString());
        }
コード例 #56
0
        public void NothingInjectedStillWorks()
        {
            // Outmost service does not call inner service
            var container = new RestierContainerBuilder(typeof(TestApiD));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("42", value);

            // Test expression compilation.
            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("42", value);
            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("42", value);
        }
コード例 #57
0
        public void NextInjectedViaProperty()
        {
            var container = new RestierContainerBuilder(typeof(TestApiB));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();
            var value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("01", value);

            // Test expression compilation.
            value = api.Context.GetApiService<ISomeService>().Call();
            Assert.Equal("01", value);
        }
コード例 #58
0
ファイル: Api.Tests.cs プロジェクト: chinadragon0515/RESTier
        public async Task ApiQueryAsyncCorrectlyForwardsCall()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var queryRequest = new QueryRequest(
                api.GetQueryableSource<string>("Test"));
            var queryResult = await api.QueryAsync(queryRequest);
            Assert.True(queryResult.Results.Cast<string>()
                .SequenceEqual(new[] {"Test"}));
        }
コード例 #59
0
        public void ContextApiScopeWorksCorrectly()
        {
            var container = new RestierContainerBuilder(typeof(TestApiC));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var service1 = api.Context.GetApiService<ISomeService>();
            
            container = new RestierContainerBuilder(typeof(TestApiC));
            provider = container.BuildContainer();
            var api2 = provider.GetService<ApiBase>();

            var service2 = api2.Context.GetApiService<ISomeService>();

            Assert.NotEqual(service1, service2);

            container = new RestierContainerBuilder(typeof(TestApiC));
            provider = container.BuildContainer();
            var api3 = provider.GetService<ApiBase>();
            var service3 = api3.Context.GetApiService<ISomeService>();

            Assert.NotEqual(service3, service2);
        }
コード例 #60
0
ファイル: Api.Tests.cs プロジェクト: chinadragon0515/RESTier
        public void GenericSourceOfComposableFunctionThrowsIfWrongType()
        {
            var container = new RestierContainerBuilder(typeof(TestApi));
            var provider = container.BuildContainer();
            var api = provider.GetService<ApiBase>();

            var context = api.Context;
            var arguments = new object[0];

            Assert.Throws<ArgumentException>(() => context.GetQueryableSource<object>("Namespace", "Function", arguments));
        }