public void GetTrusonaficationResult_of_an_accepted_trusonafication_should_include_the_bound_identifier()
        {
            //given
            var userIdentifier   = "TacoMan3000";
            var deviceIdentifier = buster.CreateDevice()["id"];
            var binding          = sut.CreateUserDevice(userIdentifier, deviceIdentifier).Result;

            sut.ActivateUserDevice(binding.ActivationCode).Wait();

            //given
            var trusonafication = Trusonafication.Essential()
                                  .DeviceIdentifier(deviceIdentifier)
                                  .Action("sit")
                                  .Resource("your lap")
                                  .Build();

            var trusonaficationId = sut.CreateTrusonafication(trusonafication).Result.Id;

            buster.AcceptTrusonafication(deviceIdentifier, trusonaficationId.ToString());

            //when
            var res = sut.GetTrusonaficationResult(trusonaficationId).Result;

            res.Status.Should()
            .Be(TrusonaficationStatus.ACCEPTED);
            res.BoundUserIdentifier.Should()
            .Be(userIdentifier);
        }
Example #2
0
        public void Callback_url_should_get_called_when_trusonafication_is_accepted()
        {
            //given
            var userIdentifier   = "TacoMan3000";
            var deviceIdentifier = buster.CreateDevice()["id"];
            var binding          = sut.CreateUserDevice(userIdentifier, deviceIdentifier).Result;

            sut.ActivateUserDevice(binding.ActivationCode).Wait();

            var callbackId = Guid.NewGuid().ToString();

            //given
            var trusonafication = Trusonafication.Essential()
                                  .DeviceIdentifier(deviceIdentifier)
                                  .Action("eat")
                                  .Resource("your taco")
                                  .CallbackUrl(buster.GetCallbackUrl(callbackId))
                                  .Build();

            var trusonaficationId = sut.CreateTrusonafication(trusonafication).Result.Id;

            //when
            buster.AcceptTrusonafication(deviceIdentifier, trusonaficationId.ToString());

            //then
            AssertEventuallyTrue(10000, () => buster.GetCallback(callbackId).Count > 0);
        }
Example #3
0
        public void CreateTrusonafication_should_handle_exceptions()
        {
            //given
            var trusonafication = Trusonafication.Essential()
                                  .DeviceIdentifier("blah")
                                  .Action("sit")
                                  .Resource("your lap")
                                  .Build();

            SetupMock(string.Empty, HttpStatusCode.BadRequest);

            //when
            Action action = () => { var res = sut.CreateTrusonafication(trusonafication).Result; };

            //then
            action.Should()
            .Throw <TrusonaException>();
        }
Example #4
0
        public void CreateTrusonafication_should_return_a_result_when_successful()
        {
            //given
            var trusonafication = Trusonafication.Essential()
                                  .DeviceIdentifier("blah")
                                  .Action("sit")
                                  .Resource("your lap")
                                  .Build();

            SetupMock(@"{
        ""id"": ""96ea5830-8e5e-42c5-9cbb-8a941d2ff7f9"",
        ""status"": ""ACCEPTED""
      }");

            //when
            var res = sut.CreateTrusonafication(trusonafication).Result;

            //then
            res.Id.Should()
            .Be(Guid.Parse("96ea5830-8e5e-42c5-9cbb-8a941d2ff7f9"));
            res.Status.Should()
            .Be(TrusonaficationStatus.ACCEPTED);
        }
        public void CreateTrusonafication_should_create_trusonafications_by_device_identifier()
        {
            //given
            var deviceIdentifier = buster.CreateDevice()["id"];
            var binding          = sut.CreateUserDevice("beefstew", deviceIdentifier).Result;

            sut.ActivateUserDevice(binding.ActivationCode).Wait();

            var trusonafication = Trusonafication.Essential()
                                  .DeviceIdentifier(deviceIdentifier)
                                  .Action("sit")
                                  .Resource("your lap")
                                  .ExpiresAt(DateTime.Now.AddSeconds(10))
                                  .Build();

            //when
            var res = sut.CreateTrusonafication(trusonafication).Result;

            //then
            res.Status
            .Should()
            .Be(TrusonaficationStatus.IN_PROGRESS);
        }
        public void GetTrusonaficationResult_should_return_a_valid_response()
        {
            var deviceIdentifier = buster.CreateDevice()["id"];
            var binding          = sut.CreateUserDevice("TacoMan3000", deviceIdentifier).Result;

            sut.ActivateUserDevice(binding.ActivationCode).Wait();

            //given
            var trusonafication = Trusonafication.Essential()
                                  .DeviceIdentifier(deviceIdentifier)
                                  .Action("sit")
                                  .Resource("your lap")
                                  .ExpiresAt(DateTime.Now.AddSeconds(1))
                                  .Build();

            var trusonaficationId = sut.CreateTrusonafication(trusonafication).Result.Id;

            //when
            var res = sut.GetTrusonaficationResult(trusonaficationId).Result;

            res.Status
            .Should()
            .Be(TrusonaficationStatus.EXPIRED);
        }
        /// <summary>
        /// Creates a Trusonafication and returns a TrusonaficationResult with the current status of the Trusonafication.
        /// See TrusonaficationStatus for the possible statuses.
        /// </summary>
        /// <returns>A TrusonaficationResult describing the current status of the Trusonafication.</returns>
        /// <param name="trusona">Trusona API.</param>
        /// <param name="trusonafication">A Trusonafication.</param>
        public static async Task <TrusonaficationResult> CreateTrusonafication(this Trusona trusona, Trusonafication trusonafication)
        {
            try
            {
                var response = await trusona.TrusonaficationService.CreateTrusonaficationAsync(
                    trusona.mapper.Map <TrusonaficationRequest>(trusonafication));

                var result = trusona.mapper.Map <TrusonaficationResult>(response);
                return(result);
            }
            catch (TrusonaServiceException ex)
            {
                if (ex.HttpResponse.StatusCode.Equals(422))
                {
                    // TODO: Additional logic here?
                }
                HandleServiceException(ex, DefaultErrorHandler);
                throw ex;
            }
        }