public void GetByIdAsync_CatalogueItemNotFound_ThrowsNotFoundException()
        {
            var catalogueItemRepositoryMock = new Mock <ICatalogueItemRepository>();

            catalogueItemRepositoryMock
            .Setup(r => r.GetByIdAsync(It.IsAny <string>(), default))
            .ReturnsAsync(() => null);

            var reader = new CatalogueItemReader(catalogueItemRepositoryMock.Object);

            Assert.ThrowsAsync <NotFoundException>(() => reader.GetByIdAsync(string.Empty, CancellationToken.None));
        }
        public async Task GetByIdAsync_ReturnsExpectedValue()
        {
            var expected = new CatalogueItemDto(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

            var catalogueItemResultMock = new Mock <ICatalogueItemResult>();

            catalogueItemResultMock.Setup(r => r.CatalogueItemId).Returns(expected.CatalogueItemId);
            catalogueItemResultMock.Setup(r => r.Name).Returns(expected.Name);

            var catalogueItemRepositoryMock = new Mock <ICatalogueItemRepository>();

            catalogueItemRepositoryMock
            .Setup(r => r.GetByIdAsync(It.IsAny <string>(), default))
            .ReturnsAsync(() => catalogueItemResultMock.Object);

            var reader = new CatalogueItemReader(catalogueItemRepositoryMock.Object);
            var actual = await reader.GetByIdAsync(string.Empty, CancellationToken.None);

            actual.Should().BeEquivalentTo(expected);
        }
        public async Task GetByIdAsync_CatalogueItemRepository_GetByIdAsync_CalledOnce()
        {
            var expected        = new CatalogueItemDto(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
            var catalogueItemId = expected.CatalogueItemId;

            var catalogueItemResultMock = new Mock <ICatalogueItemResult>();

            catalogueItemResultMock.Setup(r => r.CatalogueItemId).Returns(catalogueItemId);
            catalogueItemResultMock.Setup(r => r.Name).Returns(expected.Name);

            var catalogueItemRepositoryMock = new Mock <ICatalogueItemRepository>();

            catalogueItemRepositoryMock
            .Setup(r => r.GetByIdAsync(It.IsAny <string>(), default))
            .ReturnsAsync(() => catalogueItemResultMock.Object);

            var reader = new CatalogueItemReader(catalogueItemRepositoryMock.Object);
            await reader.GetByIdAsync(catalogueItemId, CancellationToken.None);

            catalogueItemRepositoryMock.Verify(r => r.GetByIdAsync(catalogueItemId, default));
        }
 public async Task <CatalogueItemDto> Handle(GetCatalogueItemByIdQuery request, CancellationToken cancellationToken) =>
 await catalogueItemReader.GetByIdAsync(request?.CatalogueItemId, cancellationToken);