コード例 #1
0
        public async Task SubtextMustNotBeLongerThanText()
        {
            // setup mock factory for dependency injection
            var mockFactory = new Mock <IMatchingAlgorithmFactory>();
            var dto         = new FindMatchCommandDto {
                Text = "AAAA", Subtext = "XXXXXXXX", MatchingAlgorithmType = MatchingAlgorithmType.OffsetBased
            };
            var command = new FindMatchCommand(dto);
            var handler = new FindMatchCommand.FindMatchCommandHandler(mockFactory.Object);

            // execute use case
            await handler.Handle(command, new CancellationToken());
        }
コード例 #2
0
        public async Task Success_RegexBasedMatching()
        {
            // setup mock factory for dependency injection
            // this will use RegexBased matching algorithm
            var mockFactory = new Mock <IMatchingAlgorithmFactory>();

            mockFactory.Setup(o => o.CreateInstance(It.IsAny <MatchingAlgorithmType>()))
            .Returns <MatchingAlgorithmType>((type) => new RegexBasedMatchng());

            // execute use case
            var dto = new FindMatchCommandDto {
                Text = "AAAA", Subtext = "a", MatchingAlgorithmType = MatchingAlgorithmType.RegexBased
            };
            var command = new FindMatchCommand(dto);
            var handler = new FindMatchCommand.FindMatchCommandHandler(mockFactory.Object);
            var result  = await handler.Handle(command, new CancellationToken());

            // assert returned result contain valida data
            Assert.AreEqual(result.Positions.Count, 4);
            Assert.IsTrue(result.SelectedMatchingAlgorithmType == "RegexBased");
        }
コード例 #3
0
        public async Task SubtextMatchIsNotFound()
        {
            // setup mock algorithm to
            // return an empty list of positions
            var mockAlogirthm = new Mock <IMatchingAlgorithm>();

            mockAlogirthm.Setup(o => o.FindAllOccurencesOfSubtext(It.IsAny <string>(), It.IsAny <string>()))
            .Returns <string, string>((text, subtext) => Task.FromResult(new List <POSITION>()));

            // setup mock factory for dependency injection
            var mockFactory = new Mock <IMatchingAlgorithmFactory>();

            mockFactory.Setup(o => o.CreateInstance(It.IsAny <MatchingAlgorithmType>()))
            .Returns <MatchingAlgorithmType>((type) => mockAlogirthm.Object);

            // execute use case
            var dto = new FindMatchCommandDto {
                Text = "AAAA", Subtext = "xxxx", MatchingAlgorithmType = MatchingAlgorithmType.OffsetBased
            };
            var command = new FindMatchCommand(dto);
            var handler = new FindMatchCommand.FindMatchCommandHandler(mockFactory.Object);
            await handler.Handle(command, new CancellationToken());
        }