コード例 #1
0
        public async Task Can_filter_text_match(string matchingText, string nonMatchingText, TextMatchKind matchKind, string filterText)
        {
            // Arrange
            var resource = new FilterableResource
            {
                SomeString = matchingText
            };

            var otherResource = new FilterableResource
            {
                SomeString = nonMatchingText
            };

            await _testContext.RunOnDatabaseAsync(async dbContext =>
            {
                dbContext.RemoveRange(dbContext.FilterableResources);
                dbContext.FilterableResources.AddRange(resource, otherResource);

                await dbContext.SaveChangesAsync();
            });

            var route = $"/filterableResources?filter={matchKind.ToString().Camelize()}(someString,'{filterText}')";

            // Act
            var(httpResponse, responseDocument) = await _testContext.ExecuteGetAsync <Document>(route);

            // Assert
            httpResponse.Should().HaveStatusCode(HttpStatusCode.OK);

            responseDocument.ManyData.Should().HaveCount(1);
            responseDocument.ManyData[0].Attributes["someString"].Should().Be(resource.SomeString);
        }
コード例 #2
0
    public async Task Can_filter_text_match(string matchingText, string nonMatchingText, TextMatchKind matchKind, string filterText)
    {
        // Arrange
        var resource = new FilterableResource
        {
            SomeString = matchingText
        };

        var otherResource = new FilterableResource
        {
            SomeString = nonMatchingText
        };

        await _testContext.RunOnDatabaseAsync(async dbContext =>
        {
            await dbContext.ClearTableAsync <FilterableResource>();
            dbContext.FilterableResources.AddRange(resource, otherResource);
            await dbContext.SaveChangesAsync();
        });

        string route = $"/filterableResources?filter={matchKind.ToString().Camelize()}(someString,'{filterText}')";

        // Act
        (HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecuteGetAsync <Document>(route);

        // Assert
        httpResponse.ShouldHaveStatusCode(HttpStatusCode.OK);

        responseDocument.Data.ManyValue.ShouldHaveCount(1);
        responseDocument.Data.ManyValue[0].Attributes.ShouldContainKey("someString").With(value => value.Should().Be(resource.SomeString));
    }