Ejemplo n.º 1
0
        public void GetMemory_should_be_callable_indirectly()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                PULSharedMemory.GetMemoryInt32ByteArrayRef().Body = (ULSharedMemory @this, int size, out byte[] buf) =>
                {
                    buf = new byte[42];
                    for (int i = 0; i < buf.Length; i++)
                    {
                        buf[i] = 42;
                    }
                    return(true);
                };

                using (var sm = new ULSharedMemory())
                {
                    // Act
                    var size   = 1024;
                    var buf    = default(byte[]);
                    var actual = sm.GetMemory(size, out buf);

                    // Assert
                    Assert.IsTrue(actual);
                    Assert.AreEqual(42, buf.Length);
                    Assert.AreEqual((byte)42, buf[0]);
                    Assert.AreEqual((byte)42, buf[buf.Length - 1]);
                }
            }
        }
Ejemplo n.º 2
0
        public void AddOnDisposed_should_be_callable_indirectly()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var handler = default(ULSharedMemory.DisposedEventHandler);

                PULSharedMemory.AddOnDisposedDisposedEventHandler().Body = (@this, value) => handler += value;
                PULSharedMemory.Dispose().Body = @this =>
                {
                    handler(true);
                    IndirectionsContext.ExecuteOriginal(() => @this.Dispose());
                };

                var called = false;

                using (var sm = new ULSharedMemory())
                {
                    // Act
                    sm.OnDisposed += disposing => called = disposing;
                }


                // Assert
                Assert.IsTrue(called);
            }
        }