public async void DoWork_ShouldDoWorkAndCompleteWithoutError_WithSaveState_WhenCalledWith_MultipleDevices()
        {
            var timeoutPolicy = PollyPolicyResultGenerator.GetSuccessfulPolicy <bool>();

            List <ICardDevice> cardDevices   = new List <ICardDevice>();
            Mock <ICardDevice> fakeDeviceOne = new Mock <ICardDevice>();
            Mock <ICardDevice> fakeDeviceTwo = new Mock <ICardDevice>();

            cardDevices.AddRange(new ICardDevice[] { fakeDeviceOne.Object, fakeDeviceTwo.Object });

            mockSubController.SetupGet(e => e.TargetDevices).Returns(cardDevices);

            mockDeviceCancellationBroker.Setup(e => e.ExecuteWithTimeoutAsync(It.IsAny <Func <CancellationToken, bool> >(),
                                                                              It.IsAny <int>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(timeoutPolicy));

            mockSubController.Setup(e => e.DidTimeoutOccur).Returns(true);
            subject.SetState(linkRequest);
            await subject.DoWork();

            Assert.True(asyncManager.WaitFor());

            //mockLoggingClient.Verify(e => e.LogErrorAsync("Unable to recover device.",
            //    It.IsAny<Dictionary<string, object>>()), Times.Never());

            mockSubController.Verify(e => e.SaveState(linkRequest), Times.Once());
            mockSubController.Verify(e => e.Complete(subject), Times.Once());
            //Assert.Null(linkRequest.LinkObjects.LinkActionResponseList[0].Errors);
        }
Example #2
0
        public async void DoWork_ShouldDoWorkAndComplete_When_StateObjectIsProvidedForMultipleDevices()
        {
            var timeoutPolicy = PollyPolicyResultGenerator.GetSuccessfulPolicy <LinkRequest>();

            List <ICardDevice> cardDevices       = new List <ICardDevice>();
            Mock <ICardDevice> fakeDeviceOne     = new Mock <ICardDevice>();
            Mock <ICardDevice> fakeDeviceTwo     = new Mock <ICardDevice>();
            DeviceInformation  deviceInformation = new DeviceInformation()
            {
                Manufacturer = linkRequest.Actions[0].DeviceRequest.DeviceIdentifier.Manufacturer,
                Model        = linkRequest.Actions[0].DeviceRequest.DeviceIdentifier.Model,
                SerialNumber = linkRequest.Actions[0].DeviceRequest.DeviceIdentifier.SerialNumber,
            };

            fakeDeviceOne.Setup(e => e.DeviceInformation).Returns(deviceInformation);
            cardDevices.AddRange(new ICardDevice[] { fakeDeviceOne.Object, fakeDeviceTwo.Object });

            mockSubController.SetupGet(e => e.TargetDevices).Returns(cardDevices);

            mockDeviceCancellationBroker.Setup(e => e.ExecuteWithTimeoutAsync(It.IsAny <Func <CancellationToken, LinkRequest> >(),
                                                                              It.IsAny <int>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(timeoutPolicy));

            await subject.DoWork();

            Assert.True(asyncManager.WaitFor());

            mockSubController.Verify(e => e.SaveState(linkRequest), Times.Once());
            mockSubController.Verify(e => e.Complete(subject), Times.Once());
        }
        public async void DoWork_ShouldForceCompletionWithCancelation__WhenTestingGetStautsAndUserCancels()
        {
            LinkActionRequest linkActionRequest = linkRequest.Actions.First();

            linkActionRequest.DeviceRequest = new LinkDeviceRequest()
            {
                //LinkObjects = new LinkDeviceRequestIPA5Object()
                //{
                //    DeviceResponseData = new LinkDeviceActionResponse
                //    {
                //        Errors = new List<LinkErrorValue>
                //        {
                //            new LinkErrorValue
                //            {
                //                Code = System.Enum.GetName(typeof(EventCodeType), EventCodeType.USER_CANCELED),
                //                Description = "Canceled"
                //            }
                //        }
                //    }
                //}
            };

            subject.SetState(linkRequest);

            var timeoutPolicy = PollyPolicyResultGenerator.GetSuccessfulPolicy <LinkRequest>();

            mockDeviceCancellationBroker.Setup(e => e.ExecuteWithTimeoutAsync(It.IsAny <Func <CancellationToken, LinkRequest> >(),
                                                                              It.IsAny <int>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(timeoutPolicy));

            await subject.DoWork();

            //Assert.NotNull(linkRequest.Actions[0].DeviceRequest.LinkObjects.DeviceResponseData.Errors);
            //Assert.Equal("USER_CANCELED", linkRequest.Actions[0].DeviceRequest.LinkObjects.DeviceResponseData.Errors[0].Code);
        }
Example #4
0
        public async void DoWork_ShouldDoWorkAndComplete_When_StateObjectIsProvided()
        {
            var timeoutPolicy = PollyPolicyResultGenerator.GetSuccessfulPolicy <LinkRequest>();

            mockDeviceCancellationBroker.Setup(e => e.ExecuteWithTimeoutAsync(It.IsAny <Func <CancellationToken, LinkRequest> >(),
                                                                              It.IsAny <int>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(timeoutPolicy));

            await subject.DoWork();

            Assert.True(asyncManager.WaitFor());

            mockSubController.Verify(e => e.SaveState(linkRequest), Times.Once());
            mockSubController.Verify(e => e.Complete(subject), Times.Once());
        }
        public async void DoWork_ShouldDoWorkAndCompleteWithoutError_WhenCalledWith_MultipleDevices()
        {
            DeviceInformation deviceInformation = new DeviceInformation()
            {
                Manufacturer = "DeviceMockerInc",
                Model        = "DeviceMokerModel",
                SerialNumber = "CEEEDEADBEEF"
            };

            var timeoutPolicy = PollyPolicyResultGenerator.GetSuccessfulPolicy <bool>();

            List <ICardDevice> cardDevices   = new List <ICardDevice>();
            Mock <ICardDevice> fakeDeviceOne = new Mock <ICardDevice>();
            Mock <ICardDevice> fakeDeviceTwo = new Mock <ICardDevice>();

            fakeDeviceTwo.Setup(e => e.DeviceInformation).Returns(deviceInformation);
            cardDevices.AddRange(new ICardDevice[] { fakeDeviceOne.Object, fakeDeviceTwo.Object });

            mockSubController.SetupGet(e => e.TargetDevices).Returns(cardDevices);

            mockDeviceCancellationBroker.Setup(e => e.ExecuteWithTimeoutAsync(It.IsAny <Func <CancellationToken, bool> >(),
                                                                              It.IsAny <int>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(timeoutPolicy));

            mockSubController.Setup(e => e.DidTimeoutOccur).Returns(true);

            linkRequest.Actions[0].Action = LinkAction.Payment;
            subject.SetState(linkRequest);
            await subject.DoWork();

            Assert.True(asyncManager.WaitFor());

            //mockLoggingClient.Verify(e => e.LogErrorAsync("Unable to recover device.",
            //    It.IsAny<Dictionary<string, object>>()), Times.Never());

            mockSubController.Verify(e => e.Complete(subject), Times.Once());
        }