コード例 #1
0
ファイル: Program.cs プロジェクト: badyb14/ranagams
        static void Main(string[] args)
        {
            var    folder        = "Dictionaries";
            var    fileName      = "word*";
            string extra         = null;
            string exclusionList = null;

            var current       = Directory.GetCurrentDirectory();
            var path          = Path.Combine(current, folder);
            var baseNames     = Directory.GetFiles(path, fileName);
            var sourceFactory = new WordListFileSourceFactory(baseNames, path, extra, exclusionList);

            source1 = sourceFactory.GetWordList(true)[0];
            source1.Load();
            source2 = sourceFactory.GetWordList(false)[0];
            source2.Load();
            string word = "trainers"; //silent,elvis,samples,calipers,trainers, salesman, auctioned,mastering, discounted,reductions,percussion

            for (int i = 0; i < 1; i++)
            {
                RunTests(word);
            }

            Console.ReadKey();
        }
コード例 #2
0
        public void BuildWordListFullPath_Throws_WhenPathIsNull()
        {
            //Arrange
            string path = null;
            string name = "s";
            string lang = "eb";

            //Act
            //Assert
            var actual = WordListFileSourceFactory.BuildWordListFullPath(path, name, lang);
        }
コード例 #3
0
 public void Constructor_Throws_WhenInvalidBaseName()
 {
     //Arrange
     string[] baseNames       = new[] { null, string.Empty };
     string   path            = "";
     string   extraPrefix     = "";
     string   exclusionPrefix = "";
     //Act
     //Assert
     var objectUnderTest = new WordListFileSourceFactory(baseNames, path, extraPrefix, exclusionPrefix);
 }
コード例 #4
0
        public void BuildWordListFullPath_Case2()
        {
            //Arrange
            string path = @"c:\somefolder";
            string name = "words";
            string lang = "en";

            //Act
            var actual = WordListFileSourceFactory.BuildWordListFullPath(path, name, lang);

            //Assert
            Assert.AreEqual(@"c:\somefolder\words_en.txt", actual);
        }
コード例 #5
0
        public void BuildWordListFullPath_Case1()
        {
            //Arrange
            string path = "";
            string name = null;
            string lang = null;

            //Act
            var actual = WordListFileSourceFactory.BuildWordListFullPath(path, name, lang);

            //Assert
            Assert.AreEqual("_.txt", actual);
        }
コード例 #6
0
        public void BuildWordListFullPath_WhenPathIsEmpty()
        {
            //Arrange
            string path = "";
            string name = "s";
            string lang = "eb";

            //Act
            var actual = WordListFileSourceFactory.BuildWordListFullPath(path, name, lang);

            //Assert
            Assert.AreEqual("s_eb.txt", actual);
        }
コード例 #7
0
        public void TryGetWordListLanguage_case1_RetursTrue()
        {
            //Arrange
            string filePath = @"c:\some_fol.der\words_en.txt";

            //Act
            string language = null;
            var    actual   = WordListFileSourceFactory.TryGetWordListLanguage(filePath, out language);

            //Assert
            Assert.AreEqual(true, actual);
            Assert.AreEqual("en", language);
        }
コード例 #8
0
        public void TryGetWordListLanguage_Case5_RetursFalse()
        {
            //Arrange
            string filePath = @"c:\somefolder\w..txt";

            //Act
            string language = null;
            var    actual   = WordListFileSourceFactory.TryGetWordListLanguage(filePath, out language);

            //Assert
            Assert.AreEqual(false, actual);
            Assert.AreEqual(null, language);
        }
コード例 #9
0
        public void TryGetWordListLanguage_EmptyPath_RetursFalse()
        {
            //Arrange
            string filePath = string.Empty;

            //Act
            string language = null;
            var    actual   = WordListFileSourceFactory.TryGetWordListLanguage(filePath, out language);

            //Assert
            Assert.AreEqual(false, actual);
            Assert.AreEqual(null, language);
        }
コード例 #10
0
        public void GetWordList_Case2()
        {
            //Arrange
            string[] baseNames       = new string[] { @"c:\d\w_en.txt", "badentry" };
            string   path            = @"c:\d";
            string   extraPrefix     = "";
            string   exclusionPrefix = "";
            var      objectUnderTest = new WordListFileSourceFactory(baseNames, path, extraPrefix, exclusionPrefix);

            //Act
            var actual = objectUnderTest.GetWordList(true);

            //Assert
            Assert.AreEqual(1, actual.Length);
        }
コード例 #11
0
ファイル: AnagramExtensions.cs プロジェクト: badyb14/ranagams
        public static IServiceCollection AddFileBasedAnagramService(this IServiceCollection collection, IConfiguration config)
        {
            var folder        = config["WordListConfig:FileProvider:Folder"];
            var fileName      = config["WordListConfig:FileProvider:BaseListName"];
            var extra         = config["WordListConfig:FileProvider:SupplementalName"];
            var exclusionList = config["WordListConfig:FileProvider:BadWords"];

            if (string.IsNullOrWhiteSpace(folder))
            {
                throw new ArgumentException("invalid folder configuration");
            }

            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentException("invalid file name configuration");
            }

            AnagramResolverService resolverService = null;
            //could take ILoggerFactory wrap it and make it a parameter for consumption.
            var logger    = LoggerFactory.CreateLogger("AnagramApi.AnagramResolverService");
            var current   = Directory.GetCurrentDirectory();
            var path      = Path.Combine(current, folder);
            var baseNames = Directory.GetFiles(path, fileName);

            logger.LogWarning("Configuration path {0}. File pattern {1}. File Count {2}", path, fileName, baseNames.Length);

            var sourceFactory = new WordListFileSourceFactory(baseNames, path, extra, exclusionList);
            var sources       = sourceFactory.GetWordList(true);

            resolverService = new AnagramResolverService(sources, (w) => new WordGenerator(w));

            collection.AddSingleton <IAnagramResolverService, AnagramResolverService>((s) => { return(resolverService); });

            EnsureAnagramServiceTelemetry(collection);

            return(collection);
        }