public void SetDirectionTest()
        {
            FakeInvokeDeviceMethod serviceClient = new FakeInvokeDeviceMethod();

            // define parameters
            string deviceId     = "mydevice";
            string direction    = GateDirection.In.ToString();
            string deviceMethod = "ReceiveCommandGateChange";

            SetGateDirectionAction action = new SetGateDirectionAction(serviceClient, this.logger);

            var result = action.Run(deviceId, direction).Result;

            // Assert that serviceClient.invocations count is 1
            Assert.AreEqual(1, serviceClient.invocations.Count);

            cmdGateDirectionUpdate expectedResponse = new cmdGateDirectionUpdate()
            {
                Direction = GateDirection.In
            };

            // Assert that the method name details from the invocation is as expected
            StringAssert.AreEqualIgnoringCase(deviceMethod, serviceClient.invocations[0].method.MethodName);

            // get response to object
            cmdGateDirectionUpdate actualResponse = JsonConvert.DeserializeObject <cmdGateDirectionUpdate>(serviceClient.invocations[0].method.GetPayloadAsJson());

            // check the expected against the actuals
            Assert.AreEqual(deviceId, serviceClient.invocations[0].device, "Device IDs did not match");
            Assert.AreEqual(expectedResponse.Direction, actualResponse.Direction, "Direction did not match");
        }
Exemple #2
0
        public void PurchaseTicketTest()
        {
            // sample payload to test
            PurchaseTicketRequest sampleRequest = new PurchaseTicketRequest()
            {
                DeviceId      = "rjTest",
                DeviceType    = DeviceType.TicketKiosk,
                TransactionId = "c3d8b13c - 3e8f - 4e57 - a7d5 - ae8adaa8c2b2",
                CreateTime    = System.DateTime.UtcNow,
                Price         = 54,
                MethodName    = "ReceivePurchaseTicketResponse"
            };
            string sampleRequestString = JsonConvert.SerializeObject(sampleRequest);

            // expected response
            PurchaseTicketPayload expectedResponse = new PurchaseTicketPayload()
            {
                DeviceId      = sampleRequest.DeviceId,
                TransactionId = sampleRequest.TransactionId,
                DeviceType    = sampleRequest.DeviceType,
                MessageType   = MessageType.cmdPurchaseTicket,
                IsApproved    = true
            };
            string expectedResponseString = JsonConvert.SerializeObject(expectedResponse);


            FakeInvokeDeviceMethod serviceClient = new FakeInvokeDeviceMethod();
            PurchaseTicketAction   action        = new PurchaseTicketAction(serviceClient, 0, sampleRequestString, logger);

            action.Run();
            // Assert that serviceClient.invocations count is 1
            Assert.That(Equals(serviceClient.invocations.Count, 1));
            // Assert that the device id from the invocation is as expected
            Assert.That(string.Equals(serviceClient.invocations[0].device, "rjTest"));
            // Assert that the method name details from the invocation is as expected
            StringAssert.AreEqualIgnoringCase(sampleRequest.MethodName, serviceClient.invocations[0].method.MethodName);

            // get response to object
            PurchaseTicketPayload actualResponse = JsonConvert.DeserializeObject <PurchaseTicketPayload>(serviceClient.invocations[0].method.GetPayloadAsJson());

            // check the expected against the actuals
            Assert.AreEqual(expectedResponse.DeviceId, actualResponse.DeviceId, "Device IDs do not match");
            Assert.AreEqual(expectedResponse.DeviceType, actualResponse.DeviceType, "Device Types do not match");
            Assert.AreEqual(expectedResponse.TransactionId, actualResponse.TransactionId, "Transaction IDs do not match");
            Assert.AreEqual(expectedResponse.MessageType, actualResponse.MessageType, "Message Types do not match");
            Assert.IsTrue(actualResponse.IsApproved, "Expected Ticket to be approved, but it was rejected");
        }
        public void TicketValidationTest()
        {
            // sample payload to test
            ValidateTicketRequest testRequest = new ValidateTicketRequest()
            {
                DeviceId      = "testID",
                DeviceType    = DeviceType.GateReader,
                TransactionId = "fakeTransactionId",
                CreateTime    = System.DateTime.UtcNow,
                MethodName    = "ReceiveTicketValidationResponse"
            };
            string requestPayload = JsonConvert.SerializeObject(testRequest);

            TestContext.WriteLine(string.Empty);
            TestContext.WriteLine(">> Testing the ticket validation method invocation.");

            FakeInvokeDeviceMethod serviceClient = new FakeInvokeDeviceMethod();
            ValidateTicketAction   action        = new ValidateTicketAction(serviceClient, requestPayload, logger);

            action.Run();

            // Assert that serviceClient.invocations count is 1
            Assert.That(Equals(1, serviceClient.invocations.Count));

            TestContext.WriteLine(string.Empty);
            TestContext.WriteLine(">> Testing the ticket validation method response.");

            // get the result and deserialize is back into our response object
            ValidateTicketResponse actualResponse = JsonConvert.DeserializeObject <ValidateTicketResponse>(serviceClient.invocations[0].method.GetPayloadAsJson());

            // Assert that various response values against expected
            Assert.AreEqual(testRequest.DeviceId, actualResponse.DeviceId, "Device IDs do not match");
            Assert.AreEqual(testRequest.DeviceType, actualResponse.DeviceType, "Device Types do not match");
            Assert.AreEqual(testRequest.MessageType, actualResponse.MessageType, "Message Types do not match");
            Assert.AreEqual(testRequest.TransactionId, actualResponse.TransactionId, "Trahsaction IDs do not match");
            Assert.AreEqual(testRequest.DeviceId, actualResponse.DeviceId, "Device IDs do not match");
            Assert.IsTrue((actualResponse.IsApproved == true || actualResponse.IsApproved == false), "IsApproved need not match range of allowed values, must be true or false");
            // Assert that the return MethodName is also correct
            Assert.AreEqual(testRequest.MethodName, serviceClient.invocations[0].method.MethodName);
        }