示例#1
0
        public void OpenStream_WhenFileExistsAndCheckExistenceTrue_ShouldReturnCorrectStream(string text)
        {
            try
            {
                // Arrange
                var logger = new LoggerConfiguration().CreateLogger();
                var storageStreamProvider = new StorageStreamProvider(_testStorageFileName, logger);
                File.WriteAllText(_testStorageFileName, string.Empty);

                // Act
                using var storageStream = storageStreamProvider.OpenStream();

                // Assert
                using var writer = new BinaryWriter(storageStream);
                writer.Seek(0, SeekOrigin.Begin);
                writer.Write(text);
                writer.Dispose();
                using var reader = new BinaryReader(File.OpenRead(_testStorageFileName));
                var writtenTextBytes = reader.ReadBytes((int)reader.BaseStream.Length);
                var writtenText      = Encoding.UTF8.GetString(writtenTextBytes);

                Assert.Equal(text, writtenText.Trim());
            }
            finally
            {
                ClearSideEffects();
            }
        }
示例#2
0
        public void OpenStream_WhenFileNotExistsAndCheckExistenceTrue_ShouldThrowException()
        {
            try
            {
                // Arrange
                var logger = new LoggerConfiguration().CreateLogger();
                var storageStreamProvider = new StorageStreamProvider(_testStorageFileName, logger);

                // Act
                void Act() => storageStreamProvider.OpenStream().Dispose();

                // Assert
                Assert.Throws <StorageNotFoundException>(Act);
            }
            finally
            {
                ClearSideEffects();
            }
        }