public void ValidExchangeMappingTest(Scope scope, Label label, Mode mode, ResourceId resource) { var fileHandler = new FileUploadManager(); var mappingHandler = new MappingManager(); var exchangeQueueHandler = new QueueManager(); var requestMappingUpdate = new Dictionary <string, object>(); var uploadResult = fileHandler.FileUpload <UploadFileResponse>($"{CSVFiles.Data[$"{resource}"]}", System.Net.Http.HttpMethod.Post); requestMappingUpdate = mode == Mode.Import ? RequestValidExchangeMappingUpdate(ImportMappingIds.Data[$"{resource}"], label, scope, ImportContents[$"{resource}"]): RequestValidExchangeMappingUpdate(ExportMappingIds.Data[$"{resource}"], label, scope, ExportContents[$"{resource}"]); var mappingResult = mappingHandler.ExchangeMapping <object>(requestMappingUpdate, System.Net.Http.HttpMethod.Put); PrAssert.That(mappingResult, PrIs.SuccessfulResponse().And.HttpCode((int)System.Net.HttpStatusCode.NoContent)); var queueRequest = CreateQueueRequest(mode, resource, uploadResult.Result.FileId); var queueResult = exchangeQueueHandler.Queue <int>(queueRequest, System.Net.Http.HttpMethod.Post); var hrbcQueueRequest = CreateHrbcQueueRequest(mode, queueResult.Result); var result = GetRequestQueueMapping(hrbcQueueRequest); PrAssert.That(result, PrIs.SuccessfulResponse().And.HttpCode((int)System.Net.HttpStatusCode.OK)); PrAssert.That(result.Result.Status, PrIs.EqualTo("finished")); PrAssert.That(result.Result.Log.Failed, PrIs.Zero); }
public void UpdateMappingByOtherHttpMethod(HttpMethod inputType) { var mappingHandler = new MappingManager(); var response = mappingHandler.ExchangeMapping <object>(GetDefaultExchangeMapping(Mode.Import, ResourceId.Client, MappingId), inputType.ToNetHttpMethod()); PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest)); }
public void DuplicateParameters(Fields field, Values value) { var mappingHandler = new MappingManager(); var mId = MappingId; var mLabel = ExchangeMapping.Label; var mScope = ExchangeMapping.Scope; var mContent = ExchangeMapping.Content; var mDiffContent = mContent; mDiffContent.Name = "Changed Name"; var parametersSameValue = new Dictionary <Fields, object> { [Fields.Id] = $"{{\"id\": \"{mId}\", \"id\": \"{mId}\", \"label\": \"{mLabel}\", \"scope\": \"{mScope}\", \"content\": {JsonConvert.SerializeObject(mContent)}}}", [Fields.Label] = $"{{\"id\": \"{mId}\", \"label\": \"{mLabel}\", \"label\": \"{mLabel}\", \"scope\": \"{mScope}\", \"content\": {JsonConvert.SerializeObject(mContent)}}}", [Fields.Scope] = $"{{\"id\": \"{mId}\", \"label\": \"{mLabel}\", \"scope\": \"{mScope}\", \"scope\": \"{mScope}\", \"content\": {JsonConvert.SerializeObject(mContent)}}}", [Fields.Content] = $"{{\"id\": \"{mId}\", \"label\": \"{mLabel}\", \"scope\": \"{mScope}\", \"content\": {JsonConvert.SerializeObject(mContent)}, \"content\": {JsonConvert.SerializeObject(mContent)}}}", }; var parametersNotSameValue = new Dictionary <Fields, object> { [Fields.Id] = $"{{\"id\": \"{mId}\", \"id\": \"1000000\", \"label\": \"{mLabel}\", \"scope\": \"{mScope}\", \"content\": {JsonConvert.SerializeObject(mContent)}}}", [Fields.Label] = $"{{\"id\": \"{mId}\", \"label\": \"{mLabel}\", \"label\": \"Changed Label\", \"scope\": \"{mScope}\", \"content\": {JsonConvert.SerializeObject(mContent)}}}", [Fields.Scope] = $"{{\"id\": \"{mId}\", \"label\": \"{mLabel}\", \"scope\": \"{mScope}\", \"scope\": \"public\", \"content\": {JsonConvert.SerializeObject(mContent)}}}", [Fields.Content] = $"{{\"id\": \"{mId}\", \"label\": \"{mLabel}\", \"scope\": \"{mScope}\", \"content\": {JsonConvert.SerializeObject(mContent)}, \"content\": {JsonConvert.SerializeObject(mDiffContent)}}}", }; var response = mappingHandler.ExchangeMapping <ErrorsResponse>(value == Values.Same ? parametersSameValue[field] : parametersNotSameValue[field], System.Net.Http.HttpMethod.Put); PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest)); PrAssert.That(response.Errors.Code, PrIs.EqualTo((int)ResultCode.NullParameterValue)); }
public void DeletedMapping(ResourceId resourceId, Mode mode) { var mappingHandler = new MappingManager(); //Delete a created mapping var deleteResponse = mappingHandler.ExchangeMapping <object>(new Dictionary <string, object> { ["id"] = MappingId }, HttpMethod.Delete); PrAssume.That(deleteResponse, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.NoContent)); //Update a mapping var updateResponse = mappingHandler.ExchangeMapping <ErrorsResponse>(GetDefaultExchangeMapping(mode, resourceId, MappingId), HttpMethod.Put); PrAssert.That(updateResponse, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.NotImplemented)); PrAssert.That(updateResponse.Errors.Code, PrIs.EqualTo((int)ResultCode.DataNotExists)); }
public void SwapMapping(ResourceId resourceId, Mode mode) { var mappingHandler = new MappingManager(); //Update a swap mapping var updateResponse = mappingHandler.ExchangeMapping <object>(GetDefaultExchangeMapping(mode == Mode.Import ? Mode.Export : Mode.Import, resourceId, MappingId), HttpMethod.Put); PrAssert.That(updateResponse, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest)); }
public void ExchangeMappingInvalidContentTest(string mode, ContentParam contentParam, InvalidContent invalidContent, int expectedCode) { ExchangeMappingProperties requestBody = ExchangeMappingProperties.GetMappingContent(mode, mode == "import" ? CreatedImportMapping.Data : CreatedExportMapping.Data, Label, Name, Group, Resource, new List <string> { "Client.P_Id" }, Labels, GroupsDic, Items, AdditionConverters); var mappingHandler = new MappingManager(); var response = mappingHandler.ExchangeMapping <object>(InvalidContentMapper[contentParam](requestBody, invalidContent), System.Net.Http.HttpMethod.Put); PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest).And.ErrorCode(100).Or.ErrorCode(116).Or.ErrorCode(103)); }
private void SendRequestAndVerify(string mode, Func <ExchangeMappingProperties, IEnumerable <KeyValuePair <string, object> > > getRequest, System.Net.HttpStatusCode statusCode, int expectedCode) { ExchangeMappingProperties requestBody = ExchangeMappingProperties.GetMappingContent(mode, mode == "import" ? CreatedImportMapping.Data : CreatedExportMapping.Data, Label, Name, Group, Resource, new List <string> { "Client.P_Id" }, Labels, GroupsDic, Items, AdditionConverters); var mappingHandler = new MappingManager(); var response = mappingHandler.ExchangeMapping <object>(getRequest(requestBody), System.Net.Http.HttpMethod.Put); PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(statusCode).And.ErrorCode(expectedCode)); }
public void InvalidJsonFormat(InvalidSpecialCondition inputType) { PrivateApiResponse <object> response = null; var mappingHandler = new MappingManager(); if (inputType == InvalidSpecialCondition.WrongContentType) { response = mappingHandler.ExchangeMapping <object>(GetDefaultExchangeMapping(Mode.Import, ResourceId.Client, MappingId), System.Net.Http.HttpMethod.Put, InvalidEntrySpecialTestCasesMapper[InvalidSpecialCondition.WrongContentType].ToString()); } else { string jsonContent = string.Empty; if (inputType == InvalidSpecialCondition.BrokenJsonFormat) { jsonContent = JsonConvert.SerializeObject(GetDefaultExchangeMapping(Mode.Import, ResourceId.Client, MappingId)).Remove(0, 1); } else { jsonContent = InvalidEntrySpecialTestCasesMapper[inputType].ToString(); } response = mappingHandler.ExchangeMapping <object>(jsonContent, System.Net.Http.HttpMethod.Put); } PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(InvalidSpecialCondition.WrongContentType == inputType ? System.Net.HttpStatusCode.UnsupportedMediaType : System.Net.HttpStatusCode.BadRequest)); }
public void UpdateMappingInjection(Fields field, InjectionInput inputType, int resultCode) { Dictionary <string, object> requestContent = null; var mappingHandler = new MappingManager(); var fieldContentMapping = new Dictionary <Fields, Action <ExchangeMappingProperties> > { [Fields.Id] = (exMapping) => { exMapping.Id = InjectionInputData.InjectionInputMapper[inputType]; exMapping.Content.Id = MappingId; }, [Fields.Label] = (exMapping) => { exMapping.Label = InjectionInputData.InjectionInputMapper[inputType]; exMapping.Id = MappingId; exMapping.Content.Id = MappingId; }, [Fields.Scope] = (exMapping) => { exMapping.Scope = InjectionInputData.InjectionInputMapper[inputType]; exMapping.Id = MappingId; exMapping.Content.Id = MappingId; }, [Fields.Content] = (exMapping) => { var mLabel = exMapping.Label; var mScope = exMapping.Scope; requestContent = new Dictionary <string, object> { ["id"] = MappingId, ["label"] = mLabel, ["scope"] = mScope, ["content"] = InjectionInputData.InjectionInputMapper[inputType] }; }, }; fieldContentMapping[field](ExchangeMapping); var response = Fields.Content == field?mappingHandler.ExchangeMapping <ErrorsResponse>(requestContent, System.Net.Http.HttpMethod.Put) : mappingHandler.ExchangeMapping <ErrorsResponse>(ExchangeMapping, System.Net.Http.HttpMethod.Put); if (field == Fields.Label) { PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.NoContent)); } else { PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest)); PrAssert.That(response.Errors.Code, PrIs.EqualTo(resultCode)); } }
public static PrivateData <int> CreateMappingCustomFixture(object requestDic) { return(new PrivateData <int>( (session, test) => { return Task.Run(() => { var mappingHandler = new MappingManager(); var result = mappingHandler.ExchangeMapping <int>(requestDic, System.Net.Http.HttpMethod.Post); PrAssume.That(result, PrIs.SuccessfulResponse(), "Cannot create mapping"); return result.Result; }); }, (session, test, res) => Task.Run(() => { }))); }
private static PrivateData <Dictionary <string, int> > CreateMappingCustomFixture(Dictionary <string, ExchangeMappingProperties> requestDic) { return(new PrivateData <Dictionary <string, int> >( (session, test) => { return Task.Run(() => { var mappingHandler = new MappingManager(); var Ids = new Dictionary <string, int>(); foreach (ResourceId resource in Utils.Resources()) { var result = mappingHandler.ExchangeMapping <int>(requestDic[$"{resource}"], System.Net.Http.HttpMethod.Post); PrAssume.That(result, PrIs.SuccessfulResponse(), "Cannot create mapping"); Ids.Add($"{resource}", result.Result); } return Ids; }); }, (session, test, res) => Task.Run(() => { }))); }