Skip to content

Expressionの値をテストする #2127

Closed
2 of 2 issues completed
Closed
2 of 2 issues completed
@tsuna-can-se

Description

@tsuna-can-se

概要

現状の単体テストでは、リポジトリに渡される検索条件が単体テストの中で確認されていない。
例えば samples/Dressca/dressca-backend/tests/Dressca.UnitTests.ApplicationCore/ApplicationService/CatalogApplicationServiceTest.cs では以下のように実装されている。

    [Fact]
    public async Task GetCatalogItemsAsync_リポジトリのFindAsyncを1回呼出す()
    {
        // Arrange
        var catalogRepositoryMock = new Mock<ICatalogRepository>();
        var catalogBrandRepository = Mock.Of<ICatalogBrandRepository>();
        var catalogCategoryRepository = Mock.Of<ICatalogCategoryRepository>();
        var logger = this.CreateTestLogger<CatalogApplicationService>();
        var service = new CatalogApplicationService(catalogRepositoryMock.Object, catalogBrandRepository, catalogCategoryRepository, logger);
        const int skip = 1;
        const int take = 10;

        // Act
        _ = await service.GetCatalogItemsAsync(skip, take, 1, 1);

        // Assert
        catalogRepositoryMock.Verify(
            r => r.FindAsync(It.IsAny<Expression<Func<CatalogItem, bool>>>(), skip, take, AnyToken),
            Times.Once);
    }

Assertする際、検索条件の検証が It.IsAny<Expression<Func<CatalogItem, bool>>>() で行われており、適切に検索条件がテストされているとは言えない。
検索条件が正しく設定されているかテストする必要がある。

詳細 / 機能詳細(オプション)

対象のテストを明らかにしてから着手する必要がある。
必要に応じて Sub-issue を作成して、少しずつ対処する。

完了条件

  • リポジトリに検索条件を引き渡す個所で、適切な検索条件が渡されているか単体テストの中で確認できていること

Sub-issues

Metadata

Metadata

Assignees

Labels

not triaged精緻化、分析がされていないtarget: DresscaサンプルアプリケーションDresscaに関係がある

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions