Пример #1
0
        public async Task SearchSymbolTest()
        {
            _apiKeyServiceMock.Setup(q => q.GetKey()).Returns(_realKeySrvice.GetKey());
            var result = await _alphaVantageServiceReal.SearchSymbolAsync("BabA");

            Assert.True(result?.Any() == true);
            Assert.True(result?.Any(q => q.Symbol.Equals(_testSymbol)) == true);
        }
Пример #2
0
        /// <summary>
        /// Validate the app publish request values, and call publish services
        /// </summary>
        /// <param name="request">Values from Publish POST request</param>
        /// <returns>Http status code and content</returns>
        public HttpResponseContent ValidatePublish(ApplicationRequest request)
        {
            HttpResponseContent response; // Body of http response content

            Uri logoUrl = null;

            // Validate publish request values
            if (request.Title == null)
            {
                throw new InvalidStringException("Invalid Title: Null");
            }
            else if (!IsValidStringLength(request.Description, descriptionLength))
            {
                throw new InvalidStringException("Invalid Description: Length cannot be greater than " + descriptionLength + " characters.");
            }
            else if (!IsValidUrl(request.LogoUrl, ref logoUrl) || !IsValidStringLength(request.LogoUrl, urlLength))
            {
                throw new InvalidUrlException("Invalid Logo Url Format");
            }
            else if (!IsValidImageExtension(logoUrl, imageType))
            {
                throw new InvalidImageException("Invalid Logo Image Extension: Can only be " + imageType);
            }
            else if (!IsValidDimensions(logoUrl, xDimension, yDimension))
            {
                throw new InvalidImageException("Invalid Logo Dimensions: Can be no more than " + xDimension + "x" + yDimension + " pixels.");
            }

            // Attempt to find api key
            var apiKey = _apiKeyService.GetKey(request.Key);

            // Key does not exist
            if (apiKey == null)
            {
                throw new InvalidApiKeyException("Invalid API Key: Key Not Found");
            }
            // Key is found, but used
            else if (apiKey.IsUsed)
            {
                throw new InvalidApiKeyException("Invalid API Key: Key Has Already Been Used");
            }

            // Attempt to find application that api key belongs to
            var app = _applicationService.GetApplication(apiKey.ApplicationId);

            // App does not exist, or does not match the api key
            if (app == null || app.Title != request.Title)
            {
                throw new InvalidApiKeyException("Invalid API Key: Key and Application Do Not Match");
            }

            // Update values of application
            app.Description      = request.Description;
            app.LogoUrl          = request.LogoUrl;
            app.UnderMaintenance = request.UnderMaintenance;

            // Iterate through applications's api keys
            for (int i = 0; i < app.ApiKeys.Count; i++)
            {
                // Found api key belongs to application's collection of api keys
                if (app.ApiKeys.ElementAt(i).Id.Equals(apiKey.Id))
                {
                    // Invalidate api key
                    app.ApiKeys.ElementAt(i).IsUsed = true;

                    // Update values of application record
                    var appResponse = _applicationService.UpdateApplication(app);
                    // Application was not found
                    if (appResponse == null)
                    {
                        throw new ArgumentException("Application Could Not Be Updated");
                    }

                    // Save data store changes
                    SaveChanges(appResponse);

                    string message;

                    // Email successful publish confirmation
                    try
                    {
                        SendAppPublishEmail(app.Email, app);
                        message = "Successful Publish to the KFC SSO portal!  An email has been sent confirming your publish.";
                    }
                    catch
                    {
                        message = "Successful Publish to the KFC SSO portal!  A confirmation email was unable to send.";
                    }

                    // Return successful publish response
                    response = new HttpResponseContent(message);
                    return(response);
                }
            }

            // Key does not exist
            throw new InvalidApiKeyException("Invalid API Key: Key Not Found");
        }