Ejemplo n.º 1
0
 public CoverageDataContext(Guid resourceID, EmitionTypes emissionType, string originalWebServerUrl)
 {
     IsMultipleWorkflowReport = resourceID == Guid.Empty;
     ResourceID            = resourceID;
     ReturnType            = emissionType;
     _originalWebServerUrl = originalWebServerUrl;
 }
Ejemplo n.º 2
0
            private static IResponseWriter Throw(EmitionTypes emitionTypes, HttpStatusCode statusCode, string title, string message)
            {
                Dev2Logger.Warn(message, GlobalConstants.WarewolfWarn);
                var response = Extensions.CreateWarewolfErrorResponse(emitionTypes, statusCode, title, message);

                throw new HttpResponseException(response);
            }
Ejemplo n.º 3
0
        public static string CreateErrorResponse(EmitionTypes emissionType, HttpStatusCode statusCode, string title, string message)
        {
            switch (emissionType)
            {
            case EmitionTypes.XML:
            case EmitionTypes.TRX:
                return(new Error
                {
                    Status = (int)statusCode,
                    Title = title,
                    Message = message
                }.ToXML());

            default:
            case EmitionTypes.JSON:
            case EmitionTypes.OPENAPI:
            case EmitionTypes.TEST:
            case EmitionTypes.Cover:
            case EmitionTypes.CoverJson:
                return(new Error
                {
                    Status = (int)statusCode,
                    Title = title,
                    Message = message
                }.ToJSON());
            }
        }
Ejemplo n.º 4
0
        private static bool IsRunAllTestsRequest(EmitionTypes returnType, string serviceName)
        {
            var isRunAllTests = !string.IsNullOrEmpty(serviceName);

            isRunAllTests &= serviceName == "*" || serviceName == ".tests" || serviceName == ".tests.trx";
            isRunAllTests &= returnType == EmitionTypes.TEST || returnType == EmitionTypes.TRX;
            return(isRunAllTests);
        }
Ejemplo n.º 5
0
        public static HttpResponseMessage CreateWarewolfErrorResponse(EmitionTypes emitionType, HttpStatusCode statusCode, string tittle, string message)
        {
            var calculatedMessage = ExecuteExceptionPayload.CreateErrorResponse(emitionType, statusCode, tittle, message);
            var content           = emitionType.GetHttpStringContent(calculatedMessage);

            return(new HttpResponseMessage(statusCode)
            {
                Content = content
            });
        }
Ejemplo n.º 6
0
        private static bool IsRunAllCoverageRequest(EmitionTypes returnType, string serviceName)
        {
            if (string.IsNullOrWhiteSpace(serviceName))
            {
                return(false);
            }
            var isRunAllCoverage = serviceName == "*" || serviceName == ".coverage" || serviceName == ".coverage.json";

            isRunAllCoverage |= serviceName.EndsWith("/.coverage");
            isRunAllCoverage &= returnType == EmitionTypes.Cover || returnType == EmitionTypes.CoverJson;
            return(isRunAllCoverage);
        }
Ejemplo n.º 7
0
            private IResponseWriter CreateEncryptedResponse(EmitionTypes emitionTypes, string payload)
            {
                var rs = new StringResponseWriterFactory();

                if (payload.Length > 0)
                {
                    var encryptedPayload = _jwtManager.GenerateToken(payload);
                    encryptedPayload = "{\"token\": \"" + encryptedPayload + "\"}";
                    return(rs.New(encryptedPayload, "application/json"));
                }

                return(Throw(emitionTypes, HttpStatusCode.InternalServerError, GlobalConstants.INTERNAL_SERVER_ERROR, "Token Genaration Failed"));
            }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the DatalistFormat instance that represents the given <paramref name="formatName" />, or creates a new one if a DatalistFormat instance
        /// does not exist for the given <paramref name="formatName" />.
        /// </summary>
        /// <param name="formatName">The display name of the datalist format.</param>
        /// <param name="publicFormatName">Name of the public format.</param>
        /// <param name="headerType">Type of the header.</param>
        /// <returns>
        /// An instance of the DatalistFormat type that is unique to the given <paramref name="formatName" />
        /// </returns>
        /// <exception cref="System.ArgumentException">formatName cannot be null or empty string.</exception>
        public static DataListFormat CreateFormat(string formatName, EmitionTypes publicFormatName = EmitionTypes.XML, string headerType = "")
        {
            if(String.IsNullOrEmpty(formatName)) throw new ArgumentException("formatName cannot be null or empty string.");
            DataListFormat format;

            lock(_formatLock)
            {
                if(!_existingFormats.TryGetValue(formatName, out format))
                {
                    format = new DataListFormat(formatName, publicFormatName, headerType);
                    _existingFormats.Add(formatName, format);
                }
            }

            return format;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the DatalistFormat instance that represents the given <paramref name="formatName" />, or creates a new one if a DatalistFormat instance
        /// does not exist for the given <paramref name="formatName" />.
        /// </summary>
        /// <param name="formatName">The display name of the datalist format.</param>
        /// <param name="publicFormatName">Name of the public format.</param>
        /// <param name="headerType">Type of the header.</param>
        /// <returns>
        /// An instance of the DatalistFormat type that is unique to the given <paramref name="formatName" />
        /// </returns>
        /// <exception cref="System.ArgumentException">formatName cannot be null or empty string.</exception>
        public static DataListFormat CreateFormat(string formatName, EmitionTypes publicFormatName = EmitionTypes.XML, string headerType = "")
        {
            if (String.IsNullOrEmpty(formatName))
            {
                throw new ArgumentException("formatName cannot be null or empty string.");
            }
            DataListFormat format;

            lock (_formatLock)
            {
                if (!_existingFormats.TryGetValue(formatName, out format))
                {
                    format = new DataListFormat(formatName, publicFormatName, headerType);
                    _existingFormats.Add(formatName, format);
                }
            }

            return(format);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets the DatalistFormat instance that represents the given <paramref name="formatName" />, or creates a new one if a DatalistFormat instance
        /// does not exist for the given <paramref name="formatName" />.
        /// </summary>
        /// <param name="formatName">The display name of the datalist format.</param>
        /// <param name="publicFormatName">Name of the public format.</param>
        /// <param name="headerType">Type of the header.</param>
        /// <returns>
        /// An instance of the DatalistFormat type that is unique to the given <paramref name="formatName" />
        /// </returns>
        /// <exception cref="System.ArgumentException">formatName cannot be null or empty string.</exception>
        public static DataListFormat CreateFormat(string formatName, EmitionTypes publicFormatName = EmitionTypes.XML, string headerType = "")
        {
            if (String.IsNullOrEmpty(formatName))
            {
                throw new ArgumentException(ErrorResource.FormatNameCannotBeNull);
            }
            DataListFormat format;

            lock (FormatLock)
            {
                if (!ExistingFormats.TryGetValue(formatName, out format))
                {
                    format = new DataListFormat(formatName, publicFormatName, headerType);
                    ExistingFormats.Add(formatName, format);
                }
            }

            return(format);
        }
Ejemplo n.º 11
0
 static bool IsRunAllTestsRequest(EmitionTypes returnType, string serviceName) => !string.IsNullOrEmpty(serviceName) && (serviceName == "*" || serviceName == ".tests" || serviceName == ".tests.trx") && (returnType == EmitionTypes.TEST || returnType == EmitionTypes.TRX);
Ejemplo n.º 12
0
 DataListFormat(string formatName, EmitionTypes publicType, string headerType)
 {
     _formatName      = formatName;
     PublicFormatName = publicType;
     ContentType      = headerType;
 }
        static void Verify_OnAuthorization_Response(bool isAuthenticated, string actionName, bool isAuthorized, HttpStatusCode expectedStatusCode, string title, string expectedMessage, EmitionTypes emitionTypes = EmitionTypes.JSON)
        {
            //------------Setup for test--------------------------
            var authorizationProvider = new Mock <IAuthorizationService>();

            authorizationProvider.Setup(p => p.IsAuthorized(It.IsAny <IAuthorizationRequest>())).Returns(isAuthorized);

            var attribute     = new AuthorizeWebAttribute(authorizationProvider.Object);
            var actionContext = CreateActionContext(isAuthenticated, actionName);

            //------------Execute Test---------------------------
            attribute.OnAuthorization(actionContext);

            //------------Assert Results-------------------------
            if (isAuthorized && isAuthenticated)
            {
                Assert.IsNull(actionContext.Response);
            }
            else
            {
                Assert.AreEqual(expectedStatusCode, actionContext.Response.StatusCode);

                var errorObject = new Error
                {
                    Status  = (int)expectedStatusCode,
                    Title   = title,
                    Message = expectedMessage
                };
                var actualResponse = actionContext.Response.Content.ReadAsStringAsync().Result;
                if (emitionTypes.Equals(EmitionTypes.XML))
                {
                    Assert.AreEqual(errorObject.ToXML(), actualResponse);
                }
                Assert.AreEqual(errorObject.ToJSON(), actualResponse);
            }
        }
Ejemplo n.º 14
0
 private DataListFormat(string formatName, EmitionTypes publicType, string headerType)
 {
     _formatName = formatName;
     PublicFormatName = publicType;
     ContentType = headerType;
 }
Ejemplo n.º 15
0
 public static StringContent GetHttpStringContent(this EmitionTypes emitionType, string message)
 {
     return(emitionType == EmitionTypes.XML || emitionType == EmitionTypes.TRX
                   ? new StringContent(message, System.Text.Encoding.UTF8, "application/xml")
                   : new StringContent(message, System.Text.Encoding.UTF8, "application/json"));
 }
Ejemplo n.º 16
0
 public CoverageDataContext(Guid resourceID, EmitionTypes emissionType, string originalWebServerUrl, string reportName)
     : this(resourceID, emissionType, originalWebServerUrl)
 {
     ReportName = reportName;
 }