public void TestGetDuplicateParameters(Values value)
        {
            var handler  = new MergeSettingsManager();
            var response = handler.MergeSettings <MergeSettingsResponse>(GetDuplicateParameters[value], System.Net.Http.HttpMethod.Get);

            PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK));
        }
        public void TestPutWrongContentTypeMergeSettings()
        {
            var handler  = new MergeSettingsManager();
            var response = handler.MergeSettings <MergeSettingsResponse>((object)MergeSettingDefaultParameters, System.Net.Http.HttpMethod.Put, "html/text");

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
        }
        public void TestMergeSettingsByOtherHttpMethod(HttpMethod inputType)
        {
            var handler  = new MergeSettingsManager();
            var response = handler.MergeSettings <MergeSettingsResponse>(MergeSettingDefaultParameters, inputType.ToNetHttpMethod());

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.NotFound));
        }
        public void TestPutDuplicateParameters(SpecialData.Parameters parameter, Values value)
        {
            var handler  = new MergeSettingsManager();
            var response = handler.MergeSettings <MergeSettingsResponse>(value == Values.Same ? PutDuplicateParametersSameValue[parameter] : PutDuplicateParametersNotSameValue[parameter], System.Net.Http.HttpMethod.Put);

            PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.NoContent));
        }
        public void TestGetMergeSettingsInjection(string parameter, InjectionInput inputType)
        {
            var handler = new MergeSettingsManager();
            var request = new Dictionary <string, string>(MergeSettingDefaultParameters);

            request[parameter] = InjectionInputData.InjectionInputMapper[inputType];
            var response = handler.MergeSettings <MergeSettingsResponse>(request, System.Net.Http.HttpMethod.Get);

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
        }
        public void InvalidIsFixedPutMethodTests(ResourceId resourceId, PutMethodTestData.InvalidValue isFixed)
        {
            var handler     = new MergeSettingsManager();
            var requestBody = new Dictionary <string, object>()
            {
                ["resourceId"] = (int)resourceId,
                ["isFixed"]    = PutMethodTestData.InvalidValueMapper[isFixed],
            };
            var response = handler.MergeSettings <object>(requestBody, HttpMethod.PUT.ToNetHttpMethod());

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(400), $"Update merge settings for {resourceId} with isFixed = {isFixed} successfully");
            PrAssert.That(response, PrIs.ErrorResponse().And.ErrorCode(PutMethodTestData.InvalidIsFixedErrorCode[isFixed]), $"Update merge settings for {resourceId} with isFixed = {isFixed} successfully");
        }
        public void ValidGetMethodTests(ResourceId resource)
        {
            var request = new Dictionary <string, string>()
            {
                ["resourceId"] = $"{(int)resource}"
            };

            var MergeSettingManager = new MergeSettingsManager();
            var result = MergeSettingManager.MergeSettings <MergeSettingsResponse>(request, string.Empty, HttpMethod.Get);

            PrAssert.That(result, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK));
            PrAssert.That(result.Result.Settings.Single().ResourceType, PrIs.EqualTo((int)resource));
        }
        public void InvalidGetMethodTests(InvalidValues testcase)
        {
            var request = new Dictionary <string, string>()
            {
                ["resourceId"] = InvalidValuesMapper[testcase]
            };

            var MergeSettingManager = new MergeSettingsManager();
            var result = MergeSettingManager.MergeSettings <MergeSettingsResponse>(request, string.Empty, HttpMethod.Get);

            PrAssert.That(result, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
            PrAssert.That(result, PrIs.WithErrorCode((int)ResultCode.InvalidParameter));
        }
        public void ValidMissingResourceIdGetMethodTest()
        {
            var MergeSettingManager = new MergeSettingsManager();
            var result = MergeSettingManager.MergeSettings <MergeSettingsResponse>(HttpMethod.Get);

            PrAssert.That(result, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK));
            PrAssert.That(result.Result.Settings, PrIs.Not.Null.Or.Empty);
            PrAssert.That(result.Result.Settings.Count, PrIs.EqualTo(4));

            foreach (var setting in result.Result.Settings)
            {
                PrAssert.That(new[] { setting.ResourceType }, PrIs.SubsetOf(new[] { 1, 5, 9, 17 }));
            }
        }
        public void ValidGetMethodCheckReturnJsonContentTypeTest()
        {
            var request = new Dictionary <string, string>()
            {
                ["resourceId"] = $"{(int)Utils.GetRandomResourceId(ValidResourceIds)}"
            };

            var MergeSettingManager = new MergeSettingsManager();
            var expectedContentType = "application/json";
            var result = MergeSettingManager.MergeSettings(request, string.Empty, HttpMethod.Get, expectedContentType);

            PrAssert.Equals(result.StatusCode, System.Net.HttpStatusCode.OK);
            PrAssert.Equals(result.Content.Headers.ContentType.MediaType, expectedContentType);
        }
        public void InvalidMissingParameterPutMethodMergeSettingsTests(PutMethodTestData.MissingParam missingParam)
        {
            var handler     = new MergeSettingsManager();
            var requestBody = new Dictionary <string, object>()
            {
                ["resourceId"] = (int)ResourceId.Client,
                ["isFixed"]    = true,
            };

            PutMethodTestData.MissingMapper[missingParam](requestBody);
            var response = handler.MergeSettings <object>(requestBody, HttpMethod.PUT.ToNetHttpMethod());

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(400), $"Update merge settings with missing {missingParam} successfully");
            PrAssert.That(response, PrIs.ErrorResponse().And.ErrorCode((int)ResultCode.NullParameterValue), $"Update merge settings with missing {missingParam} successfully");
        }
示例#12
0
        public void ValidPutMethodMergeSettingsTests(ResourceId resourceId, int isFixed)
        {
            var handler     = new MergeSettingsManager();
            var requestBody = new Dictionary <string, string>()
            {
                ["resourceId"] = $"{(int)resourceId}",
                ["isFixed"]    = $"{isFixed}",
            };
            var response = handler.MergeSettings <object>((object)requestBody, HttpMethod.PUT.ToNetHttpMethod());

            PrAssert.That(response, PrIs.SuccessfulResponse(), $"Cannot update merge settings for {resourceId} with isFixed = {isFixed}");
            requestBody.Remove("isFixed");
            var getResponse = handler.MergeSettings <MergeSettingsResponse>(requestBody, HttpMethod.GET.ToNetHttpMethod());

            PrAssert.That(getResponse, PrIs.SuccessfulResponse(), $"Cannot get merge settings for {resourceId}");
            PrAssert.That(getResponse.Result.Settings.Count, PrIs.EqualTo(1), $"The return response contains more than 1 item");
            PrAssert.That(getResponse.Result.Settings.Single().IsFixed, PrIs.EqualTo(isFixed), $"The return settings' isFixed is not as expected");
        }
        public void TestPutInvalidBodyJson(InvalidSpecialCondition inputType)
        {
            var handler = new MergeSettingsManager();

            string jsonContent = string.Empty;

            if (inputType == InvalidSpecialCondition.BrokenJsonFormat)
            {
                jsonContent = JsonConvert.SerializeObject(MergeSettingDefaultParameters).ToString().Substring(1);
            }
            else
            {
                jsonContent = DashboardHelpers.InvalidBodyJsonTestCasesMapper[inputType].ToString();
            }

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

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
        }