public void TestReadInvalidOtherParamItemState(Enums.ResourceType resourceType, ItemState itemState, string parameter, ReadInvalidInput invalidInput, int expectedCode) { var parameters = GetUrlParameters(resourceType, itemState, parameter, invalidInput); ErrorCode result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadFail(resourceType.ToString(), parameters); Assert.That(result, MustBe.MatchingErrorCode(expectedCode), Enums.Message.WRONG_ERROR_CODE); }
public static ReadResponseData <XmlResource> GetSingleSearchResult(string resourceType, string fieldAlias, string condition, object firsrCondValue, object secondCondValue, int resultCode, Dictionary <string, object> extraUrlParameters = null) { string tempCond = $"{fieldAlias}:{condition}={firsrCondValue}"; string formatCond = condition == DateTimeValidator.Or ? $"{tempCond}:{secondCondValue}" : tempCond; Dictionary <string, object> urlParameters = new Dictionary <string, object>() { { "partition", AuthenticationInfoProvider.Current.DefaultPartition }, { "condition", formatCond }, { "field", fieldAlias } }; if (extraUrlParameters != null) { urlParameters = urlParameters.Concat(extraUrlParameters).GroupBy(d => d.Key).ToDictionary(d => d.Key, d => d.First().Value); } if (resultCode == Enums.PublicAPIResultCode.DateTimeOutOfRange) { ErrorCode errorResult = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadFail(resourceType, urlParameters); Assert.That(errorResult, MustBe.MatchingErrorCode(resultCode), Enums.Message.WRONG_ERROR_CODE); return(null); } else { var result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadSuccess(resourceType, urlParameters); Assert.That(result, Is.Not.Null, string.Format(Enums.Message.READ_RESOURCE_FAILED, resourceType)); Assert.That(result.Code, Is.EqualTo(resultCode), Enums.Message.WRONG_ERROR_CODE); Assert.That(result.Items, Is.Not.Null, string.Format("Read {0}'s resource to be empty!", resourceType)); return(result); } }
public void TestReadPhaseWithDuplicateParameters(string param, bool isDuplicatedValue) { Enums.ResourceType job = Enums.ResourceType.Job; Dictionary <string, object> parameters = new Dictionary <string, object>() { { PhaseApiFields.Partition, AuthenticationInfoProvider.Current.DefaultPartition }, }; List <object> duplicatedParameters = new List <object>(); var parameterValues = new Dictionary <string, object> { [PhaseApiFields.ResourceId + "1"] = (int)records.Data[$"{job.ToPrivateEnum()}0"].Id, [PhaseApiFields.ResourceId + "2"] = (int)records.Data[$"{job.ToPrivateEnum()}1"].Id, [PhaseApiFields.Id + "1"] = PhaseHelper.CreatePhase(job, records.Data[$"{job.ToPrivateEnum()}0"].Id.ToString()), [PhaseApiFields.Id + "2"] = PhaseHelper.CreatePhase(job, records.Data[$"{job.ToPrivateEnum()}1"].Id.ToString()), [PhaseApiFields.Resource + "1"] = (int)Enums.ResourceType.Client, [PhaseApiFields.Resource + "2"] = (int)Enums.ResourceType.Activity, [PhaseApiFields.Count + "1"] = 10, [PhaseApiFields.Count + "2"] = 11, [PhaseApiFields.Start + "1"] = 10, [PhaseApiFields.Start + "2"] = 12, [PhaseApiFields.Field + "1"] = PhaseApiFields.Memo, [PhaseApiFields.Field + "2"] = PhaseApiFields.Phase, [PhaseApiFields.Condition + "1"] = $"{nameof(PhaseApiFields.Id)}:eq={records.Data[$"{job.ToPrivateEnum()}0"].Id}", [PhaseApiFields.Condition + "2"] = $"{nameof(PhaseApiFields.Id)}:eq={records.Data[$"{job.ToPrivateEnum()}1"].Id}", [PhaseApiFields.Order + "1"] = $"{PhaseApiFields.Order}={nameof(PhaseApiFields.Id)}:{records.Data[$"{job.ToPrivateEnum()}0"].Id}", [PhaseApiFields.Order + "2"] = $"{PhaseApiFields.Order}={nameof(PhaseApiFields.Id)}:{records.Data[$"{job.ToPrivateEnum()}1"].Id}", }; if (isDuplicatedValue) { duplicatedParameters = new List <object> { parameterValues[$"{param}1"], parameterValues[$"{param}1"], parameterValues[$"{param}1"], }; } else { duplicatedParameters = new List <object> { parameterValues[$"{param}1"], parameterValues[$"{param}2"], parameterValues[$"{param}2"], }; } if (param != PhaseApiFields.Resource) { parameters.Add(PhaseApiFields.Resource, (int)job); } parameters.Add(param, duplicatedParameters); ErrorCode result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadFail <Phase>(parameters); Assert.That(result, MustBe.MatchingErrorCode(Enums.PublicAPIResultCode.ParameterIsInvalid), Enums.Message.WRONG_ERROR_CODE); }
public void TestCreateSingleItem(Enums.ResourceType resourceType, string fieldName, InjectionInput fieldType) { XmlResource resource = ResourceHelper.CreateSingleResourceItem(resourceType, $"{resourceType.ToResourceName()}.{fieldName}", InjectionInputData.InjectionInputMapper[fieldType], records, true); ErrorCode result = ResourceHelper.WriteResourceFail(resource, cleaner); Assert.That(result, MustBe.MatchingErrorCode(Enums.PublicAPIResultCode.InvalidParameterValue), Enums.Message.WRONG_ERROR_CODE); }
public void TestReadSpecialInvalidInput(ReadSpecialInvalidInput invalidInput, int expectedCode) { Dictionary <string, object> urlParameters = GetUrlParameter(invalidInput); ErrorCode result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadFail <Partition>(urlParameters); Assert.That(result, MustBe.MatchingErrorCode(expectedCode), Enums.Message.WRONG_ERROR_CODE); }
public void TestCreateListItem(Enums.ResourceType resourceType, InjectionInput fieldType) { List <XmlResource> resources = ResourceHelper.CreateListResourceItem(resourceType, $"{resourceType.ToResourceName()}.{AppField}", InjectionInputData.InjectionInputMapper[fieldType], records); ErrorCode result = ResourceHelper.WriteResourcesFail(resources, cleaner); Assert.That(result, MustBe.MatchingErrorCode(Enums.PublicAPIResultCode.InvalidParameterValue), Enums.Message.WRONG_ERROR_CODE); }
public void TestCreateSingleItem(Enums.ResourceType resourceType, WriteInvalidInput valueType, int expectedCode) { string fieldAlias = resourceType.ToResourceName() + "." + AppField; XmlResource resource = ResourceHelper.CreateSingleResourceItem(resourceType, fieldAlias, FieldValueMapper.InvalidMapper[valueType], records, true); ErrorCode result = ResourceHelper.WriteResourceFail(resource, cleaner); Assert.That(result, MustBe.MatchingErrorCode(expectedCode), Enums.Message.WRONG_ERROR_CODE); }
public void TestUpdateSingleItem(Enums.ResourceType resourceType, PhaseDateInput phaseDateType, PhaseOptionInput phaseOptionType, int expectedCode) { phaseDictionary = PhaseFieldHelper.InitPhaseList(phaseSearcher); var resource = PhaseFieldHelper.GetUpdatedResourcePhaseField(resourceType, phaseDateType, phaseOptionType, 0, phaseSearcher, phaseEntryReader, GetPhaseOrderBySort(resourceType), phaseDictionary, records); ErrorCode result = ResourceHelper.WriteResourceFail(resource, null); Assert.That(result, MustBe.MatchingErrorCode(expectedCode), string.Format("Cannot create phase for {0}", resourceType)); }
private static void ReadOrderPhaseFailed(Dictionary <string, object> urlParameters) { Handler handler = PublicApiAdapter.CreateAdapterForDefaultConnection().Read(nameof(Phase), urlParameters); Assert.That(handler, Is.Not.Null, "Cannot read resource!"); ErrorCode result = XmlHelper.ParseXMLString <ErrorCode>(handler.RawContent); Assert.That(result, MustBe.MatchingErrorCode(Enums.PublicAPIResultCode.InvalidParameterValue), Enums.Message.WRONG_ERROR_CODE); }
public void TestCreateSingleItem(Enums.ResourceType resourceType, string fieldName, Enums.TextType textType, AlphabetLenght characterNumber) { string fieldValue = Util.GetRandomText(textType, AlphabetValueMapper.AlphabetMapper[characterNumber]); XmlResource resource = ResourceHelper.CreateSingleResourceItem(resourceType, $"{resourceType.ToResourceName()}.{fieldName}", fieldValue, records, true); ErrorCode result = ResourceHelper.WriteResourceFail(resource, cleaner); Assert.That(result, MustBe.MatchingErrorCode(Enums.PublicAPIResultCode.InvalidParameterValue), Enums.Message.WRONG_ERROR_CODE); }
public void TestCreateSingleItem(Enums.ResourceType resourceType, InjectionInput fieldType) { XmlResource resource = ResourceHelper.CreateSingleResourceItem(resourceType, customFields.Data[$"{resourceType}"].Field.ToAlias(), InjectionInputData.InjectionInputMapper[fieldType], records); ErrorCode result = ResourceHelper.WriteResourceFail(resource, cleaner); Assert.That(result, MustBe.MatchingErrorCode(Enums.PublicAPIResultCode.InvalidParameterValue), Enums.Message.WRONG_ERROR_CODE); }
public void TestReadInjection(string param) { Dictionary <string, object> parameters = new Dictionary <string, object>() { { param, SQLInjection }, }; ErrorCode result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadFail <Partition>(parameters); Assert.That(result, MustBe.MatchingErrorCode(Enums.PublicAPIResultCode.InvalidParameterValue), Enums.Message.WRONG_ERROR_CODE); }
/// <summary> /// Send a request to update a single resource /// </summary> /// <param name="resourceType"></param> /// <param name="fieldAlias"></param> /// <param name="getFieldValue"></param> /// <param name="expectedCode"></param> /// <param name="records"></param> /// <param name="idRelatedFieldCreatedAutomatically"></param> /// <param name="index"></param> /// <param name="referenceRecords"></param> public static void UpdateSingleItem(Enums.ResourceType resourceType, string fieldAlias, Func <int, object> getFieldValue, int expectedCode, HrbcRecordCreator records, bool idRelatedFieldCreatedAutomatically = false, int index = 0, HrbcRecordCreator referenceRecords = null) { XmlResource resource = ResourceHelper.CreateUpdatedResource(resourceType, records.Data[$"{resourceType.ToPrivateEnum()}{index}"].Id.ToString(), fieldAlias, getFieldValue(index), idRelatedFieldCreatedAutomatically, referenceRecords, index); var error = ResourceHelper.WriteResourceFail(resource, null); Assert.That(error, MustBe.MatchingErrorCode(expectedCode), Enums.Message.WRONG_ERROR_CODE); }
/// <summary> /// Send request to create a single resource /// </summary> /// <param name="resourceType"></param> /// <param name="fieldAlias"></param> /// <param name="fieldValue"></param> /// <param name="expectedCode"></param> /// <param name="cleaner"></param> /// <param name="referenceRecords"></param> /// <param name="idRelatedFieldCreatedAutomatically"></param> /// <param name="index"></param> public static void CreateSingleItem(Enums.ResourceType resourceType, string fieldAlias, Func <int, object> getFieldValue, int expectedCode, HrbcRecordDelete cleaner, HrbcRecordCreator referenceRecords, bool idRelatedFieldCreatedAutomatically = false, int index = 0) { XmlResource resource = ResourceHelper.CreateSingleResourceItem(resourceType, fieldAlias, getFieldValue(index), referenceRecords, idRelatedFieldCreatedAutomatically, index, referenceRecords); var error = ResourceHelper.WriteResourceFail(resource, cleaner); Assert.That(error, MustBe.MatchingErrorCode(expectedCode), Enums.Message.WRONG_ERROR_CODE); }
public void CreateRecordWithDeletedFieldTest(Enums.ResourceType resource) { var resourceItem = ResourceHelper.CreateResourceInstance(RecordCreator, resource); resourceItem.DictionaryValues.Add($"{resource.ToString()}.{DeletedFieldsCreator.Data[resource].Name}", "TEST VALUE"); var result = PublicApiAdapter.CreateAdapterForDefaultConnection().WriteFail(resourceItem, cleaner.DeleteMany); Assert.That(result, MustBe.MatchingErrorCode(Enums.PublicAPIResultCode.ParameterIsInvalid), Enums.Message.WRONG_ERROR_CODE); }
/// <summary> /// Send and verify a post request failed /// </summary> /// <param name="apiUrl">Url of api</param> /// <param name="parameters">Parameters</param> public static void SendPostRequestApiError(string apiUrl, Dictionary <string, object> parameters) { Handler handler = PublicApiAdapter.CreateAdapterForDefaultConnection().Write(nameof(Partition), null, parameters); Assert.That(handler, MustBe.Not.Null, "Cannot send a request to PublicAPI"); Assert.That(handler.HttpCode, MustBe.EqualTo(HttpStatusCode.OK), "Cannot send a request to PublicAPI"); ErrorCode errorCode = XmlHelper.ParseXMLString <ErrorCode>(handler.RawContent); Assert.That(errorCode, MustBe.MatchingErrorCode(Enums.PublicAPIResultCode.ResourceNotExist), Enums.Message.WRONG_ERROR_CODE); }
public void TestReadField(string field) { Dictionary <string, object> parameters = new Dictionary <string, object>() { { "field", $"Partition.{field}" }, }; ErrorCode result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadFail <Partition>(parameters); Assert.That(result, MustBe.MatchingErrorCode(Enums.PublicAPIResultCode.ParameterIsInvalid), Enums.Message.WRONG_ERROR_CODE); }
public void TestCreateListItem(Enums.ResourceType resourceType, Enums.TextType textType, AlphabetLenght characterNumber) { string fieldValue = Util.GetRandomText(textType, AlphabetValueMapper.AlphabetMapper[characterNumber]); List <XmlResource> resources = ResourceHelper.CreateListResourceItem(resourceType, customFields.Data[$"{resourceType}"].Field.ToAlias(), fieldValue, records); ErrorCode result = ResourceHelper.WriteResourcesFail(resources, cleaner); Assert.That(result, MustBe.MatchingErrorCode(Enums.PublicAPIResultCode.InvalidParameterValue), Enums.Message.WRONG_ERROR_CODE); }
public void TestReadInvalidItemState(Enums.ResourceType resourceType, ReadInvalidInput invalidInput, int expectedCode) { var parameters = new Dictionary <string, object>() { { DeletedDataFields.Partition, AuthenticationInfoProvider.Current.DefaultPartition }, { DeletedDataFields.ItemState, ReadInvalidInputItemStateMapper.InvalidItemStateMapper[invalidInput] }, }; ErrorCode result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadFail(resourceType.ToString(), parameters); Assert.That(result, MustBe.MatchingErrorCode(expectedCode), Enums.Message.WRONG_ERROR_CODE); }
public void TestSearchCondition(string field, string conditionValue, int expectedCode) { Dictionary <string, object> urlParameters = new Dictionary <string, object>() { ["condition"] = $"Partition.{field}:eq={conditionValue}", }; ErrorCode result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadFail <Partition>(urlParameters); Assert.That(result, MustBe.MatchingErrorCode(expectedCode), Enums.Message.WRONG_ERROR_CODE); }
public void TestReadCommonInvalidInput(string parameter, ReadInvalidInput invalidInput, int expectedCode) { Dictionary <string, object> urlParameters = new Dictionary <string, object>() { [parameter] = ReadInvalidInputFieldMapper.CommonMapper[invalidInput], }; ErrorCode result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadFail <Partition>(urlParameters); Assert.That(result, MustBe.MatchingErrorCode(expectedCode), Enums.Message.WRONG_ERROR_CODE); }
public void TestCreateSingleItem(Enums.ResourceType resourceType, WriteInvalidInput valueType, int expectedCode) { Assume.That(customFields.Data, Is.Not.Null, "HrbcFieldCreator cannot create custom fields!"); string fieldAlias = customFields.Data[$"{resourceType}"].Field.ToAlias(); XmlResource resource = ResourceHelper.CreateSingleResourceItem(resourceType, fieldAlias, FieldValueMapper.InvalidMapper[valueType], records, true); ErrorCode result = ResourceHelper.WriteResourceFail(resource, cleaner); Assert.That(result, MustBe.MatchingErrorCode(expectedCode), Enums.Message.WRONG_ERROR_CODE); }
public void TestReadSingleOrder(string field, OrderTestHelper.OrderType order) { string paramValue = order == OrderTestHelper.OrderType.OrderEmpty ? $"Partition.{field}" : $"Partition.{field}:{order.ToLowerString()}"; Dictionary <string, object> parameters = new Dictionary <string, object>() { { "order", paramValue }, }; ErrorCode result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadFail <Partition>(parameters); Assert.That(result, MustBe.MatchingErrorCode(Enums.PublicAPIResultCode.ParameterIsInvalid), Enums.Message.WRONG_ERROR_CODE); }
/// <summary> /// Send a request to update a list of resources /// </summary> /// <param name="resourceType"></param> /// <param name="fieldAlias"></param> /// <param name="fieldValue"></param> /// <param name="expectedCode"></param> /// <param name="records"></param> public static void UpdateListItem(Enums.ResourceType resourceType, string fieldAlias, Func <int, object> getFieldValue, int expectedCode, HrbcRecordCreator records, bool idRelatedFieldCreatedAutomatically = false, HrbcRecordCreator referenceRecord = null) { IEnumerable <XmlResource> resourceList = new int[] { 0, 1 }.Select(index => { return(ResourceHelper.CreateUpdatedResource(resourceType, records.Data[$"{resourceType.ToPrivateEnum()}{index}"].Id.ToString(), fieldAlias, getFieldValue(index), idRelatedFieldCreatedAutomatically, referenceRecord, index)); }); ErrorCode result = ResourceHelper.WriteResourcesFail(resourceList); Assert.That(result, MustBe.MatchingErrorCode(expectedCode), Enums.Message.WRONG_ERROR_CODE); }
public void TestReadField(string field) { Dictionary <string, object> parameters = new Dictionary <string, object>() { { FieldApiFields.Partition, AuthenticationInfoProvider.Current.DefaultPartition }, { FieldApiFields.Resource, (int)Enums.ResourceType.Client.ToPrivateEnum() }, { "field", $"Partition.{field}" }, }; ErrorCode result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadFail <Field>(parameters); Assert.That(result, MustBe.MatchingErrorCode(Enums.PublicAPIResultCode.ParameterIsInvalid), Enums.Message.WRONG_ERROR_CODE); }
public void TestUpdateListItem(Enums.ResourceType resourceType, Enums.TextType textType, AlphabetLenght characterNumber) { List<XmlResource> resourceList = new[] { 0, 1 }.Select(depKey => ResourceHelper.CreateResourceInstance(records, resourceType, depKey)).ToList(); List<WriteResultItem> ids = ResourceHelper.WriteResources(resourceType, resourceList, cleaner); Assume.That(ids, MustBe.SuccessfullyWritten(resourceList.Count()), string.Format(Enums.Message.CREATE_RESOURCE_ENTRY_FAILED, resourceType)); string fieldAlias = resourceType.ToResourceName() + "." + AppField; string fieldValue = Util.GetRandomText(textType, AlphabetValueMapper.AlphabetMapper[characterNumber]); resourceList = ids.Select(item => ResourceHelper.CreateUpdatedResource(resourceType, item.Id, fieldAlias, fieldValue)).ToList(); ErrorCode result = ResourceHelper.WriteResourcesFail(resourceList); Assert.That(result, MustBe.MatchingErrorCode(Enums.PublicAPIResultCode.InvalidParameterValue), Enums.Message.WRONG_ERROR_CODE); }
public void TestUpdateSingleItem(Enums.ResourceType resourceType, Enums.TextType textType, AlphabetLenght characterNumber) { XmlResource resource = ResourceHelper.CreateResourceInstance(records, resourceType); string id = ResourceHelper.WriteResource(resource, cleaner); Assume.That(id, Is.Not.Null.And.Not.Empty, string.Format(Enums.Message.CREATE_RESOURCE_ENTRY_FAILED, resourceType)); string fieldAlias = resourceType.ToResourceName() + "." + AppField; string fieldValue = Util.GetRandomText(textType, AlphabetValueMapper.AlphabetMapper[characterNumber]); resource = ResourceHelper.CreateUpdatedResource(resourceType, id, fieldAlias, fieldValue); var error = ResourceHelper.WriteResourceFail(resource, null); Assert.That(error, MustBe.MatchingErrorCode(Enums.PublicAPIResultCode.InvalidParameterValue), Enums.Message.WRONG_ERROR_CODE); }
/// <summary> /// Read search failed /// </summary> /// <param name="resourceType">Resource type</param> /// <param name="fieldAliases">Field alias</param> /// <param name="conditions">Condtion</param> public static void ReadFailed(Enums.ResourceType resourceType, string fieldAlias, string conditions) { Dictionary <string, object> urlParameters = new Dictionary <string, object>() { { "partition", AuthenticationInfoProvider.Current.DefaultPartition }, { "condition", $"{conditions}" }, { "field", $"{fieldAlias}" } }; ErrorCode result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadFail(resourceType.ToString(), urlParameters); Assert.That(result, MustBe.MatchingErrorCode(Enums.PublicAPIResultCode.ParameterIsInvalid), Enums.Message.WRONG_ERROR_CODE); }
public void TestUpdateSingleItem(ResourceType resourceType, string fieldName, string fieldValue, int expectedCode) { var phase = new Phase { Id = phaseEntryReader.Data[$"{resourceType.ToPrivateEnum()}{0}"].First().Id }; phase.DictionaryValues[fieldName] = fieldValue; var error = PhaseHelper.WritePhaseFail(phase); Assert.That(error, MustBe.MatchingErrorCode(expectedCode), Enums.Message.WRONG_ERROR_CODE); }
public void ItemStateReadInvalidInjectionTests(Enums.ResourceType resource, InjectionInput injection, int expectedCode) { var request = new Dictionary <string, object>() { [PropertyType.ItemState.ToLowerString()] = InjectionInputData.InjectionInputMapper[injection], [PropertyType.Partition.ToLowerString()] = AuthenticationInfoProvider.Current.DefaultPartition }; ErrorCode result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadFail(resource.ToString(), request); Assert.That(result, MustBe.MatchingErrorCode(Enums.PublicAPIResultCode.NotImplemented), Enums.Message.WRONG_ERROR_CODE); }