public void SupportsNonTrailingOptionalParameters() { var source = typeof(ILMethodsWithDefaultParameters).GetMethod(nameof(MethodWithNonTrailingOptionalParameters)); var shim = Shim.Create <Func <float, sbyte, bool> >(source); Assert.True(shim(Float32Contant, Int8Constant)); }
public void SupportsFactoryStyleStructConstructors() { var ctor = typeof(StructWithConstructor).GetConstructors().First(); var factory = Shim.Create <Func <StructWithConstructor> >(ctor, ConstructorDelegateKind.Factory); Assert.True(factory().HasBeenConstructedProperly); }
public void SupportsNonTrailingPurelyOptionalParameters() { var source = typeof(OptionalsShimTests).GetMethod(nameof(MethodWothNonTrailingPurelyOptionalParameters)); var shim = Shim.Create <Func <int, double, bool> >(source); Assert.True(shim(Int32Constant, Float64Constant)); }
public void Creates_a_success_response_with_payload() { var sut = Shim.Success("payload".ToByteString()); sut.Payload.ToStringUtf8().Should().Be("payload"); sut.Status.Should().Be((int)ResponseCodes.Ok); }
public static void Serialize(this Shim shim, LevelSerializeContext context) { context.WriteAnimationSet(shim.AnimationSet); context.bw.Write(shim.Position); context.bw.Write(shim.FacingLeft); context.bw.Write(shim.parallaxX); context.bw.Write(shim.parallaxY); context.bw.Write(shim.animationNumber); context.bw.WriteNullableString(shim.ambientSoundSource); if (context.Version >= 14) { context.bw.Write(shim.tag); } if (context.Version >= 16) { context.bw.Write(shim.properties.Count); foreach (var kvp in shim.properties) { context.bw.Write(kvp.Key); context.bw.Write(kvp.Value ?? string.Empty); // (null value should probably be blocked by editor, but being safe...) } } }
private static bool SignatureEquals(Shim shim, Type type, MethodBase method) { if (shim.Type == null || type == shim.Type) { return($"{shim.Type}::{shim.Original.ToString()}" == $"{type}::{method.ToString()}"); } if (type.IsSubclassOf(shim.Type)) { if ((shim.Original.IsAbstract || !shim.Original.IsVirtual) || (shim.Original.IsVirtual && !method.IsOverride())) { return($"{shim.Original.ToString()}" == $"{method.ToString()}"); } } if (shim.Type.IsAssignableFrom(type)) { if ((shim.Original.IsAbstract || !shim.Original.IsVirtual) || (shim.Original.IsVirtual && !method.IsOverride())) { return($"{shim.Original.ToString()}" == $"{method.ToString()}" || method.Name.EndsWith(shim.Original.Name)); } } return(false); }
private void Window_Loaded(object sender, RoutedEventArgs e) { fetchCommandLineArgs(Environment.GetCommandLineArgs()); Console.WriteLine("\nClient at :" + receiverPort + "\n"); tbWindow.Text = "Client at " + receiverPort; shim = new Shim(receiverPort, downLoadFolder); tReceive = new Thread( () => { while (true) { string message = shim.GetMessage(); Action <String> act = new Action <string>(processClientSideMessages); Object[] args = { message }; Dispatcher.Invoke(act, args); } } ); tReceive.Start(); fetchDataForArgsTab(); if (auto) { automator(sender, e); } }
public void RelativeLayoutTests_Item_ChangeSize() { _layout.Position = new Point(10, 20); _layout.Size = new Vector2(30f, 40f); _layout.Horizontal = HorizontalAlignment.Left; _layout.Vertical = VerticalAlignment.Top; var item = new Shim() { Horizontal = HorizontalAlignment.Right, Vertical = VerticalAlignment.Bottom }; _layout.AddItem(item); _layout.Size = new Vector2(100f, 200f); Assert.AreEqual(110, item.Rect.X); Assert.AreEqual(220, item.Rect.Y); Assert.AreEqual(HorizontalAlignment.Right, item.Horizontal); Assert.AreEqual(VerticalAlignment.Bottom, item.Vertical); Assert.AreEqual(10, _layout.Rect.X); Assert.AreEqual(20, _layout.Rect.Y); Assert.AreEqual(100f, _layout.Rect.Width); Assert.AreEqual(200f, _layout.Rect.Height); Assert.AreEqual(HorizontalAlignment.Left, _layout.Horizontal); Assert.AreEqual(VerticalAlignment.Top, _layout.Vertical); }
public void AbsoluteLayoutTests_TwoItem_FarAway() { _layout.Position = new Point(10, 20); _layout.Horizontal = HorizontalAlignment.Left; _layout.Vertical = VerticalAlignment.Top; var shim1 = new Shim() { Position = new Point(100, 200), Size = new Vector2(30, 40) }; _layout.AddItem(shim1); var shim2 = new Shim() { Position = new Point(150, 240), Size = new Vector2(50, 60) }; _layout.AddItem(shim2); Assert.AreEqual(110, shim1.Rect.X); Assert.AreEqual(220, shim1.Rect.Y); Assert.AreEqual(160, shim2.Rect.X); Assert.AreEqual(260, shim2.Rect.Y); Assert.AreEqual(HorizontalAlignment.Left, shim1.Horizontal); Assert.AreEqual(VerticalAlignment.Top, shim1.Vertical); }
public void AbsoluteLayoutTests_ChangeProperties_size() { _layout.Position = new Point(10, 20); _layout.Size = new Vector2(100f, 200f); _layout.Vertical = VerticalAlignment.Top; _layout.Horizontal = HorizontalAlignment.Left; var shim = new Shim() { Position = new Point(100, 200), Size = new Vector2(30, 40), Vertical = VerticalAlignment.Top, Horizontal = HorizontalAlignment.Left }; _layout.AddItem(shim); _layout.Vertical = VerticalAlignment.Bottom; _layout.Size = new Vector2(100f, 400f); Assert.AreEqual(10, _layout.Rect.X); Assert.AreEqual(-380, _layout.Rect.Y); Assert.AreEqual(100, _layout.Rect.Width); Assert.AreEqual(400, _layout.Rect.Height); Assert.AreEqual(VerticalAlignment.Bottom, _layout.Vertical); Assert.AreEqual(HorizontalAlignment.Left, _layout.Horizontal); Assert.AreEqual(110, shim.Position.X); Assert.AreEqual(-180, shim.Position.Y); Assert.AreEqual(HorizontalAlignment.Left, shim.Horizontal); Assert.AreEqual(VerticalAlignment.Top, shim.Vertical); }
public void SupportsShimsWithoutOptionalParameters() { var source = typeof(OptionalsShimTests).GetMethod(nameof(MethodWithoutOptionalParameters)); var shim = Shim.Create <Func <double, string, int, object, bool> >(source); Assert.True(shim(Float64Constant, StringConstant, Int32Constant, null)); }
public void SupportsDecimalOptionalParameters() { var source = typeof(OptionalsShimTests).GetMethod(nameof(MethodWithDecimalOptionalParameters)); var shim = Shim.Create <Func <bool> >(source); Assert.True(shim()); }
public void SupportsValidCSharpOptionalParameters() { var source = typeof(OptionalsShimTests).GetMethod(nameof(MethodWithAllPossibleCSharpOptionalParameters)); var shim = Shim.Create <Func <bool> >(source); Assert.True(shim()); }
public void ReturnTrue_GivenTimeEqualToDelayInMinutes() { Shim shim = Shim.Replace(() => DateTime.Now).With(() => DateTime.Now.AddMinutes(1)); var message = GetTestMessage(); PoseContext.Isolate(() => Assert.True(message.IsTimeToDisplay()), shim); }
public void TestReplace() { Shim shim = Shim.Replace(() => Console.WriteLine("")); Assert.AreEqual(typeof(Console).GetMethod("WriteLine", new[] { typeof(string) }), shim.Original); Assert.IsNull(shim.Replacement); }
public void RelativeLayoutTests_Item_TopCenter() { _layout.Position = new Point(10, 20); _layout.Size = new Vector2(30f, 40f); _layout.Horizontal = HorizontalAlignment.Left; _layout.Vertical = VerticalAlignment.Top; var item = new Shim() { Horizontal = HorizontalAlignment.Center, Vertical = VerticalAlignment.Top }; _layout.AddItem(item); Assert.AreEqual(25, item.Rect.X); Assert.AreEqual(20, item.Rect.Y); Assert.AreEqual(HorizontalAlignment.Center, item.Horizontal); Assert.AreEqual(VerticalAlignment.Top, item.Vertical); Assert.AreEqual(10, _layout.Rect.X); Assert.AreEqual(20, _layout.Rect.Y); Assert.AreEqual(30f, _layout.Rect.Width); Assert.AreEqual(40f, _layout.Rect.Height); Assert.AreEqual(HorizontalAlignment.Left, _layout.Horizontal); Assert.AreEqual(VerticalAlignment.Top, _layout.Vertical); }
public async void Start_calls_the_handlers_chat_method() { var options = Options.Create(new ChaincodeSettings { CORE_PEER_ADDRESS = "example.test:9999", CORE_CHAINCODE_ID_NAME = "unittest" }); var message = new ChaincodeMessage { Type = ChaincodeMessage.Types.Type.Register, Payload = new ChaincodeID { Name = "unittest" }.ToByteString() }; var handlerMock = new Mock <IHandler>(); handlerMock.Setup(m => m.Chat(message)).Returns(Task.CompletedTask); var handlerFactoryMock = new Mock <IHandlerFactory>(); handlerFactoryMock.Setup(m => m.Create("example.test", 9999)) .Returns(handlerMock.Object); var shim = new Shim(options, new Mock <ILogger <Shim> >().Object, handlerFactoryMock.Object); var result = await shim.Start(); result.Should().BeSameAs(handlerMock.Object); handlerFactoryMock.VerifyAll(); handlerMock.VerifyAll(); }
public void ThrowsOnNullInputs() { var placeholder = GetType().GetMethod(nameof(ThrowsOnNullInputs)); Assert.Throws <ArgumentNullException>(() => Shim.Create <Action>(null)); Assert.Throws <ArgumentNullException>(() => Shim.Create <Action>(null, ConstructorDelegateKind.Factory)); }
public void Creates_an_error_response() { var sut = Shim.Error("foobar"); sut.Message.Should().Be("foobar"); sut.Status.Should().Be((int)ResponseCodes.Error); }
public void Creates_an_empty_success_response() { var sut = Shim.Success(); sut.Payload.Should().BeEmpty(); sut.Status.Should().Be((int)ResponseCodes.Ok); }
public static Shim DeserializeShim(this LevelDeserializeContext context) { var animationSet = context.ReadAnimationSet(); var position = context.br.ReadPosition(); var facingLeft = context.br.ReadBoolean(); var parallaxX = context.br.ReadSingle(); var parallaxY = context.br.ReadSingle(); var shim = new Shim(animationSet, position, facingLeft, parallaxX, parallaxY); shim.animationNumber = context.br.ReadInt32(); shim.ambientSoundSource = context.br.ReadNullableString(); if (context.Version >= 14) { shim.tag = context.br.ReadInt32(); } if (context.Version >= 16) { int count = context.br.ReadInt32(); for (int i = 0; i < count; i++) { shim.properties.Add(context.br.ReadString(), context.br.ReadString()); } } return(shim); }
public void ReturnTrue_OnSecondInterval() { Shim shim = Shim.Replace(() => DateTime.Now).With(() => DateTime.Now.AddMinutes(1)); var message = GetTestMessage(); message.GetMessageInstance(); // Will reset the interval time PoseContext.Isolate(() => Assert.True(message.IsTimeToDisplay()), shim); }
public void ReturnTrue_AfterWaitingFullInterval() { const int intervalInMinutes = 1; Shim shim = Shim.Replace(() => DateTime.Now).With(() => DateTime.Now.AddMinutes(intervalInMinutes)); var currencyUpdate = new CurrencyUpdate(intervalInMinutes, null); PoseContext.Isolate(() => Assert.True(currencyUpdate.IsTimeToRun()), shim); }
public void SupportsClassInstanceMethods() { var source = typeof(ClassWithConstructor).GetMethod(nameof(ClassWithConstructor.PureInstanceMethod)); var shim = Shim.Create <Func <ClassWithConstructor, bool, bool> >(source); var instance = new ClassWithConstructor(); Assert.True(shim(instance, true)); }
public NetMQBeacon(NetMQContext context) { m_shim = new Shim(); m_actor = NetMQActor.Create(context, m_shim); m_receiveEventHelper = new EventDelegatorHelper <NetMQBeaconEventArgs>(() => m_actor.ReceiveReady += OnReceiveReady, () => m_actor.ReceiveReady -= OnReceiveReady); }
internal static Shim ShimGetByteArrayAsync(byte[] buffer) { return(Shim.Replace(() => Is.A <HttpClient>().GetByteArrayAsync(Is.A <Uri>())) .With((HttpClient @this, Uri uri) => { return new Task <byte[]>(() => buffer); })); }
//----------<Helper Function to process command line arguments and make the instance of shim> --------------------------- private void InitializeClient() { string[] args = Environment.GetCommandLineArgs(); int clientPort = Convert.ToInt32(args[1].Substring(args[1].IndexOf(':') + 1)); int serverPort = Convert.ToInt32(args[2].Substring(args[2].IndexOf(':') + 1)); shim = new Shim(clientPort, serverPort); }
public void PromptOK_Returns_Nothing() { Shim shim = Given_MessageBox_Show_Returns(MessageBoxResult.OK); PoseContext.Isolate(() => { subject.PromptOK("content", "title"); }, shim); }
public void TestReplaceWithInstanceVariable() { ShimTests shimTests = new ShimTests(); Shim shim = Shim.Replace(() => shimTests.TestReplace()); Assert.AreEqual(typeof(ShimTests).GetMethod("TestReplace"), shim.Original); Assert.AreSame(shimTests, shim.Instance); Assert.IsNull(shim.Replacement); }
private void Window_Loaded(object sender, RoutedEventArgs e) { shim = new Shim(); StatusText = "Initialized Client"; AppendLogger(StatusText); receiving = true; thread = new Thread(ThreadProc); thread.Start(); }
public GallioTestProvider() #endif { #if RESHARPER_60 Solution = solution; PsiModuleManager = psiModuleManager; CacheManager = cacheManager; #endif shim = new Shim(this); }
public GallioTestProvider() { shim = new Shim(this); }
public BindingListener(Shim shim) { this._shim = shim; }
public static Shim Create(CB comboBox, ComboBoxMode mode) { Shim shim = new Shim(); shim.Initialize(comboBox, (mode == ComboBoxMode.AsyncEager)); return shim; }
public static Shim Create(System.Windows.Controls.ComboBox comboBox, ComboBoxMode mode) { Shim shim = new Shim(); shim.Initialize(comboBox, (mode == ComboBoxMode.AsyncEager)); return shim; }