Пример #1
0
        public async Task ApiModelBuilder_ShouldCorrectlyAddBindingsForCollectionNavigationProperty()
        {
            // In this case, only one entity set People has entity type Person.
            // Bindings for collection navigation property Customer.Friends should be added.
            // Bindings for singleton navigation property Customer.BestFriend should be added.
            var model = await RestierTestHelpers.GetTestableModelAsync <ApiC, DbContext>(serviceCollection : di);

            var customersBindings = model.EntityContainer.FindEntitySet("Customers").NavigationPropertyBindings.ToArray();

            var friendsBinding = customersBindings.FirstOrDefault(c => c.NavigationProperty.Name == "Friends");

            friendsBinding.Should().NotBeNull();
            friendsBinding.Target.Name.Should().Be("People");

            var bestFriendBinding = customersBindings.FirstOrDefault(c => c.NavigationProperty.Name == "BestFriend");

            bestFriendBinding.Should().NotBeNull();
            bestFriendBinding.Target.Name.Should().Be("People");

            var meBindings = model.EntityContainer.FindSingleton("Me").NavigationPropertyBindings.ToArray();

            var friendsBinding2 = meBindings.FirstOrDefault(c => c.NavigationProperty.Name == "Friends");

            friendsBinding2.Should().NotBeNull();
            friendsBinding2.Target.Name.Should().Be("People");

            var bestFriendBinding2 = meBindings.FirstOrDefault(c => c.NavigationProperty.Name == "BestFriend");

            bestFriendBinding2.Should().NotBeNull();
            bestFriendBinding2.Target.Name.Should().Be("People");
        }
Пример #2
0
        public async Task GetModelUsingDefaultModelHandler()
        {
            var model = await RestierTestHelpers.GetTestableModelAsync <TestableEmptyApi, DbContext>(serviceCollection : (services) =>
            {
                addTestServices(services);
                services.AddChainedService <IModelBuilder>((sp, next) => new TestModelProducer())
                .AddChainedService <IModelBuilder>((sp, next) => new TestModelExtender(2)
                {
                    InnerHandler = next,
                })
                .AddChainedService <IModelBuilder>((sp, next) => new TestModelExtender(3)
                {
                    InnerHandler = next,
                });
            });

            model.SchemaElements.Should().HaveCount(4);
            model.SchemaElements.SingleOrDefault(e => e.Name == "TestName").Should().NotBeNull();
            model.SchemaElements.SingleOrDefault(e => e.Name == "TestName2").Should().NotBeNull();
            model.SchemaElements.SingleOrDefault(e => e.Name == "TestName3").Should().NotBeNull();
            model.EntityContainer.Should().NotBeNull();
            model.EntityContainer.Elements.SingleOrDefault(e => e.Name == "TestEntitySet").Should().NotBeNull();
            model.EntityContainer.Elements.SingleOrDefault(e => e.Name == "TestEntitySet2").Should().NotBeNull();
            model.EntityContainer.Elements.SingleOrDefault(e => e.Name == "TestEntitySet3").Should().NotBeNull();
        }
Пример #3
0
        public async Task PrimitiveTypesShouldWork()
        {
            var model = await RestierTestHelpers.GetTestableModelAsync <LibraryApi, LibraryContext>();

            model.Validate(out var errors).Should().BeTrue();
            errors.Should().BeEmpty();

            var universe = model.FindDeclaredType("Microsoft.Restier.Tests.Shared.Scenarios.Library.Universe")
                           as IEdmComplexType;

            universe.Should().NotBeNull();

            var propertyArray = universe.Properties().ToArray();
            var i             = 0;

            propertyArray[i++].Type.AsPrimitive().IsBinary().Should().BeTrue();
            propertyArray[i++].Type.AsPrimitive().IsBoolean().Should().BeTrue();
            propertyArray[i++].Type.AsPrimitive().IsByte().Should().BeTrue();
            // propertyArray[i++].Type.AsPrimitive().IsDate().Should().BeTrue();
            propertyArray[i++].Type.AsPrimitive().IsDateTimeOffset().Should().BeTrue();
            propertyArray[i++].Type.AsPrimitive().IsDecimal().Should().BeTrue();
            propertyArray[i++].Type.AsPrimitive().IsDouble().Should().BeTrue();
            propertyArray[i++].Type.AsPrimitive().IsDuration().Should().BeTrue();
            propertyArray[i++].Type.AsPrimitive().IsGuid().Should().BeTrue();
            propertyArray[i++].Type.AsPrimitive().IsInt16().Should().BeTrue();
            propertyArray[i++].Type.AsPrimitive().IsInt32().Should().BeTrue();
            propertyArray[i++].Type.AsPrimitive().IsInt64().Should().BeTrue();
            // propertyArray[i++].Type.AsPrimitive().IsSByte().Should().BeTrue();
            propertyArray[i++].Type.AsPrimitive().IsSingle().Should().BeTrue();
            // propertyArray[i++].Type.AsPrimitive().IsStream().Should().BeTrue();
            propertyArray[i++].Type.AsPrimitive().IsString().Should().BeTrue();
            // propertyArray[i].Type.AsPrimitive().IsTimeOfDay().Should().BeTrue();
        }
Пример #4
0
        public async Task ApiModelBuilder_ShouldSkipEntitySetWithUndeclaredType()
        {
            var model = await RestierTestHelpers.GetTestableModelAsync <ApiE>();

            model.EntityContainer.FindEntitySet("People").EntityType().Name.Should().Be("Person");
            model.EntityContainer.Elements.Select(e => e.Name).Should().NotContain("Orders");
        }
Пример #5
0
        public async Task ApiModelBuilder_ShouldProduceEmptyModelForEmptyApi()
        {
            var model = await RestierTestHelpers.GetTestableModelAsync <EmptyApi>();

            model.SchemaElements.Should().HaveCount(1);
            model.EntityContainer.Elements.Should().BeEmpty();
        }
Пример #6
0
        public async Task ApiModelBuilder_ShouldProduceCorrectModelForIgnoringInheritedProperty()
        {
            var model = await RestierTestHelpers.GetTestableModelAsync <ApiD>();

            model.EntityContainer.Elements.Select(e => e.Name).Should().NotContain("ApiConfiguration");
            model.EntityContainer.Elements.Select(e => e.Name).Should().NotContain("Invisible");
            model.EntityContainer.FindEntitySet("Customers").EntityType().Name.Should().Be("Customer");
            model.EntityContainer.FindSingleton("Me").EntityType().Name.Should().Be("Customer");
        }
Пример #7
0
        public async Task ApiModelBuilder_ShouldProduceCorrectModelForBasicScenario()
        {
            var model = await RestierTestHelpers.GetTestableModelAsync <ApiA>();

            model.EntityContainer.Elements.Select(e => e.Name).Should().NotContain("ApiConfiguration");
            model.EntityContainer.Elements.Select(e => e.Name).Should().NotContain("Invisible");
            model.EntityContainer.FindEntitySet("People").Should().NotBeNull();
            model.EntityContainer.FindSingleton("Me").Should().NotBeNull();
        }
Пример #8
0
        public async Task ApiModelBuilder_ShouldNotAddAmbiguousNavigationPropertyBindings()
        {
            // In this case, two entity sets Employees and People have entity type Person.
            // Bindings for collection navigation property Customer.Friends should NOT be added.
            // Bindings for singleton navigation property Customer.BestFriend should NOT be added.
            var model = await RestierTestHelpers.GetTestableModelAsync <ApiG>();

            model.EntityContainer.FindEntitySet("Customers").NavigationPropertyBindings.Should().BeEmpty();
            model.EntityContainer.FindSingleton("Me").NavigationPropertyBindings.Should().BeEmpty();
        }
Пример #9
0
        public async Task ApiModelBuilder_ShouldProduceCorrectModelForOverridingProperty()
        {
            var model = await RestierTestHelpers.GetTestableModelAsync <ApiC, DbContext>(serviceCollection : di);

            model.EntityContainer.Elements.Select(e => e.Name).Should().NotContain("ApiConfiguration");
            model.EntityContainer.Elements.Select(e => e.Name).Should().NotContain("Invisible");
            model.EntityContainer.FindEntitySet("People").Should().NotBeNull();
            model.EntityContainer.FindEntitySet("Customers").EntityType().Name.Should().Be("Customer");
            model.EntityContainer.FindSingleton("Me").EntityType().Name.Should().Be("Customer");
        }
Пример #10
0
        public async Task ComplexTypeShoudWork()
        {
            var model = await RestierTestHelpers.GetTestableModelAsync <LibraryApi, LibraryContext>();

            model.Validate(out var errors).Should().BeTrue();
            errors.Should().BeEmpty();

            var address = model.FindDeclaredType("Microsoft.Restier.Tests.Shared.Scenarios.Library.Address") as IEdmComplexType;

            address.Should().NotBeNull();
            address.Properties().Should().HaveCount(2);
        }
Пример #11
0
        public async Task GetModelUsingDefaultModelHandler()
        {
            var model = await RestierTestHelpers.GetTestableModelAsync <TestApiA>();

            model.SchemaElements.Should().HaveCount(4);
            model.SchemaElements.SingleOrDefault(e => e.Name == "TestName").Should().NotBeNull();
            model.SchemaElements.SingleOrDefault(e => e.Name == "TestName2").Should().NotBeNull();
            model.SchemaElements.SingleOrDefault(e => e.Name == "TestName3").Should().NotBeNull();
            model.EntityContainer.Should().NotBeNull();
            model.EntityContainer.Elements.SingleOrDefault(e => e.Name == "TestEntitySet").Should().NotBeNull();
            model.EntityContainer.Elements.SingleOrDefault(e => e.Name == "TestEntitySet2").Should().NotBeNull();
            model.EntityContainer.Elements.SingleOrDefault(e => e.Name == "TestEntitySet3").Should().NotBeNull();
        }
Пример #12
0
        public async Task ApiModelBuilder_ShouldCorrectlyAddBindingsForSingletonNavigationProperty()
        {
            // In this case, only one singleton Me has entity type Person.
            // Bindings for collection navigation property Customer.Friends should NOT be added.
            // Bindings for singleton navigation property Customer.BestFriend should be added.
            var model = await RestierTestHelpers.GetTestableModelAsync <ApiH>();

            var binding = model.EntityContainer.FindEntitySet("Customers").NavigationPropertyBindings.Single();

            binding.NavigationProperty.Name.Should().Be("BestFriend");
            binding.Target.Name.Should().Be("Me");
            binding = model.EntityContainer.FindSingleton("Me2").NavigationPropertyBindings.Single();
            binding.NavigationProperty.Name.Should().Be("BestFriend");
            binding.Target.Name.Should().Be("Me");
        }
Пример #13
0
        public async Task ApiModelBuilder_ShouldSkipExistingEntitySet()
        {
            var model = await RestierTestHelpers.GetTestableModelAsync <ApiF>();

            model.EntityContainer.FindEntitySet("VipCustomers").EntityType().Name.Should().Be("VipCustomer");
        }