/// <returns>a singleton instance of repository</returns>
 public McrRepository createMcrRepository()
 {
     // We should maintain the singleton instance of cache repository
     // because its implementation needs the state of data synchronizing.
     if (cacheFileMcrRepositoryInstance == null)
     {
         FileProcessor baseFileProcessor = new TxtFileProcessor();
         FileProcessor rsaProcessor = new TextParsingDecorator(
             baseFileProcessor, new RijndaelEncryptor());
         FileProcessor compressionProcessor = new TextParsingDecorator(
             rsaProcessor, new CompressorImp());
         cacheFileMcrRepositoryInstance = new CacheFileMcrRepositoryProxy(
                         new ApringFileMcrRepository(
                         compressionProcessor));
     }
     return cacheFileMcrRepositoryInstance;
 }
        public async Task ProcessLinesAsync_CorrectTxtFile_AppropriateDictionaryOfWordsIsCalculated()
        {
            //prepare
            var writerThreshold                    = 32768;
            var wordFrequencyCalculatorMock        = new Mock <IWordFrequencyCalculator>();
            IDictionary <string, int> actualResult = null;

            wordFrequencyCalculatorMock.Setup(x => x.MergeInfo(It.IsAny <IDictionary <string, int> >()))
            .Callback((IDictionary <string, int> input) => {
                if (input.Count != 0)
                {
                    actualResult = new Dictionary <string, int>(input);
                }
            });

            string testFileName = "testtext.txt";
            string testData     = "Hello World world is beatiful\n Is that Right?\r\n";

            PrepareTestData(testData, testFileName);

            //act
            var txtProcessor = new TxtFileProcessor(wordFrequencyCalculatorMock.Object, writerThreshold);
            await txtProcessor.ProcessLinesAsync(testFileName);

            //check

            var expectedDictionary = new Dictionary <string, int>();

            expectedDictionary.Add("hello", 1);
            expectedDictionary.Add("world", 2);
            expectedDictionary.Add("is", 2);
            expectedDictionary.Add("beatiful", 1);
            expectedDictionary.Add("that", 1);
            expectedDictionary.Add("right?", 1);

            actualResult.Should().BeEquivalentTo(expectedDictionary);
        }