Exemplo n.º 1
0
        public IActionResult Get(string apiToken)
        {
            try
            {
                if (!Guid.TryParse(apiToken, out Guid apiTokenGuid))
                {
                    string msg = $"Could not parse API token passed in into a GUID.  API token: {apiToken}";
                    _logger.Error(msg);
                    return(StatusCode((int)HttpStatusCode.BadRequest, msg));
                }

                var result = _webPageHelper.GetUserInfo(apiTokenGuid);

                if (result == null)
                {
                    return(NotFound());
                }

                return(Ok(result));
            }
            catch (Exception ex)
            {
                _logger.Error($"Unhandled exception occurred when attempting to get user data", ex);
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
        public void GetUserInfo_VerifyReturnObject()
        {
            var           apiToken      = new Guid("a84165c4-d33c-44d0-9478-1651b16b361b");
            const int     callsPerMonth = 100;
            const bool    canCallApi    = true;
            const string  email         = "email";
            const string  firstName     = "firstName";
            const string  lastName      = "lastName";
            const decimal pricePerMonth = 100;
            const int     userId        = 25;

            //arrange
            _userManager.Setup(x => x.GetUserByApiToken(apiToken)).Returns(new User
            {
                ApiToken      = apiToken,
                CallsPerMonth = callsPerMonth,
                CanCallApi    = canCallApi,
                Email         = email,
                FirstName     = firstName,
                LastName      = lastName,
                PricePerMonth = pricePerMonth,
                UserId        = userId
            });

            _accountTypeHelper.Setup(x => x.GetAccountTypeBasedOnPricing(pricePerMonth, callsPerMonth)).Returns("Custom");

            //act
            var model = _webPageHelper.GetUserInfo(apiToken);

            //assert
            AssertWithMessage.AreEqual(model.AccountLocked, !canCallApi, nameof(model.AccountLocked));
            AssertWithMessage.AreEqual(model.AccountType, "Custom", nameof(model.AccountType));
            AssertWithMessage.AreEqual(model.ApiToken, apiToken, nameof(model.ApiToken));
            AssertWithMessage.AreEqual(model.Email, email, nameof(model.Email));
            AssertWithMessage.AreEqual(model.FirstName, firstName, nameof(model.FirstName));
            AssertWithMessage.AreEqual(model.LastName, lastName, nameof(model.LastName));
            AssertWithMessage.AreEqual(model.CallsPerMonth, callsPerMonth, nameof(model.CallsPerMonth));
            AssertWithMessage.AreEqual(model.PricePerMonth, pricePerMonth, nameof(model.PricePerMonth));
        }