예제 #1
0
        public async Task Run_Success()
        {
            var path = Path.Combine(Environment.CurrentDirectory, "TestData/TestFile.txt");

            await using var stream = File.OpenRead(path);
            var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name))
            {
                Headers     = new HeaderDictionary(),
                ContentType = MimeTypesConstants.Text.Plain
            };

            var wordCountSearchParameter = new WordCountSearchParameter
            {
                File = file,
            };

            wordCountSearchParameter.Validate();

            _wordCounterServiceMock.Setup(x => x.ProcessWordsWithDefinitions(It.IsAny <string>(), It.IsAny <int>()))
            .ReturnsAsync(new List <WordCountApiResponse>
            {
                new WordCountApiResponse
                {
                    Count       = 10,
                    Definitions = new List <Definitions>(),
                    Word        = "Test"
                }
            });

            var result = await _wordCountCommand.Run(wordCountSearchParameter);

            result.Any().Should().BeTrue();
        }
        public void Validate_Docx_File_Upload_Success()
        {
            var path = Path.Combine(Environment.CurrentDirectory, "TestData/TestFile.docx");

            using var stream = File.OpenRead(path);
            var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name))
            {
                Headers     = new HeaderDictionary(),
                ContentType = Core.Data.Constants.MimeTypesConstants.Application.WordDocx
            };

            var wordCountSearchParameter = new WordCountSearchParameter
            {
                File = file,
            };

            wordCountSearchParameter.Validate();
            wordCountSearchParameter.Limit.Should().Be(WordCountSearchParameter.DefaultLimit);
            wordCountSearchParameter.Text.HasValue().Should().BeTrue();
        }
        public void Validate_Text_File_With_Limit_Upload_Success()
        {
            var path = Path.Combine(Environment.CurrentDirectory, "TestData/TestFile.txt");

            using var stream = File.OpenRead(path);
            var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name))
            {
                Headers     = new HeaderDictionary(),
                ContentType = MimeTypesConstants.Text.Plain
            };
            const int limit = 100;
            var       wordCountSearchParameter = new WordCountSearchParameter
            {
                File  = file,
                Limit = limit
            };

            wordCountSearchParameter.Validate();
            wordCountSearchParameter.Limit.Should().Be(limit);
            wordCountSearchParameter.Text.HasValue().Should().BeTrue();
        }
 public override Task Validate(WordCountSearchParameter input)
 {
     input.Validate();
     return(Task.CompletedTask);
 }