Example #1
0
        public void Debug_Log_Call_Shoould_Write_File_Expected_Message__And_Path()
        {
            string message         = LoggerProvider.CreateLogMessage(MessageLength.Normal);
            string expectedMessage = $"{_dateTimeProviderMock.UtcNow} [DEBUG] {message}";

            using (var stream = _streamFactoryMock.Create())
            {
                var streamLogger = new StreamLogger(stream, _dateTimeProviderMock, _streamWriterMock);
                streamLogger.Log(LogLevel.Debug, message);
                _streamWriterMock.Received().Writeline(Arg.Any <Stream>(), Arg.Is(expectedMessage));
            }
        }
Example #2
0
        public void WriteStringList(Stream stream, IEnumerable items, SeekOrigin seekOrigin = SeekOrigin.Begin)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }
            if (!Enum.IsDefined(typeof(SeekOrigin), seekOrigin))
            {
                throw new InvalidEnumArgumentException(nameof(seekOrigin), (int)seekOrigin, typeof(SeekOrigin));
            }

            var alternateStream = _streamFactory.Create();

            using (var streamWriter = _streamWriterService.Writer(alternateStream, Encoding.Default))
            {
                foreach (var item in items)
                {
                    streamWriter.WriteLine(item);
                }
                streamWriter.Flush();

                stream.Seek(0, seekOrigin);
                alternateStream.Seek(0, SeekOrigin.Begin);
                alternateStream.CopyTo(stream);
            }
        }
Example #3
0
        public IEnumerable ReadStringList(Stream stream, SeekOrigin seekOrigin = SeekOrigin.Begin)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (!Enum.IsDefined(typeof(SeekOrigin), seekOrigin))
            {
                throw new InvalidEnumArgumentException(nameof(seekOrigin), (int)seekOrigin, typeof(SeekOrigin));
            }

            var result = new List <string>();

            var alternateStream = _streamFactory.Create();

            stream.Seek(0, seekOrigin);
            stream.CopyTo(alternateStream);
            alternateStream.Seek(0, SeekOrigin.Begin);

            using (var streamReader = _streamReaderService.Reader(alternateStream, Encoding.Default))
            {
                string line;
                while ((line = streamReader.ReadLine()) != null)
                {
                    result.Add(line);
                }
            }

            return(result);
        }
Example #4
0
 public void TestInititalize()
 {
     _streamFactoryMock = Substitute.For <IStreamFactory>();
     _streamFactoryMock.Create().Returns(new MemoryStream());
     _dateTimeProviderMock = Substitute.For <IDateTimeProvider>();
     _dateTimeProviderMock.UtcNow.Returns(DateTime.UtcNow.ToString());
     _streamWriterMock = Substitute.For <IStreamWriter>();
 }
Example #5
0
        public Stream Import(string filePath)
        {
            if (string.IsNullOrWhiteSpace(filePath))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(filePath));
            }

            var stream = _streamFactory.Create();

            using (var fileStream = _fileService.Open(filePath, FileMode.Open, FileAccess.Read))
            {
                fileStream.Seek(0, SeekOrigin.Begin);
                fileStream.CopyTo(stream);
            }

            stream.Seek(0, SeekOrigin.Begin);
            return(stream);
        }
Example #6
0
    public async Task ExtractAsync(string archivePath, string outputDirectory)
    {
        await using var inputStream = _fileService.OpenRead(archivePath);
        await using var zipStream   = _streamFactory.Create(inputStream);

        var outputFilePath = GetOutputFilePath(archivePath, outputDirectory);

        await using var outputStream = _fileService.OpenWrite(outputFilePath);

        await zipStream.CopyToAsync(outputStream);
    }
Example #7
0
        public void Send(MailMessage mailMessage)
        {
            _streamManager.Add(_streamFactory.Create());
            var response = _connectionEngine.Execute(mailMessage);

            if (response.ResponseCode != SmtpResponseCode.ClosingTransmissionChannel)
            {
                throw new SmtpException("Server returned " + response.ResponseCode + " " + response.ResponseText);
            }
            _streamManager.Close();
        }
        public HashValue Sign(IUser user, HashValue previousHash, UserMessage message)
        {
            using (var stream = _streamFactory.Create())
            {
                stream.Write("Client {0} after {1} ask for ", user, previousHash);
                _messageStreamWriter.Write(stream, message);

                var hash = _hashProvider.GetHashOfStream(stream);
                return(hash);
            }
        }
Example #9
0
 public FileResource(
     FileResourceExporter fileResourceExporter,
     FileResourceImporter fileResourceImporter,
     FileResourceReader fileResourceReader,
     FileResourceWriter fileResourceWriter,
     IStreamFactory streamFactory)
 {
     _fileResourceExporter = fileResourceExporter ?? throw new ArgumentNullException(nameof(fileResourceExporter));
     _fileResourceImporter = fileResourceImporter ?? throw new ArgumentNullException(nameof(fileResourceImporter));
     _fileResourceReader   = fileResourceReader ?? throw new ArgumentNullException(nameof(fileResourceReader));
     _fileResourceWriter   = fileResourceWriter ?? throw new ArgumentNullException(nameof(fileResourceWriter));
     if (streamFactory == null)
     {
         throw new ArgumentNullException(nameof(streamFactory));
     }
     _stream = streamFactory.Create();
 }
Example #10
0
 public HashValue Sign(long index, INode node, string rnd, HashValue previousHash, IReadOnlyList <Transaction> transactions)
 {
     using (var stream = _streamFactory.Create())
     {
         stream.Write("Block {0} signed by {1} after {2}, Based on {3} and contains next transactions: ", index, node, previousHash, rnd);
         var first = true;
         foreach (var transaction in transactions)
         {
             if (first)
             {
                 first = false;
             }
             else
             {
                 stream.Write(", ");
             }
             stream.Write(transaction.Signature.ToString());
         }
         stream.Write(".");
         var hash = _hashProvider.GetHashOfStream(stream);
         return(hash);
     }
 }