public async void DoWork_ShouldFailRequest_When_TimeoutPolicyReturnsFailure()
        {
            DeviceInformation deviceInformation = new DeviceInformation()
            {
                Manufacturer = "DeviceMockerInc",
                Model        = "DeviceMokerModel",
                SerialNumber = "CEEEDEADBEEF"
            };
            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);

            var timeoutPolicy = PollyPolicyResultGenerator.GetFailurePolicy <bool>(new Exception("Request timed out"));

            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.DALAction;
            subject.SetState(linkRequest);

            await subject.DoWork();

            Assert.True(asyncManager.WaitFor());

            //mockLoggingClient.Verify(e => e.LogErrorAsync(It.IsAny<string>(), It.IsAny<Dictionary<string, object>>()), Times.Once());
            mockSubController.Verify(e => e.Complete(subject), Times.Once());
        }
        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);
        }
예제 #3
0
        public async void DoWork_ShouldFailRequest_When_RequestTimeoutIsTriggered()
        {
            var timeoutPolicy = PollyPolicyResultGenerator.GetFailurePolicy <LinkRequest>(new Exception("Request timed out"));

            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());

            //mockLoggingClient.Verify(e => e.LogErrorAsync(It.IsAny<string>(), It.IsAny<Dictionary<string, object>>()), Times.Once());

            //Assert.NotNull(linkRequest.Actions[0].DeviceRequest.LinkObjects);
            //Assert.Equal(Enum.GetName(typeof(EventCodeType), EventCodeType.REQUEST_TIMEOUT),
            //    linkRequest.Actions[0].DeviceRequest.LinkObjects.DeviceResponseData.Errors[0].Code);

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

            //DeviceInformation actualValue = new DeviceInformation()
            //{
            //    Manufacturer = linkRequest.LinkObjects.LinkActionResponseList[0].DeviceResponse.Devices[0].Manufacturer,
            //    Model = linkRequest.LinkObjects.LinkActionResponseList[0].DeviceResponse.Devices[0].Model,
            //    SerialNumber = linkRequest.LinkObjects.LinkActionResponseList[0].DeviceResponse.Devices[0].SerialNumber
            //};
            //Assert.NotEqual(deviceInformation, actualValue);
        }
예제 #4
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);
        }
예제 #6
0
        public async void DoWork_ShouldForceCompletionWithCancelation__WhenTestingGetCardData(string exception, string userEvent, DeviceEvent deviceEvent)
        {
            LinkActionRequest linkActionRequest = linkRequest.Actions.First();

            linkActionRequest.Action        = LinkAction.Payment;
            linkActionRequest.DeviceRequest = new LinkDeviceRequest()
            {
                //LinkObjects = new LinkDeviceRequestIPA5Object()
                //{
                //    DeviceResponseData = new LinkDeviceActionResponse
                //    {
                //        Errors = new List<LinkErrorValue>
                //        {
                //            new LinkErrorValue
                //            {
                //                Code = exception,
                //                Description = "Canceled"
                //            }
                //        }
                //    }
                //}
            };
            string expectedValue = linkActionRequest.Action.ToString();

            Mock <ICardDevice> fakeDeviceThree = new Mock <ICardDevice>();

            fakeDeviceThree.Setup(e => e.ResetDevice(It.IsAny <LinkRequest>())).Returns(linkRequest);

            subject.SetState(linkRequest);

            var timeoutPolicy = PollyPolicyResultGenerator.GetFailurePolicy <LinkRequest>(new Exception(exception));

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

            await subject.DoWork();

            //mockLoggingClient.Verify(e => e.LogErrorAsync(string.Format("Unable to obtain Card Data from device - '{0}'.", userEvent),
            //    It.IsAny<Dictionary<string, object>>()), Times.Once());

            //Assert.NotNull(linkRequest.Actions[0].DeviceRequest.LinkObjects.DeviceResponseData.Errors);
            //Assert.Equal(exception, linkRequest.Actions[0].DeviceRequest.LinkObjects.DeviceResponseData.Errors[0].Code);
            //Assert.Equal(expectedValue, linkRequest.Actions[0].DeviceRequest.LinkObjects.DeviceResponseData.Errors[0].Type);

            //DeviceInformation actualValue = new DeviceInformation()
            //{
            //    Manufacturer = linkRequest.LinkObjects.LinkActionResponseList[0].DeviceResponse.Devices[0].Manufacturer,
            //    Model = linkRequest.LinkObjects.LinkActionResponseList[0].DeviceResponse.Devices[0].Model,
            //    SerialNumber = linkRequest.LinkObjects.LinkActionResponseList[0].DeviceResponse.Devices[0].SerialNumber
            //};
            //Assert.NotEqual(deviceInformation, actualValue);
        }
예제 #7
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());
        }
예제 #8
0
        public async void DoWork_ShouldFailWhenCardDeviceNotFound_WhenCalled()
        {
            var timeoutPolicy = PollyPolicyResultGenerator.GetFailurePolicy <LinkRequest>(new Exception("Request timed out"));

            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());

            //mockLoggingClient.Verify(e => e.LogErrorAsync(string.Format($"Unable to obtain device information from request - '{DeviceDiscovery.NoDeviceMatched}'."),
            //    It.IsAny<Dictionary<string, object>>()), Times.Once());
        }
        public async void DoWork_ShouldFailRequest_When_TimeoutPolicyReturnsFailureForMultipleDevices()
        {
            List <ICardDevice> cardDevices   = new List <ICardDevice>();
            Mock <ICardDevice> fakeDeviceOne = new Mock <ICardDevice>();
            Mock <ICardDevice> fakeDeviceTwo = new Mock <ICardDevice>();

            DeviceInformation deviceInformation = new DeviceInformation()
            {
                Manufacturer = "DeviceMocker",
                Model        = "DeviceMock",
                SerialNumber = "CEEDEADBEEF"
            };

            fakeDeviceOne.Setup(e => e.DeviceInformation).Returns(deviceInformation);
            fakeDeviceTwo.Setup(e => e.DeviceInformation).Returns(deviceInformation);

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

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

            var timeoutPolicy = PollyPolicyResultGenerator.GetFailurePolicy <LinkRequest>(new Exception("Request timed out"));

            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());

            //mockLoggingClient.Verify(e => e.LogErrorAsync(It.IsAny<string>(), It.IsAny<Dictionary<string, object>>()), Times.Exactly(2));

            //Assert.NotNull(linkRequest.Actions[0].DeviceRequest.LinkObjects);
            //Assert.Equal(Enum.GetName(typeof(EventCodeType), EventCodeType.REQUEST_TIMEOUT), linkRequest.Actions[0].DeviceRequest.LinkObjects.DeviceResponseData.Errors[0].Code);

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

            //DeviceInformation actualValue = new DeviceInformation()
            //{
            //    Manufacturer = linkRequest.LinkObjects.LinkActionResponseList[0].DeviceResponse.Devices[0].Manufacturer,
            //    Model = linkRequest.LinkObjects.LinkActionResponseList[0].DeviceResponse.Devices[0].Model,
            //    SerialNumber = linkRequest.LinkObjects.LinkActionResponseList[0].DeviceResponse.Devices[0].SerialNumber
            //};
            //Assert.NotEqual(deviceInformation, actualValue);
        }
        public async void DoWork_ShouldFailRequest_When_TimeoutPolicyReturnsFailure()
        {
            List <ICardDevice> iCardDevices = new List <ICardDevice>()
            {
                new Devices.Simulator.DeviceSimulator()
                {
                    SortOrder = 1
                }
            };

            mockDevicePluginLoader.Setup(e => e.FindAvailableDevices(pluginPath)).Returns(iCardDevices);

            DeviceInformation deviceInformation = new DeviceInformation()
            {
                Manufacturer = "DeviceMocker",
                Model        = "DeviceMock",
                SerialNumber = "CEEDEADBEEF"
            };

            fakeDeviceOne.Setup(e => e.DeviceInformation).Returns(deviceInformation);

            DeviceSection deviceSection = new DeviceSection();

            deviceSection.Simulator.SortOrder = 1;
            mockController.Setup(e => e.Configuration).Returns(deviceSection);

            var timeoutPolicy = PollyPolicyResultGenerator.GetFailurePolicy <List <LinkErrorValue> >(new Exception("Request timed out"));

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

            await subject.DoWork();

            Assert.True(asyncManager.WaitFor());

            //mockLoggingClient.Verify(e => e.LogErrorAsync(It.IsAny<string>(), It.IsAny<Dictionary<string, object>>()), Times.Once());

            mockController.Verify(e => e.Error(subject), Times.Once());
        }