Example #1
0
        public void When_ToSubsciptionEntityIsCalledOnSubscribeRequest_Then_SubscriptionEntityIsReturned()
        {
            var subscribeRequest = new SubscribeRequest
            {
                AccessToken = "Token",
                Username    = "******"
            };

            var entity = subscribeRequest.ToSubscriptionEntity();

            // Assert
            Assert.AreEqual(subscribeRequest.Username, entity.Username);
            Assert.AreEqual(subscribeRequest.AccessToken, entity.AccessToken);
        }
Example #2
0
        public ActionResult Post([FromBody] SubscribeRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(new BadRequestResult());
            }

            var subscription = _notificationsService.Subscribe(request.ToSubscriptionEntity());

            if (subscription.CreationTime == DateTime.MinValue)
            {
                return(new JsonResult(new { status = "Failed", message = "Failed to add subscription" }));
            }

            return(new JsonResult(subscription.ToSubscribeResponse()));
        }