public void TokenExtractor_InCorrect_Token_Test() { var t = new TokenExtractor(new CurlyBracketDefinition()); t.Extract("Hoang ]Duy[ Bao").ToList() .Should().HaveCount(0); t.Extract("Hoang Duy Bao[[").ToList() .Should().HaveCount(0); }
public void TokenExtractor_Support_DuplicateOfToken_Test() { var t = new TokenExtractor(new CurlyBracketDefinition()); t.Extract("Hoang [{Duy}] Bao").ToList() .Should().HaveCount(1) .And.Subject.First().Token.Should().Be("{Duy}"); }
public void TokenExtractor_BracketsToken_Test() { var t = new TokenExtractor(new CurlyBracketDefinition()); t.Extract("Hoang {Duy} Bao").ToList() .Should().HaveCount(1) .And.Subject.First().Token.Should().Be("{Duy}"); t.Extract("Hoang Duy Bao").ToList() .Should().HaveCount(0); t.Extract("").ToList() .Should().HaveCount(0); t.Extract((string)null).ToList() .Should().HaveCount(0); var list = t.Extract( "Hoang {Duy} Bao, Hoang {Duy} Bao, Hoang {Duy} Bao, Hoang {Duy} Bao, Hoang {Duy} Bao, Hoang {Duy} Bao, Hoang {Duy} Bao, Hoang {Duy} Bao, Hoang {Duy} Bao, Hoang {Duy} Bao, Hoang {Duy} Bao, Hoang {Duy}") .ToList(); list.Should().HaveCount(12) .And.Subject.First().Key.Should().Be("Duy"); }
public void TokenExtractor_AngledBracket_Test() { var t = new TokenExtractor(new AngledBracketDefinition()); t.Extract("Hoang <Duy> Bao").ToList() .Should().HaveCount(1) .And.Subject.First().Token.Should().Be("<Duy>"); t.Extract("Hoang Duy Bao").ToList() .Should().HaveCount(0); t.Extract("").ToList() .Should().HaveCount(0); t.Extract((string)null).ToList() .Should().HaveCount(0); var list = t.Extract( "Hoang <Duy> Bao, Hoang <Duy> Bao, Hoang <Duy> Bao, Hoang <Duy> Bao, Hoang <Duy> Bao, Hoang <Duy> Bao, Hoang <Duy> Bao, Hoang <Duy> Bao, Hoang <Duy> Bao, Hoang <Duy> Bao, Hoang <Duy> Bao, Hoang <Duy>") .ToList(); list.Should().HaveCount(12) .And.Subject.First().Key.Should().Be("Duy"); }
public async Task Extract_TemplatesWithSpecialCharacters_ExtractionSuccessfull() { // Arrange Mock <ILogger <TokenMapper> > logger = new Mock <ILogger <TokenMapper> >(); Mock <ILogger <TokenExtractor> > extractionLogger = new Mock <ILogger <TokenExtractor> >(); ITokenMapper mapper = new TokenMapper(logger.Object); ITokenExtractor tokenExtractor = new TokenExtractor(mapper, extractionLogger.Object); // Act List <Extraction> extractions = await tokenExtractor.Extract("Hello\n${uuid}"); // Assert Assert.Single(extractions); Assert.Equal("Hello\n{0}", extractions[0].Template); Assert.Equal("uuid", extractions[0].Tokens[0].Key); }
public async Task Extract_TemplatesWithJson_ExtractionSuccessfull() { // Arrange Mock <ILogger <TokenMapper> > logger = new Mock <ILogger <TokenMapper> >(); Mock <ILogger <TokenExtractor> > extractionLogger = new Mock <ILogger <TokenExtractor> >(); ITokenMapper mapper = new TokenMapper(logger.Object); ITokenExtractor tokenExtractor = new TokenExtractor(mapper, extractionLogger.Object); // Act List <Extraction> extractions = await tokenExtractor.Extract("{\"Hello\": \"World\", \"id\": \"${uuid}\"}"); // Assert Assert.Single(extractions); Assert.Equal("{{\"Hello\": \"World\", \"id\": \"{0}\"}}", extractions[0].Template); Assert.Equal("uuid", extractions[0].Tokens[0].Key); }
public async Task Extract_TemplateWithOneToken_TokenExtracted() { // Arrange Mock <ILogger <TokenMapper> > logger = new Mock <ILogger <TokenMapper> >(); Mock <ILogger <TokenExtractor> > extractionLogger = new Mock <ILogger <TokenExtractor> >(); ITokenMapper mapper = new TokenMapper(logger.Object); ITokenExtractor tokenExtractor = new TokenExtractor(mapper, extractionLogger.Object); // Act List <Extraction> extractions = await tokenExtractor.Extract("I am a log for ${uuid}"); // Assert Extraction extraction = extractions.First(); Assert.Equal("I am a log for {0}", extraction.Template); Assert.Equal("uuid", extraction.Tokens.First().Key); }
public async Task Extract_TemplateWithTwoTokenInJson_TokensExtracted() { // Arrange Mock <ILogger <TokenMapper> > logger = new Mock <ILogger <TokenMapper> >(); Mock <ILogger <TokenExtractor> > extractionLogger = new Mock <ILogger <TokenExtractor> >(); ITokenMapper mapper = new TokenMapper(logger.Object); ITokenExtractor tokenExtractor = new TokenExtractor(mapper, extractionLogger.Object); // Act List <Extraction> extractions = await tokenExtractor.Extract("{\"Hello\":\"${randomitem(world,universe)}\", \"id\": \"${uuid}\"}"); // Assert Extraction extraction = extractions.First(); Assert.Equal("{{\"Hello\":\"{0}\", \"id\": \"{1}\"}}", extraction.Template); Assert.Equal("randomitem", extraction.Tokens[0].Key); Assert.Equal("uuid", extraction.Tokens[1].Key); }