コード例 #1
0
        public async Task NullIsReturnedWhenNoExtractorWasFound()
        {
            // Arrange
            var repository = new MediaExtractorRepository();

            // Act
            var url = await repository.ExtractMedia("test");

            // Assert
            Assert.IsNull(url);
        }
コード例 #2
0
        public async Task NonMatchingExtractorIsNotUsed()
        {
            // Arrange
            var repository = new MediaExtractorRepository();
            var extractor  = new Mock <IMediaExtractor>();

            extractor.Setup(v => v.CanExtract("test")).Returns(false);
            extractor.Setup(v => v.GetMediaUrl("test")).Verifiable();

            repository.AddExtractor(extractor.Object);

            // Act
            await repository.ExtractMedia("test");

            // Assert
            extractor.Verify(v => v.CanExtract("test"), Times.Once());
            extractor.Verify(v => v.GetMediaUrl("test"), Times.Never());
        }
コード例 #3
0
        public async Task SearchEndsWithFirstMatch()
        {
            // Arrange
            var repository = new MediaExtractorRepository();
            var e1         = new Mock <IMediaExtractor>();

            e1.Setup(e => e.CanExtract("test")).Returns(true);
            var e2 = new Mock <IMediaExtractor>();

            e2.Setup(e => e.CanExtract("test")).Returns(true);

            repository.AddExtractor(e1.Object);
            repository.AddExtractor(e2.Object);

            // Act
            await repository.ExtractMedia("test");

            // Assert
            e1.Verify(v => v.CanExtract("test"), Times.Once());
            e2.Verify(v => v.CanExtract("test"), Times.Never());
        }
コード例 #4
0
        public async Task AllExtractorsAreChecked()
        {
            // Arrange
            var repository = new MediaExtractorRepository();
            var e1         = new Mock <IMediaExtractor>();

            e1.Setup(e => e.CanExtract("test")).Returns(false);
            var e2 = new Mock <IMediaExtractor>();

            e2.Setup(e => e.CanExtract("test")).Returns(false);

            repository.AddExtractor(e1.Object);
            repository.AddExtractor(e2.Object);

            // Act
            await repository.ExtractMedia("test");

            // Assert
            e1.Verify(v => v.CanExtract("test"), Times.Once());
            e2.Verify(v => v.CanExtract("test"), Times.Once());
        }