Esempio n. 1
0
        public async Task GetObject_SharedMemoryObject_VerifyMatches(string content)
        {
            using (SharedMemoryManager manager = new SharedMemoryManager(_loggerFactory, _mapAccessor))
            {
                // Put content into shared memory
                SharedMemoryMetadata metadata = await manager.PutObjectAsync(content);

                // Get object from shared memory
                object readObject = await manager.GetObjectAsync(metadata.MemoryMapName, 0, content.Length, typeof(SharedMemoryObject));

                SharedMemoryObject readContent       = readObject as SharedMemoryObject;
                Stream             readContentStream = readContent.Content;

                Assert.NotNull(readContentStream);
                Assert.Equal(metadata.MemoryMapName, readContent.MemoryMapName);
                Assert.Equal(metadata.Count, readContent.Count);

                using (StreamReader reader = new StreamReader(readContentStream))
                {
                    string readContentString = await reader.ReadToEndAsync();

                    // Verify read content matches the content that was written
                    Assert.Equal(content, readContentString);
                }
            }
        }
Esempio n. 2
0
        public async Task GetObject_EmptyContent_SharedMemoryObject_VerifyException()
        {
            using (SharedMemoryManager manager = new SharedMemoryManager(_loggerFactory, _mapAccessor))
                using (Stream content = new MemoryStream())
                {
                    // Put content into shared memory
                    SharedMemoryMetadata metadata = await manager.PutObjectAsync(content);

                    // Get object from shared memory
                    await Assert.ThrowsAnyAsync <Exception>(() => manager.GetObjectAsync(metadata.MemoryMapName, 0, (int)content.Length, typeof(SharedMemoryObject)));
                }
        }
Esempio n. 3
0
        public async Task GetObject_String_VerifyMatches(string content)
        {
            using (SharedMemoryManager manager = new SharedMemoryManager(_loggerFactory, _mapAccessor))
            {
                // Put content into shared memory
                SharedMemoryMetadata metadata = await manager.PutObjectAsync(content);

                // Get object from shared memory
                object readObject = await manager.GetObjectAsync(metadata.MemoryMapName, 0, content.Length, typeof(string));

                string readContent = readObject as string;

                // Verify read content matches the content that was written
                Assert.Equal(content, readContent);
            }
        }
Esempio n. 4
0
        public async Task GetObject_ByteArray_VerifyMatches(int contentSize)
        {
            using (SharedMemoryManager manager = new SharedMemoryManager(_loggerFactory, _mapAccessor))
            {
                // Prepare content and put into shared memory
                byte[] content = TestUtils.GetRandomBytesInArray(contentSize);
                SharedMemoryMetadata metadata = await manager.PutObjectAsync(content);

                // Get object from shared memory
                object readObject = await manager.GetObjectAsync(metadata.MemoryMapName, 0, contentSize, typeof(byte[]));

                byte[] readContent = readObject as byte[];

                // Verify read content matches the content that was written
                Assert.True(TestUtils.UnsafeCompare(content, readContent));
            }
        }