public void ShouldInvokeTheSpecifiedMethod() { IFakeInterface instance = Substitute.For <IFakeInterface>(); RouteMethod result = this.adapter.CreateMethod( () => instance, typeof(IFakeInterface).GetMethod(nameof(IFakeInterface.SimpleMethod))); result(null); instance.Received().SimpleMethod(); }
public void ShouldPassInTheTypesDefaultValueForParametersMarkedAsOptional() { IFakeInterface instance = Substitute.For <IFakeInterface>(); RouteMethod result = this.adapter.CreateMethod( () => instance, typeof(IFakeInterface).GetMethod(nameof(IFakeInterface.NonDefaultedOptions))); result(new Dictionary <string, object>()); instance.Received().NonDefaultedOptions(0); }
public void ShouldPassInDefaultedValuesForOptionalParametersWithDefaults() { IFakeInterface instance = Substitute.For <IFakeInterface>(); RouteMethod result = this.adapter.CreateMethod( () => instance, typeof(IFakeInterface).GetMethod(nameof(IFakeInterface.OptionalParameter))); result(new Dictionary <string, object>()); instance.Received().OptionalParameter(321); }
public async Task ShouldReturnNoContentValueForTaskMethods() { IFakeInterface instance = Substitute.For <IFakeInterface>(); RouteMethod wrapper = this.adapter.CreateMethod( () => instance, typeof(IFakeInterface).GetMethod(nameof(IFakeInterface.TaskMethod))); object result = await wrapper(null); Assert.That(result, Is.SameAs(NoContent.Value)); await instance.Received().TaskMethod(); }
public void ShouldPassInTheCapturedValueForOptionalParameters() { IFakeInterface instance = Substitute.For <IFakeInterface>(); RouteMethod result = this.adapter.CreateMethod( () => instance, typeof(IFakeInterface).GetMethod(nameof(IFakeInterface.OptionalParameter))); result(new Dictionary <string, object> { { "optional", 123 } }); instance.Received().OptionalParameter(123); }
public void ShouldThrowExceptionsInsideTheConvertedTask() { IFakeInterface instance = Substitute.For <IFakeInterface>(); instance.TaskMethod().Returns(Task.FromException(new DivideByZeroException())); RouteMethod result = this.adapter.CreateMethod( () => instance, typeof(IFakeInterface).GetMethod(nameof(IFakeInterface.TaskMethod))); Exception ex = result(null).Exception.Flatten(); Assert.That(ex.InnerException, Is.InstanceOf <DivideByZeroException>()); }
public async Task ShouldConvertGenericTaskToTaskObject() { IFakeInterface instance = Substitute.For <IFakeInterface>(); instance.Int32Task().Returns(123); RouteMethod wrapper = this.adapter.CreateMethod( () => instance, typeof(IFakeInterface).GetMethod(nameof(IFakeInterface.Int32Task))); object result = await wrapper(null); Assert.That(result, Is.EqualTo(123)); }
public FakeController(IFakeInterface fakeInterface) { this.fakeInterface = fakeInterface; }
public Task <object> MyReturn() { IFakeInterface instance = null; return(instance.Int32Task().ContinueWith <object>(t => t.Result)); }
public FakeController(IDispatcher dispatcher, IFakeInterface fakeInterface) : base(dispatcher) { this.fakeInterface = fakeInterface; }