Example #1
0
        public static void SendAndVerifyMergeRequest(HrbcRecordCreator record, MergeManager mergeHandler, ResourceId resourceId, int baseIndex, int mergeIndex, bool IsValidRequest = true)
        {
            var requestContent = new Dictionary <string, object>()
            {
                ["baseId"]   = record.Data[$"{resourceId}{baseIndex}"].Id,
                ["mergedId"] = new List <ulong>()
                {
                    record.Data[$"{resourceId}{mergeIndex}"].Id
                },
                ["mapping"] = GetMapping(resourceId, record.Data[$"{resourceId}{baseIndex}"].Id, record.Data[$"{ResourceId.Client}{baseIndex}"].Id),
            };
            var response = mergeHandler.MergeRecords <MergeResponse>(resourceId, requestContent, System.Net.Http.HttpMethod.Post);

            if (IsValidRequest)
            {
                PrAssert.That(response, PrIs.SuccessfulResponse());
                PrAssert.That(response.Result.Id, PrIs.Not.Null);
                LoopAndVerifyCompleteMerge(response.Result.Id);
            }
            else
            {
                PrAssert.That(response, PrIs.ErrorResponse().With.HttpCode((int)HttpStatusCode.BadRequest));
                PrAssert.That(response.Errors.Code, PrIs.EqualTo((int)ResultCode.InvalidParameter));
                PrAssert.That(response.Errors.Error, PrIs.EqualTo("Invalid Parameter."));
            }
        }
Example #2
0
        public void MergeInvalid(ResourceId resourceId, InvalidTestCases inputType, Parameters parameter)
        {
            var mergeRequest = GetParameters(resourceId, inputType, parameter);
            var mergeHandler = new MergeManager();
            var response     = mergeHandler.MergeRecords <MergeResponse>(resourceId, mergeRequest, System.Net.Http.HttpMethod.Post);

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
        }
Example #3
0
        public void MergeInjection(ResourceId resourceId, InjectionInput injection, Parameters parameter)
        {
            var mergeRequest = GetDefaultParameters(resourceId);

            mergeRequest[Char.ToLowerInvariant(parameter.ToString()[0]) + parameter.ToString().Substring(1)] = InjectionInputData.InjectionInputMapper[injection];

            var mergeHandler = new MergeManager();
            var response     = mergeHandler.MergeRecords <MergeResponse>(resourceId, mergeRequest, System.Net.Http.HttpMethod.Post);

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
        }
Example #4
0
        public void MergeValid(ResourceId resourceId, ValidTestCases inputType)
        {
            var mergeRequest = GetParameters(resourceId, inputType);
            var mergeHandler = new MergeManager();
            var response     = mergeHandler.MergeRecords <MergeResponse>(resourceId, mergeRequest, HttpMethod.Post);

            PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK));

            //Waiting for merge task successed before verifing data
            Assert.That(GetQueueMergeStatus(response.Result.Id.ToString()), "The merging is not finished yet!");

            //Verify data
            VerifyData(resourceId, inputType);
        }
Example #5
0
        public void MergeByOtherHttpMethod(HttpMethod inputType)
        {
            var mergeRequest = GetDefaultParameters(ResourceId.Client);
            var httpMethod   = new Dictionary <HttpMethod, System.Net.Http.HttpMethod>()
            {
                [HttpMethod.GET]    = System.Net.Http.HttpMethod.Get,
                [HttpMethod.DELETE] = System.Net.Http.HttpMethod.Delete,
                [HttpMethod.PUT]    = System.Net.Http.HttpMethod.Put,
            };

            var mergeHandler = new MergeManager();
            var response     = mergeHandler.MergeRecords <MergeResponse>(ResourceId.Client, mergeRequest, httpMethod[inputType]);

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
        }
Example #6
0
        public void MergeInvalidCommon(ResourceId resourceId, InvalidCommonTestCases inputType)
        {
            var parameters = GetDefaultParameters(resourceId);

            switch (inputType)
            {
            case InvalidCommonTestCases.AdditonalDuplicateId:
                parameters["baseId"]      = GetRecordId(resourceId, 3);
                parameters["mergedId"]    = GetRecordId(resourceId, 4);
                parameters["duplicateId"] = GetRecordId(resourceId, 5);
                break;

            case InvalidCommonTestCases.NoneExistedField:
                parameters["baseId"]   = GetRecordId(resourceId, 6);
                parameters["mergedId"] = GetRecordId(resourceId, 7);
                parameters["mapping"]  = GetMapping(resourceId, $"{resourceId.ToString()}.P_NonExistField", "TEST");
                break;

            case InvalidCommonTestCases.NoneExistedResource:
                parameters["baseId"]   = GetRecordId(resourceId, 8);
                parameters["mergedId"] = GetRecordId(resourceId, 9);
                parameters["mapping"]  = GetMapping(resourceId, $"Resource.P_Zipcode", "000-0000");
                break;

            case InvalidCommonTestCases.WrongResource:
                parameters["baseId"]   = GetRecordId(resourceId, 10);
                parameters["mergedId"] = GetRecordId(resourceId, 11);
                parameters["mapping"]  = GetMapping(resourceId, $"Job.P_Zipcode", "000-0000");
                break;

            case InvalidCommonTestCases.ReverseField:
                parameters["baseId"]   = GetRecordId(resourceId, 12);
                parameters["mergedId"] = GetRecordId(resourceId, 13);
                parameters["mapping"]  = GetMapping(resourceId, $"{resourceId.ToString()}.P_Zipcode", "{\"" + resourceId.ToString() + ".P_Zipcode\": \"000 - 0000\"}");
                break;
            }

            var mergeHandler = new MergeManager();
            var response     = mergeHandler.MergeRecords <MergeResponse>(resourceId, parameters, System.Net.Http.HttpMethod.Post);

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
        }
        public void DeletedIds(TestCoreFramework.Enums.ResourceType resourceId)
        {
            var baseId         = DeletedRecord.Data[resourceId.ToPrivateApiResource()].Ids[0][0];
            var mergeId        = DeletedRecord.Data[resourceId.ToPrivateApiResource()].Ids[1][0];
            var clientId       = DeletedRecord.Data[ResourceId.Client].Ids[0][0];
            var requestContent = new Dictionary <string, object>()
            {
                ["baseId"]   = baseId,
                ["mergedId"] = new List <int>()
                {
                    mergeId
                },
                ["mapping"] = Common.GetMapping(resourceId.ToPrivateApiResource(), (ulong)baseId, (ulong)clientId),
            };
            MergeManager mergeHandler = new MergeManager();
            var          response     = mergeHandler.MergeRecords <MergeResponse>(resourceId.ToPrivateApiResource(), requestContent, System.Net.Http.HttpMethod.Post);

            PrAssert.That(response, PrIs.ErrorResponse().With.HttpCode((int)HttpStatusCode.BadRequest));
            PrAssert.That(response.Errors.Code, PrIs.EqualTo((int)ResultCode.InvalidParameter));
            PrAssert.That(response.Errors.Error, PrIs.EqualTo("Invalid Parameter."));
        }
Example #8
0
        public void MergeDeletedId(ResourceId resourceId, Parameters parameter)
        {
            var parameters = GetDefaultParameters(resourceId);

            switch (parameter)
            {
            case Parameters.MergedId:
                parameters["mergedId"] = PrepareDeletedIdsData.Data[resourceId].Ids[0][0].ToString();
                break;

            case Parameters.BaseId:
                parameters["baseId"]   = PrepareDeletedIdsData.Data[resourceId].Ids[0][0].ToString();
                parameters["mergedId"] = PrepareDeletedIdsData.Data[resourceId].Ids[1][0].ToString();
                parameters["mapping"]  = GetMapping(resourceId, $"{resourceId.ToString()}.P_Id", PrepareDeletedIdsData.Data[resourceId].Ids[0][0].ToString());
                break;
            }

            var mergeHandler = new MergeManager();
            var response     = mergeHandler.MergeRecords <MergeResponse>(resourceId, parameters, System.Net.Http.HttpMethod.Post);

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