示例#1
0
        public void GetFileSize_returns_expected_size(string message)
        {
            using var file = new TinyMemoryMappedFile("Test");

            var data = Encoding.UTF8.GetBytes(message);

            file.Write(data);

            file.GetFileSize().ShouldBe(message.Length);
        }
示例#2
0
        public void Write_then_read_returns_what_was_written(string message)
        {
            using var file = new TinyMemoryMappedFile("Test");

            var data = Encoding.UTF8.GetBytes(message);

            file.Write(data);

            file.Read().ShouldBe(data);
        }
示例#3
0
        public void Secondary_instance_keeps_file_alive()
        {
            using var file2 = new TinyMemoryMappedFile("Test");

            using (var file1 = new TinyMemoryMappedFile("Test"))
            {
                file1.Write(new byte[] { 1, 2, 3, 4, 5 });
            }

            file2.GetFileSize().ShouldBe(5);
        }
示例#4
0
        public void Dispose_destroys_file()
        {
            using (var file = new TinyMemoryMappedFile("Test"))
            {
                file.Write(new byte[] { 1, 2, 3, 4, 5 });
            }

            using (var file = new TinyMemoryMappedFile("Test"))
            {
                file.GetFileSize().ShouldBe(0);
            }
        }
示例#5
0
        public void Write_with_more_data_than_size_limit_throws()
        {
            using var file = new TinyMemoryMappedFile("Test", 4);

            Should.Throw <ArgumentOutOfRangeException>(() => file.Write(new byte[] { 1, 2, 3, 4, 5 }));
        }