Esempio n. 1
0
        public async Task DefaultApiBaseCanBeCreatedAndDisposed()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <TestableEmptyApi, DbContext>(serviceCollection : di);

            Action exceptionTest = () => { api.Dispose(); };

            exceptionTest.Should().NotThrow <Exception>();
        }
Esempio n. 2
0
        public async Task LibraryApi_SaveVisibilityMatrix(string path)
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <LibraryApi, LibraryContext>();

            api.WriteCurrentVisibilityMatrix(Path.Combine(path, baselineFolder));

            File.Exists($"{Path.Combine(path, baselineFolder)}{api.GetType().Name}-ApiSurface.txt").Should().BeTrue();
        }
Esempio n. 3
0
        public async Task SubmitAsync_CorrectlyForwardsCall()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <TestableEmptyApi, DbContext>(serviceCollection : di) as ApiBase;

            var submitResult = await api.SubmitAsync();

            submitResult.CompletedChangeSet.Should().NotBeNull();
        }
Esempio n. 4
0
        public async Task QueryAsync_CorrectlyForwardsCall()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <TestApi>() as ApiBase;

            var queryRequest = new QueryRequest(api.GetQueryableSource <string>("Test"));
            var queryResult  = await api.QueryAsync(queryRequest);

            queryResult.Results.Cast <string>().SequenceEqual(new[] { "Test" }).Should().BeTrue();
        }
Esempio n. 5
0
        public async Task GetQueryableSource_ComposableFunction_ThrowsIfWrongType()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <TestApi>() as ApiBase;

            var arguments = new object[0];

            Action exceptionTest = () => { api.GetQueryableSource <object>("Namespace", "Function", arguments); };

            exceptionTest.Should().Throw <ArgumentException>();
        }
Esempio n. 6
0
        public async Task GetQueryableSource_EntitySet_ThrowsIfNotMapped()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <TestApiEmpty>() as ApiBase;

            var arguments = new object[0];

            Action exceptionTest = () => { api.GetQueryableSource("Test", arguments); };

            exceptionTest.Should().Throw <NotSupportedException>();
        }
Esempio n. 7
0
        public async Task GetQueryableSource_OfT_ContainerElementThrowsIfWrongType()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <TestApi>() as ApiBase;

            var arguments = new object[0];

            Action exceptionTest = () => { api.GetQueryableSource <object>("Test", arguments); };

            exceptionTest.Should().Throw <ArgumentException>();
        }
Esempio n. 8
0
        public async Task GetQueryableSource_ProviderCannotExecute()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <TestApi>() as ApiBase;

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

            Action exceptionTest = () => { source.Provider.Execute(null); };

            exceptionTest.Should().Throw <NotSupportedException>();
        }
Esempio n. 9
0
        public async Task GetQueryableSource_OfT_ComposableFunction_ThrowsIfNotMapped()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <TestApiEmpty>() as ApiBase;

            var arguments = new object[0];

            Action exceptionTest = () => { api.GetQueryableSource <DateTime>("Namespace", "Function", arguments); };

            exceptionTest.Should().Throw <NotSupportedException>();
        }
Esempio n. 10
0
        public async Task GetQueryableSource_CannotEnumerateIEnumerable()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <TestApi>() as ApiBase;

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

            Action exceptionTest = () => { (source as IEnumerable).GetEnumerator(); };

            exceptionTest.Should().Throw <NotSupportedException>();
        }
Esempio n. 11
0
        public async Task GetQueryableSource_ProviderCannotGenericExecute()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <TestableEmptyApi, DbContext>(serviceCollection : di) as ApiBase;

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

            Action exceptionTest = () => { source.Provider.Execute <string>(null); };

            exceptionTest.Should().Throw <NotSupportedException>();
        }
Esempio n. 12
0
        public async Task GetQueryableSource_ComposableFunction_ThrowsIfNotMapped()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <TestableEmptyApi, DbContext>(serviceCollection : diEmpty) as ApiBase;

            var arguments = new object[0];

            Action exceptionTest = () => { api.GetQueryableSource("Namespace", "Function", arguments); };

            exceptionTest.Should().Throw <NotSupportedException>();
        }
Esempio n. 13
0
        public async Task GetQueryableSource_ComposableFunction_IsConfiguredCorrectly()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <TestApi>() as ApiBase;

            var arguments = new object[0];
            var source    = api.GetQueryableSource("Namespace", "Function", arguments);

            CheckQueryable(source, typeof(DateTime), new List <string> {
                "Namespace", "Function"
            }, arguments);
        }
Esempio n. 14
0
        public async Task GetQueryableSource_OfT_EntitySet_IsConfiguredCorrectly()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <TestApi>() as ApiBase;

            var arguments = new object[0];
            var source    = api.GetQueryableSource <string>("Test", arguments);

            CheckQueryable(source, typeof(string), new List <string> {
                "Test"
            }, arguments);
        }
Esempio n. 15
0
        public async Task QueryAsync_WithQueryReturnsResults()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <TestApi>() as ApiBase;

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

            var results = result.Results.Cast <string>();

            results.SequenceEqual(new[] { "Test" }).Should().BeTrue();
        }
Esempio n. 16
0
        public async Task GetQueryableSource_EntitySet_IsConfiguredCorrectly()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <TestableEmptyApi, DbContext>(serviceCollection : di) as ApiBase;

            var arguments = new object[0];
            var source    = api.GetQueryableSource("Test", arguments);

            CheckQueryable(source, typeof(string), new List <string> {
                "Test"
            }, arguments);
        }
Esempio n. 17
0
        public async Task StoreApi_CompareCurrentVisibilityMatrixToPriorRun()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <StoreApi, DbContext>(serviceCollection : (services) => { services.AddTestStoreApiServices(); });

            var fileName = $"{Path.Combine(relativePath, baselineFolder)}{api.GetType().Name}-ApiSurface.txt";

            File.Exists(fileName).Should().BeTrue();
            var oldReport = File.ReadAllText(fileName);
            var newReport = api.GenerateVisibilityMatrix();

            oldReport.Should().BeEquivalentTo(newReport);
        }
Esempio n. 18
0
        public async Task LibraryApi_CompareCurrentVisibilityMatrixToPriorRun()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <LibraryApi, LibraryContext>();

            var fileName = $"{relativePath}{api.GetType().Name}-ApiSurface.txt";

            File.Exists(fileName).Should().BeTrue();
            var oldReport = File.ReadAllText(fileName);
            var newReport = await api.GenerateVisibilityMatrix();

            oldReport.Should().BeEquivalentTo(newReport);
        }
Esempio n. 19
0
        public async Task NothingInjectedStillWorks()
        {
            // Outmost service does not call inner service
            var api = await RestierTestHelpers.GetTestableApiInstance <TestApiD>();

            var value = api.GetApiService <ISomeService>().Call();

            value.Should().Be("42");

            // Test expression compilation. (RWM: I don't think this works the way they thought it did.)
            value = api.GetApiService <ISomeService>().Call();
            value.Should().Be("42");
            value = api.GetApiService <ISomeService>().Call();
            value.Should().Be("42");
        }
Esempio n. 20
0
        public async Task ContextApiScopeWorksCorrectly()
        {
            var api = await RestierTestHelpers.GetTestableApiInstance <TestApiC>();

            var service1 = api.GetApiService <ISomeService>();

            var api2 = await RestierTestHelpers.GetTestableApiInstance <TestApiC>();

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

            service1.Should().NotBe(service2);

            var api3 = await RestierTestHelpers.GetTestableApiInstance <TestApiC>();

            var service3 = api3.GetApiService <ISomeService>();

            service3.Should().NotBe(service2);
        }
Esempio n. 21
0
        public async Task ConfigurationRegistersApiServicesCorrectly()
        {
            var apiA = await RestierTestHelpers.GetTestableApiInstance <TestApiA>();

            apiA.GetApiService <IServiceA>().Should().BeNull();
            apiA.GetApiService <IServiceB>().Should().BeNull();

            var apiB = await RestierTestHelpers.GetTestableApiInstance <TestApiB>();

            apiB.GetApiService <IServiceA>().Should().BeSameAs(TestApiB.serviceA);

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

            serviceBInterface.Should().BeSameAs(serviceBInstance);

            var serviceBFirst = serviceBInterface as ServiceB;

            serviceBFirst.Should().NotBeNull();

            serviceBFirst.InnerHandler.Should().BeSameAs(TestApiB.serviceB);
        }