Exemple #1
0
        public void TestDashboardRegistrationByOtherHttpMethod(HttpMethod inputType)
        {
            var handler  = new DashboardManager(DashboardHelpers.DashboardRegistrationEndPoint);
            var response = handler.SendDashboard <object>(DashboardHelpers.DashboardRegistrationDefaultParameters(UserIds), inputType.ToNetHttpMethod());

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
        }
        public void TestValidSpecialDashboardRegistration(ValidSpecialDashboardRegistration inputType)
        {
            var handler         = new DashboardManager(DashboardHelpers.DashboardRegistrationEndPoint);
            var originalRequest = new Dictionary <string, object>(DashboardHelpers.DashboardRegistrationDefaultParameters(UserIds));
            var request         = originalRequest["settings"] as Dictionary <string, object>;

            if (inputType == ValidSpecialDashboardRegistration.AbstractAgents)
            {
                request["owners"] = new Dictionary <string, List <int> >
                {
                    ["agents"] = new List <int> {
                        -1
                    }
                };
            }
            else
            {
                request["owners"] = new Dictionary <string, List <int> >
                {
                    ["depts"] = new List <int> {
                        -1
                    }
                };
            }
            originalRequest["settings"] = request;

            var response = handler.SendDashboard <object>(originalRequest, HttpMethod.Put);

            PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.NoContent));
            PrAssert.That(response.Result, PrIs.Null.Or.Empty);

            //Verify owners data
            VerifyOwnersData(-1, -1);
        }
        private Dictionary <string, object> GetRequestDashboardRegistrationValid(DashboardHelpers.Options option, Owners owner, DashboardHelpers.SearchOwners searchOwner, DashboardHelpers.TimePeriod timePeriod, DashboardHelpers.Types type)
        {
            var originalRequest = new Dictionary <string, object>(DashboardHelpers.DashboardRegistrationDefaultParameters(UserIds));
            var request         = originalRequest["settings"] as Dictionary <string, object>;

            if (option == DashboardHelpers.Options.Array)
            {
                request["options"] = DashboardHelpers.OptionValues.Select(item => item.Value).ToList();
            }
            else
            if (option == DashboardHelpers.Options.Random)
            {
                request["options"] = RandOptionList;
            }
            else
            {
                request["options"] = new List <int> {
                    DashboardHelpers.OptionValues[option]
                };
            }

            request["owners"] = new Dictionary <string, List <int> >
            {
                ["agents"] = OwnerValues[owner](),
                ["depts"]  = new List <int>()
            };
            request["searchOwners"] = SearchOwnerValues[searchOwner]();
            request["timePeriod"]   = new Dictionary <string, string>
            {
                ["type"] = timePeriod.ToString()
            };
            originalRequest["type"]     = type.ToString().ToLower();
            originalRequest["settings"] = request;
            return(originalRequest);
        }
        public void TestDashboardRegistrationAccessEndpoint(AccessState accessState, HttpStatusCode httpStatusCode, ResultCode resultCode)
        {
            var handler = new DashboardManager();
            var request = new Dictionary <string, object>(DashboardHelpers.DashboardRegistrationDefaultParameters(UserIds));
            AccessEndpointManager accessEndpointHandler = new AccessEndpointManager();
            var response = accessEndpointHandler.AccessEndpoint <object>(accessState, DashboardRegistrationEndpoint, request, HttpMethod.Put);

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(httpStatusCode).And.ErrorCode((int)resultCode), $"Still able to send a dashboard.");
        }
Exemple #5
0
        public void TestInvalidSpecialDashboardRegistration(DashboardHelpers.InvalidSpecialDashboardRegistration inputType)
        {
            var handler         = new DashboardManager(DashboardHelpers.DashboardRegistrationEndPoint);
            var originalRequest = new Dictionary <string, object>(DashboardHelpers.DashboardRegistrationDefaultParameters(UserIds));
            var request         = RequestContentForInvalidSpecialDashboardRegistration[inputType](originalRequest["settings"] as Dictionary <string, object>);

            originalRequest["settings"] = request;
            var response = handler.SendDashboard <object>(originalRequest, System.Net.Http.HttpMethod.Put, inputType == DashboardHelpers.InvalidSpecialDashboardRegistration.WrongContentType ? "html/text" : "application/json");

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
        }
Exemple #6
0
        private Dictionary <string, object> GetRequestContentForInjectionDashboardRegistration(DashboardHelpers.Parameters parameter, InjectionInput inputType)
        {
            var orginalRequest = new Dictionary <string, object>(DashboardHelpers.DashboardRegistrationDefaultParameters(UserIds));
            var request        = orginalRequest["settings"] as Dictionary <string, object>;
            var injectionData  = InjectionInputData.InjectionInputMapper[inputType];

            switch (parameter)
            {
            case DashboardHelpers.Parameters.Agents:
                request["owners"] = new Dictionary <string, string>
                {
                    ["agents"] = injectionData
                };
                break;

            case DashboardHelpers.Parameters.Depts:
                request["owners"] = new Dictionary <string, string>
                {
                    ["depts"] = injectionData
                };
                break;

            case DashboardHelpers.Parameters.TimePeriodType:
                request["timePeriod"] = new Dictionary <string, string>
                {
                    ["type"] = injectionData
                };
                break;

            case DashboardHelpers.Parameters.Type:
                orginalRequest["type"] = injectionData;
                break;

            default:
                request[Char.ToLowerInvariant(parameter.ToString()[0]) + parameter.ToString().Substring(1)] = injectionData;
                break;
            }

            if (parameter == DashboardHelpers.Parameters.Settings)
            {
                orginalRequest["settings"] = injectionData;
            }
            else
            {
                orginalRequest["settings"] = request;
            }

            return(orginalRequest);
        }
Exemple #7
0
        public void TestInvalidBodyJson(InvalidSpecialCondition inputType)
        {
            var handler = new DashboardManager(DashboardHelpers.DashboardRegistrationEndPoint);
            var request = new Dictionary <string, object>(DashboardHelpers.DashboardRegistrationDefaultParameters(UserIds));

            string jsonContent = string.Empty;

            if (inputType == InvalidSpecialCondition.BrokenJsonFormat)
            {
                jsonContent = JsonConvert.SerializeObject(request).Remove(0, 1);
            }
            else
            {
                jsonContent = DashboardHelpers.InvalidBodyJsonTestCasesMapper[inputType].ToString();
            }

            var response = handler.SendDashboard <object>(jsonContent, System.Net.Http.HttpMethod.Put);

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
        }
Exemple #8
0
        private Dictionary <string, object> GetRequestContentForInvalidDashboardRegistration(DashboardHelpers.Parameters parameter, InvalidTestCases inputType)
        {
            var orginalRequest = new Dictionary <string, object>(DashboardHelpers.DashboardRegistrationDefaultParameters(UserIds));
            var request        = orginalRequest["settings"] as Dictionary <string, object>;
            var parameterName  = Char.ToLowerInvariant(parameter.ToString()[0]) + parameter.ToString().Substring(1);

            if (inputType != InvalidTestCases.Missing)
            {
                switch (parameter)
                {
                case DashboardHelpers.Parameters.Agents:
                    request["owners"] = new Dictionary <string, string>
                    {
                        ["agents"] = inputType == InvalidTestCases.Negative ? "-2" : InvalidMaps[inputType].ToString()
                    };
                    break;

                case DashboardHelpers.Parameters.Depts:
                    request["owners"] = new Dictionary <string, string>
                    {
                        ["depts"] = InvalidMaps[inputType].ToString()
                    };
                    break;

                case DashboardHelpers.Parameters.TimePeriodType:
                    request["timePeriod"] = new Dictionary <string, string>
                    {
                        ["type"] = InvalidMaps[inputType].ToString()
                    };
                    break;

                case DashboardHelpers.Parameters.Settings:
                    orginalRequest["settings"] = InvalidMaps[inputType].ToString();
                    break;

                case DashboardHelpers.Parameters.Type:
                    orginalRequest["type"] = InvalidMaps[inputType].ToString();
                    break;

                default:
                    request[parameterName] = InvalidMaps[inputType].ToString();
                    break;
                }
            }
            else
            if (inputType == InvalidTestCases.Missing)
            {
                if (DashboardHelpers.Parameters.Settings == parameter || DashboardHelpers.Parameters.Type == parameter)
                {
                    orginalRequest.Remove(parameterName);
                }
                else
                if (DashboardHelpers.Parameters.Agents == parameter || DashboardHelpers.Parameters.Depts == parameter)
                {
                    (request["owners"] as Dictionary <string, List <int> >).Remove(parameterName);
                }
                else
                if (DashboardHelpers.Parameters.TimePeriodType == parameter)
                {
                    (request["timePeriod"] as Dictionary <string, string>).Remove("type");
                }
                else
                {
                    request.Remove(parameterName);
                }
            }
            orginalRequest["settings"] = request;
            return(orginalRequest);
        }