public void NetCoreInterop_Start_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.Start(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_Start_module_withoutStart_do_nothing() { ///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.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.Start(moduleCreated); ///assert ///cleanup }
public void NetCoreInterop_Create_throws_when_Start_is_Missing_throws() { ///arrage uint returnValue = 0; Mock <DotNetCoreReflectionLayer> mockedReflectionLayer = new Mock <DotNetCoreReflectionLayer>(); MethodInfo anyFakeMethod = typeof(NetCoreInteropUnitTests).GetRuntimeMethod("anyFakeMethod", new Type[] { }); mockedReflectionLayer.Setup(t => t.GetMethod(null, "Receive", null)).Returns(anyFakeMethod); mockedReflectionLayer.Setup(t => t.GetMethod(null, "Destroy", null)).Returns(anyFakeMethod); NetCoreInterop.replaceReflectionLayer(mockedReflectionLayer.Object); ///act try { returnValue = NetCoreInterop.Create((IntPtr)0x42, (IntPtr)0x42, "AnyAssemblyName", "AnyEntryType", "AnyConfiguration"); } catch (Exception e) { ///assert /// Assert.Contains("Missing implementation of Create, Destroy or Receive.", e.Message); return; } Assert.True(false, "No exception was thrown."); ///cleanup }
public void NetCoreInterop_Create_throws_when_InvokeMethod_throws() { ///arrage uint returnValue = 0; Mock <DotNetCoreReflectionLayer> mockedReflectionLayer = new Mock <DotNetCoreReflectionLayer>(); mockedReflectionLayer.Setup(t => t.InvokeMethod(null, null, null)).Throws(new Exception("Fake Exception.")); NetCoreInterop.replaceReflectionLayer(mockedReflectionLayer.Object); ///act try { returnValue = NetCoreInterop.Create((IntPtr)0x42, (IntPtr)0x42, "AnyAssemblyName", "AnyEntryType", "AnyConfiguration"); } catch (Exception) { ///assert /// return; } Assert.True(false, "No exception was thrown."); ///cleanup }
public void NetCoreInterop_Receive_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. try { moduleCreated = NetCoreInterop.Create((IntPtr)0x42, (IntPtr)0x42, "AnyAssemblyName", "AnyEntryType", "AnyConfiguration"); } catch (FileNotFoundException) { ///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 Message messageInstance = new Message(notFail____minimalMessage); uint messageSize = uint.Parse(messageInstance.Content.GetLength(0).ToString()) + 14; ///act NetCoreInterop.Receive(notFail____minimalMessage, messageSize, moduleCreated); ///assert mockedReflectionLayer.Verify(t => t.InvokeMethod(null, anyFakeMethod, It.IsAny <Object[]>())); ///cleanup }
public void NetCoreInterop_Start_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.Start(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_Receive_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"); 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.Receive(notFail____minimalMessage, messageSize, 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_Create_with_entryType_null_arg_throw() { ///arrage ///act try { uint returnValue = NetCoreInterop.Create((IntPtr)0x42, (IntPtr)0x42, "AnyAssemblyName", null, "AnyConfiguration"); } catch (ArgumentNullException e) { ///assert /// Assert.Contains("entryType cannot be null", e.Message); return; } Assert.True(false, "No exception was thrown."); ///cleanup }
public void NetCoreInterop_Create_with_configuration_null_arg_not_throw() { ///arrage uint returnValue = 0; ///act try { returnValue = NetCoreInterop.Create((IntPtr)0x42, (IntPtr)0x42, "AnyAssemblyName", "AnyEntryType", null); } catch (FileNotFoundException e) { ///assert /// return; } Assert.True(false, "No exception was thrown."); ///cleanup }
public void NetCoreInterop_Create_with_assemblyName_null_arg_throw() { ///arrage Mock <DotNetCoreReflectionLayer> mockedReflectionLayer = new Mock <DotNetCoreReflectionLayer>(); NetCoreInterop.replaceReflectionLayer(mockedReflectionLayer.Object); ///act try { uint returnValue = NetCoreInterop.Create((IntPtr)0x42, (IntPtr)0x42, null, "AnyEntryType", "AnyConfiguration"); } catch (ArgumentNullException e) { ///assert /// Assert.Contains("assemblyName cannot be null", e.Message); return; } Assert.True(false, "No exception was thrown."); ///cleanup }
public void NetCoreInterop_create_a_module_success() { ///arrage uint returnValue = 0; 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); ///act returnValue = NetCoreInterop.Create((IntPtr)0x42, (IntPtr)0x42, "AnyAssemblyName", "AnyEntryType", "AnyConfiguration"); /// assert Assert.Equal(returnValue.ToString(), "1"); ///cleanup }
public void NetCoreInterop_Create_throws_when_GetType_throws() { ///arrage uint returnValue = 0; Mock <DotNetCoreReflectionLayer> mockedReflectionLayer = new Mock <DotNetCoreReflectionLayer>(); NetCoreInterop.replaceReflectionLayer(mockedReflectionLayer.Object); ///act try { returnValue = NetCoreInterop.Create((IntPtr)0x42, (IntPtr)0x42, "AnyAssemblyName", "AnyEntryType", null); } catch (Exception) { ///assert /// return; } Assert.True(false, "No exception was thrown."); ///cleanup }