public void MakeCreator()
        {
            reader = A.Fake <ITextReader>();
            var words = new List <string> {
                "Привет", "Земля", "и", "Земля"
            };

            A.CallTo(() => reader.ReadWords(null))
            .WithAnyArguments()
            .Returns(words);

            wordProcessor = A.Fake <IWordProcessor>();
            var wordsWithCounts = new List <WordWithCount>
            {
                new WordWithCount("земля", 2),
                new WordWithCount("привет", 1)
            };

            A.CallTo(() => wordProcessor.ProcessWords(words))
            .WithAnyArguments()
            .Returns(wordsWithCounts);

            var builder = new ContainerBuilder();

            builder.RegisterInstance(reader).As <ITextReader>();
            builder.RegisterInstance(wordProcessor).As <IWordProcessor>();
            var container = GetContainer(builder);

            imageCreator = container.Resolve <IImageCreator>();
        }
Exemple #2
0
 public Result <Bitmap> GetTagCloudBitmap(Parameters parameters)
 {
     return(Result.Of(() => fileReader.ReadWords(parameters.InputFilePath))
            .RefineError("Failed to read input file")
            .Then(words => wordProcessor.ProcessWords(words))
            .RefineError("Failed to process words")
            .Then(processedWords => layoutAlgorithm.GetLayout(processedWords, parameters.ImageSize))
            .Then(layout =>
                  visualizer.GetLayoutBitmap(layout, parameters.Font, parameters.ImageSize, parameters.Colors))
            .RefineError("Failed to build layout"));
 }
        public void ImageCreator_CallDependenciesMethodsOnce()
        {
            imageCreator.CreateImage(settings);

            A.CallTo(() => reader.ReadWords(null))
            .WithAnyArguments()
            .MustHaveHappenedOnceExactly();

            A.CallTo(() => wordProcessor.ProcessWords(null))
            .WithAnyArguments()
            .MustHaveHappenedOnceExactly();
        }
Exemple #4
0
        public Result <None> CreateImage(IInitialSettings settings)
        {
            var words = reader.ReadWords(settings.InputFilePath);

            return(wordProcessor.ProcessWords(words)
                   .Then(wordsWithCount => wordsWithCount.ToList())
                   .Then(wordsWithCount =>
            {
                words = wordsWithCount.Select(e => e.Word);
                var sizes = converter.ConvertToSizes(wordsWithCount);
                var rectangles = layouter.GetRectangles(sizes);
                return imageSizeCalculator.CalculateImageSize(rectangles)
                .Then(calculatedSize => HandleSize(settings, calculatedSize))
                .Then(imageSize => (rect: GetWordRectangles(words, rectangles, imageSize), imageSize));
            })
                   .Then(x => visualizer.DrawImage(x.rect, x.imageSize))
                   .Then(image => saver.SaveImage(image, settings.OutputFilePath)));
        }
Exemple #5
0
        public void CreateImage(IInitialSettings settings)
        {
            var words          = reader.ReadWords(settings.InputFilePath);
            var wordsWithCount = wordProcessor.ProcessWords(words).ToList();
            var sizes          = converter.ConvertToSizes(wordsWithCount);
            var rectangles     = layouter.GetRectangles(sizes);
            var imageSize      = settings.ImageSize;

            if (imageSize == Size.Empty)
            {
                imageSize = imageSizeCalculator.CalculateImageSize(rectangles);
            }
            rectangles = rectanglesTransformer.TransformRectangles(rectangles, imageSize);
            words      = wordsWithCount.Select(e => e.Word);
            var wordRectangles = words.Zip(rectangles, (w, r) => new WordRectangle(w, r)).ToList();
            var image          = visualizer.DrawImage(wordRectangles, imageSize);

            saver.SaveImage(image, settings.OutputFilePath);
        }
Exemple #6
0
 public Result <IEnumerable <string> > GetWords()
 {
     return(processor.ProcessWords(reader.ReadWords()));
 }