public void ShouldAttendTheServiceFlow()
        {
            var sentences           = new[] { new Sentence(null, 1, "1") };
            var algorithmResult     = new AlgorithmResult(sentences);
            var serializationResult = Guid.NewGuid().ToString();

            _mockAlgorithm
            .Setup(m => m.Analyse(It.IsAny <StreamReader>()))
            .Returns(algorithmResult)
            .Verifiable();

            _mockSerializer
            .Setup(m => m.Serialize(It.IsAny <Analyse>()))
            .Callback(new Action <Analyse>(a => Validations.SentenceValidator.AssertAreEquivalents(sentences, a.Sentences, true)))
            .Returns(serializationResult)
            .Verifiable();

            _mockRepository
            .Setup(m => m.SaveAnalyse(It.IsAny <Analyse>()))
            .Callback(new Action <Analyse>(a => Validations.SentenceValidator.AssertAreEquivalents(sentences, a.Sentences, true)))
            .Returns(1)
            .Verifiable();

            var tempFile = Path.GetTempFileName();
            var result   = _testingObject.Analyse(new AnalyseCommand(tempFile));

            Assert.AreEqual(serializationResult, result.Result);
            _mockRepository.VerifyAll();
            _mockSerializer.VerifyAll();
            _mockAlgorithm.VerifyAll();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Text Analyser!");
            Console.WriteLine();

            string filePath;

            Console.WriteLine();
            Console.WriteLine("Inform the file path:");
            filePath = Console.ReadLine();

            if (!File.Exists(filePath))
            {
                Console.WriteLine("File not found.");
                return;
            }

            Console.WriteLine("Inform the analyse algorithm");
            Console.WriteLine(" 1: TextSubStringsAlgorithm");
            Console.WriteLine(" 2: CharacterTableMapAlgorithm");

            try
            {
                switch (int.Parse(Console.ReadLine()))
                {
                case 1:
                    _algorithm = new TextSubStringsAlgorithm();
                    break;

                case 2:
                    _algorithm = new CharacterTableMapAlgorithm();
                    break;

                default:
                    Console.WriteLine("Invalid option.");
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Erro: {ex.Message}");
                return;
            }

            Console.WriteLine();
            Console.WriteLine($"Great. Lets analyse file {filePath}");
            Console.WriteLine();

            var sqlServerRepository = new SqlServerAnalyseDbContext();
            var jsonSerializer      = new JsonSerializer();

            Console.WriteLine("-----------------------");
            Console.WriteLine($"Repository: {sqlServerRepository}");
            Console.WriteLine($"Serializer: {jsonSerializer}");
            Console.WriteLine($"Algorithm: {_algorithm}");
            Console.WriteLine();

            Console.WriteLine("Running analyser ...");
            var analyser = new TextAnalyserService(
                repository: sqlServerRepository,
                serializer: jsonSerializer,
                algorithm: _algorithm);

            var result = analyser.Analyse(new AnalyseCommand(filePath));

            Console.WriteLine(result);
        }