コード例 #1
0
ファイル: ConditionsTests.cs プロジェクト: erikvk/RESTable
        public async Task OneConditionFilters()
        {
            // One condition should filter the results
            await using var request = Context.CreateRequest <TestResource>()
                                      .WithCondition(nameof(TestResource.Id), Operators.GREATER_THAN, 10);
            request.Selector       = () => TestResource.Generate(20);
            await using var result = await request.GetResult();

            await using var serialized = await result.Serialize();

            Assert.Equal(10, serialized.EntityCount);
        }
コード例 #2
0
        public async Task MaxValueOffsetReturnsNoEntities()
        {
            await using var request       = Context.CreateRequest <TestResource>();
            request.Selector              = () => TestResource.Generate(20);
            request.MetaConditions.Offset = int.MaxValue;

            await using var result = await request.GetResult();

            await using var serialized = await result.Serialize();

            Assert.Equal(0, serialized.EntityCount);
        }
コード例 #3
0
        public async Task ZeroOffsetAppliesNoOffset()
        {
            await using var request       = Context.CreateRequest <TestResource>();
            request.Selector              = () => TestResource.Generate(20);
            request.MetaConditions.Offset = 0;

            await using var result = await request.GetResult();

            await using var serialized = await result.Serialize();

            Assert.Equal(20, serialized.EntityCount);
        }
コード例 #4
0
        public async Task NegativeLimitReturnsAllEntities()
        {
            await using var request      = Context.CreateRequest <TestResource>();
            request.Selector             = () => TestResource.Generate(20);
            request.MetaConditions.Limit = -1;

            await using var result = await request.GetResult();

            await using var serialized = await result.Serialize();

            Assert.Equal(20, serialized.EntityCount);
        }
コード例 #5
0
ファイル: ConditionsTests.cs プロジェクト: erikvk/RESTable
        public async Task TwoConditionsFilter()
        {
            // Two conditions should filter the results
            await using var request = Context.CreateRequest <TestResource>()
                                      .WithCondition(nameof(TestResource.Id), Operators.GREATER_THAN, 10)
                                      .WithCondition(nameof(TestResource.Name) + ".1", Operators.EQUALS, 'a'); // second letter in name is 'a'
            request.Selector       = () => TestResource.Generate(20);
            await using var result = await request.GetResult();

            await using var serialized = await result.Serialize();

            Assert.Equal(5, serialized.EntityCount);
        }
コード例 #6
0
        public async Task PositiveOffsetOffsetsEntities()
        {
            await using var request       = Context.CreateRequest <TestResource>();
            request.Selector              = () => TestResource.Generate(20);
            request.MetaConditions.Offset = 5;

            await using var result = await request.GetResult();

            await using var serialized = await result.Serialize();

            Assert.Equal(15, serialized.EntityCount);
            var first = await result.ToEntities <TestResource>().FirstAsync();

            Assert.Equal(6, first.Id);
        }
コード例 #7
0
        public async Task NegativeOffsetAppliesNegativeSkip()
        {
            await using var request       = Context.CreateRequest <TestResource>();
            request.Selector              = () => TestResource.Generate(20);
            request.MetaConditions.Offset = -5;

            await using var result = await request.GetResult();

            await using var serialized = await result.Serialize();

            Assert.Equal(5, serialized.EntityCount);
            var first = await result.ToEntities <TestResource>().FirstAsync();

            Assert.Equal(16, first.Id);
            var last = await result.ToEntities <TestResource>().LastAsync();

            Assert.Equal(20, last.Id);
        }