Exemplo n.º 1
0
        public void NetCoreInterop_Destroy_with_moduleid_that_exists_succeed()
        {
            ///arrage
            Mock <DotNetCoreReflectionLayer> mockedReflectionLayer = new Mock <DotNetCoreReflectionLayer>();

            MethodInfo anyFakeMethod = typeof(NetCoreInteropUnitTests).GetRuntimeMethod("anyFakeMethod", new Type[] { });

            mockedReflectionLayer.Setup(t => t.GetMethod(null, "Receive", new Type[] { typeof(Message) })).Returns(anyFakeMethod);
            mockedReflectionLayer.Setup(t => t.GetMethod(null, "Destroy", new Type[] { })).Returns(anyFakeMethod);
            mockedReflectionLayer.Setup(t => t.GetMethod(null, "Start", new Type[] { })).Returns(anyFakeMethod);

            mockedReflectionLayer.Setup(t => t.InvokeMethod(null, anyFakeMethod, null));


            NetCoreInterop.replaceReflectionLayer(mockedReflectionLayer.Object);
            uint moduleCreated = 0;

            //Make sure we create the dictioary.

            moduleCreated = NetCoreInterop.Create((IntPtr)0x42, (IntPtr)0x42, "AnyAssemblyName", "AnyEntryType", "AnyConfiguration");

            ///act
            NetCoreInterop.Destroy(moduleCreated);

            ///assert
            mockedReflectionLayer.Verify(t => t.InvokeMethod(null, anyFakeMethod, It.IsAny <Object[]>()));


            ///cleanup
        }
Exemplo n.º 2
0
        public void NetCoreInterop_Destroy_with_moduleid_that_not_exists_throw()
        {
            ///arrage
            Mock <DotNetCoreReflectionLayer> mockedReflectionLayer = new Mock <DotNetCoreReflectionLayer>();
            MethodInfo anyFakeMethod = typeof(NetCoreInteropUnitTests).GetRuntimeMethod("anyFakeMethod", new Type[] { });

            mockedReflectionLayer.Setup(t => t.GetMethod(null, "Receive", new Type[] { typeof(Message) })).Returns(anyFakeMethod);
            mockedReflectionLayer.Setup(t => t.GetMethod(null, "Destroy", new Type[] { })).Returns(anyFakeMethod);
            mockedReflectionLayer.Setup(t => t.GetMethod(null, "Start", new Type[] { })).Returns(anyFakeMethod);

            NetCoreInterop.replaceReflectionLayer(mockedReflectionLayer.Object);


            //Make sure we create the dictioary.
            NetCoreInterop.Create((IntPtr)0x42, (IntPtr)0x42, "AnyAssemblyName", "AnyEntryType", "AnyConfiguration");

            ///act
            try
            {
                NetCoreInterop.Destroy(42);
            }
            catch (Exception e)
            {
                ///assert
                ///
                Assert.Contains("Module 42 can't be found.", e.Message);
                return;
            }
            Assert.True(false, "No exception was thrown.");

            ///cleanup
        }
        public void NetCoreInterop_Destroy_with_moduleid_that_not_exists_throw()
        {
            ///arrage
            ///arrage

            //Make sure we create the dictioary.
            try
            {
                NetCoreInterop.Create((IntPtr)0x42, (IntPtr)0x42, "AnyAssemblyName", "AnyEntryType", "AnyConfiguration");
            }
            catch (FileNotFoundException e)
            {
                ///assert
                ///
            }

            byte[] notFail____minimalMessage =
            {
                0xA1, 0x60,             /*header*/
                0x00, 0x00, 0x00, 14,   /*size of this array*/
                0x00, 0x00, 0x00, 0x00, /*zero properties*/
                0x00, 0x00, 0x00, 0x00  /*zero message content size*/
            };

            ///act
            var  messageInstance = new Message(notFail____minimalMessage);
            uint messageSize     = uint.Parse(messageInstance.Content.GetLength(0).ToString()) + 14;

            ///act
            try
            {
                NetCoreInterop.Destroy(42);
            }
            catch (Exception e)
            {
                ///assert
                ///
                Assert.Contains("Module 42 can't be found.", e.Message);
                return;
            }
            Assert.True(false, "No exception was thrown.");

            ///cleanup
        }