예제 #1
0
        public async Task Code_Call_Method_That_Posts_Invalid_Type_To_Code()
        {
            // arrange
            IFiberLoop fiber     = new Fiber(new FrameFactory(new WaitFactory()));
            var        methodOne = MockMethod();
            var        methodTwo = MockMethod();
            var        value1    = 42;
            var        value2    = "hello world";
            var        value3    = Guid.NewGuid();

            methodOne
            .Setup(m => m.CodeAsync(fiber, It.Is(Item(value1))))
            .Returns(async() => { return(fiber.Call <string, Guid>(methodTwo.Object.CodeAsync, value2, methodOne.Object.CodeAsync)); });
            methodTwo
            .Setup(m => m.CodeAsync(fiber, It.Is(Item(value2))))
            .Returns(async() => { return(fiber.Done("not a guid")); });
            methodOne
            .Setup(m => m.CodeAsync(fiber, It.Is(ExceptionOfType <Guid, InvalidTypeException>())))
            .ReturnsAsync(NullWait.Instance);

            // act
            fiber.Call(methodOne.Object.CodeAsync, value1);
            await PollAsync(fiber);

            // assert
            methodOne.VerifyAll();
        }
예제 #2
0
        public async Task Code_Call_Method_With_Return()
        {
            // arrange
            IFiberLoop fiber     = new Fiber(new FrameFactory(new WaitFactory()));
            var        methodOne = MockMethod();
            var        methodTwo = MockMethod();
            var        value1    = 42;
            var        value2    = "hello world";
            var        value3    = Guid.NewGuid();

            methodOne
            .Setup(m => m.CodeAsync(fiber, It.Is(Item(value1))))
            .Returns(async() => { return(fiber.Call <string, Guid>(methodTwo.Object.CodeAsync, value2, methodOne.Object.CodeAsync)); });
            methodTwo
            .Setup(m => m.CodeAsync(fiber, It.Is(Item(value2))))
            .Returns(async() => { return(fiber.Done(value3)); });
            methodOne
            .Setup(m => m.CodeAsync(fiber, It.Is(Item(value3))))
            .ReturnsAsync(NullWait.Instance);

            // act
            fiber.Call(methodOne.Object.CodeAsync, value1);
            await PollAsync(fiber);

            // assert
            methodOne.VerifyAll();
        }
예제 #3
0
        public static async Task <DialogContext> MakeContextAsync(IDialog root, IBotToUser botToUser)
        {
            var        data    = new JObjectBotData(new Connector.Message());
            IFiberLoop fiber   = new Fiber(new FrameFactory(new WaitFactory()));
            var        context = new DialogContext(botToUser, data, fiber);
            var        loop    = Methods.Void(Methods.Loop(context.ToRest(root.StartAsync), int.MaxValue));

            fiber.Call(loop, null);
            await fiber.PollAsync();

            return(context);
        }
예제 #4
0
        public async Task Code_Call_Code()
        {
            // arrange
            IFiberLoop fiber    = new Fiber(new FrameFactory(new WaitFactory()));
            var        method   = MockMethod();
            var        valueOne = 42;
            var        valueTwo = "hello world";

            method
            .Setup(m => m.CodeAsync(fiber, It.Is(Item(valueOne))))
            .Returns(async() => { return(fiber.Call(method.Object.CodeAsync, valueTwo)); });
            method
            .Setup(m => m.CodeAsync(fiber, It.Is(Item(valueTwo))))
            .ReturnsAsync(NullWait.Instance);

            // act
            fiber.Call(method.Object.CodeAsync, valueOne);
            await PollAsync(fiber);

            // assert
            method.VerifyAll();
        }
예제 #5
0
        public async Task Fiber_OneCall_ThenDone_Throws()
        {
            // arrange
            IFiberLoop fiber  = new Fiber(new FrameFactory(new WaitFactory()));
            var        method = MockMethod();

            method
            .Setup(m => m.CodeAsync(fiber, It.IsAny <IAwaitable <int> >()))
            .Returns(async() => { return(fiber.Done(42)); });

            // act
            fiber.Call(method.Object.CodeAsync, 42);
            await PollAsync(fiber);

            // assert
            method.VerifyAll();
        }
예제 #6
0
        public async Task Fiber_With_Wait_Is_Serializable()
        {
            // arrange
            IFiberLoop fiber  = new Fiber(new FrameFactory(new WaitFactory()));
            IMethod    method = new SerializableMethod();

            // act
            var value = 42;

            fiber.Call(method.CodeAsync, value);

            // assert
            AssertSerializable(ref fiber);
            var next = await fiber.PollAsync();

            Assert.AreEqual(Need.Done, next.Need);
        }
예제 #7
0
        public async Task Poll_Is_Not_Reentrant()
        {
            // arrange
            IFiberLoop fiber  = new Fiber(new FrameFactory(new WaitFactory()));
            var        method = MockMethod();
            var        value  = 42;

            method
            .Setup(m => m.CodeAsync(fiber, It.Is(Item(value))))
            .Returns(async() => { await fiber.PollAsync(); return(null); });

            // act
            fiber.Call(method.Object.CodeAsync, value);
            await PollAsync(fiber);

            // assert
            method.VerifyAll();
        }
예제 #8
0
        public async Task Code_Throws_To_User()
        {
            // arrange
            IFiberLoop fiber  = new Fiber(new FrameFactory(new WaitFactory()));
            var        method = MockMethod();
            var        value  = 42;

            method
            .Setup(m => m.CodeAsync(fiber, It.Is(Item(value))))
            .Returns(async() => { throw new CodeException(); });

            // act
            fiber.Call(method.Object.CodeAsync, value);
            await PollAsync(fiber);

            // assert
            method.VerifyAll();
        }
예제 #9
0
        public async Task Code_Is_Called()
        {
            // arrange
            IFiberLoop fiber  = new Fiber(new FrameFactory(new WaitFactory()));
            var        method = MockMethod();
            var        value  = 42;

            method
            .Setup(m => m.CodeAsync(fiber, It.Is(Item(value))))
            .ReturnsAsync(NullWait.Instance);

            // act
            fiber.Call(method.Object.CodeAsync, value);
            await PollAsync(fiber);

            // assert
            method.VerifyAll();
        }
예제 #10
0
        public async Task Code_Item_Variance()
        {
            // arrange
            IFiberLoop fiber         = new Fiber(new FrameFactory(new WaitFactory()));
            var        method        = MockMethod();
            string     valueAsString = "hello world";
            object     valueAsObject = valueAsString;

            method
            .Setup(m => m.CodeAsync(fiber, It.Is(Item(valueAsObject))))
            .ReturnsAsync(NullWait.Instance);

            // act
            fiber.Call(method.Object.CodeAsync, valueAsString);
            await PollAsync(fiber);

            // assert
            method.VerifyAll();
        }
예제 #11
0
        public async Task Method_Void()
        {
            // arrange
            IFiberLoop fiber  = new Fiber(new FrameFactory(new WaitFactory()));
            var        method = MockMethod();
            var        value  = "hello world";

            method
            .Setup(m => m.CodeAsync(fiber, It.Is(Item(value))))
            .Returns(async() => fiber.Done(42));

            // act
            var loop = Methods.Void <string>(method.Object.CodeAsync);

            fiber.Call(loop, value);
            await PollAsync(fiber);

            // assert
            method.Verify(m => m.CodeAsync(fiber, It.Is(Item(value))), Times.Exactly(1));
        }
예제 #12
0
        public async Task Fiber_OneCall_NeedDone()
        {
            // arrange
            IFiberLoop fiber  = new Fiber(new FrameFactory(new WaitFactory()));
            var        method = MockMethod();
            var        value  = 42;

            method
            .Setup(m => m.CodeAsync(fiber, It.Is(Item(value))))
            .ReturnsAsync(NullWait.Instance);

            // act
            fiber.Call(method.Object.CodeAsync, value);

            // assert
            var next = await fiber.PollAsync();

            Assert.AreEqual(Need.Done, next.Need);
            method.VerifyAll();
        }