Exemple #1
0
        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();
        }
Exemple #2
0
        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);
        }
Exemple #3
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);
        }
Exemple #4
0
        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();
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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>());
        }
Exemple #7
0
        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;
 }
Exemple #9
0
        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;
 }