public void ReadInvalidGenericRecordTests(ResourceId resource, InvalidReadGenericRecord condition)
        {
            var recordHandler = new GenericRecordManager();
            var requestDic    = new Dictionary <string, object>()
            {
                ["resource"] = resource.GetHashCode(),
                ["idList"]   = new int[] { Common.ReadRecordsId(resource, FirstSystemRecord) },
                ["fields"]   = string.Format("{0}.P_PhaseDate,{1}.P_Name", resource.ToAlias(), resource.ToAlias())
            };

            if (condition == InvalidReadGenericRecord.NotLogin)
            {
                PrivateApiConnection.GetConnectionForCurrentTest().DeAuthenticate();
                var result = recordHandler.ReadRecord <ReadGenericRecordResponse.Error>(requestDic, HttpMethod.Post);
                PrivateApiConnection.GetConnectionForCurrentTest().Authenticate();
                PrAssert.That(result, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.Unauthorized));
            }
            else if (condition == InvalidReadGenericRecord.TransactionError)
            {
                // This case unable to reproduce at this time.
            }
            else if (condition == InvalidReadGenericRecord.WrongFieldId)
            {
                requestDic["idList"] = WrongId;
                var result = recordHandler.ReadRecord <ReadGenericRecordResponse.Error>(requestDic, HttpMethod.Post);
                PrAssert.That(result, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.InternalServerError));
            }
            else
            {
                requestDic["idList"] = null;
                var result = recordHandler.ReadRecord <ReadGenericRecordResponse.Error>(requestDic, HttpMethod.Post);
                PrAssert.That(result, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
            }
        }
Example #2
0
        public static bool CheckExistedRecordId(ResourceId resource, int[] recordId)
        {
            var requestDic = new Dictionary <string, object>()
            {
                ["resource"] = resource.GetHashCode(),
                ["idList"]   = new int[] { recordId.GetEnumerator().GetHashCode() },
                ["fields"]   = string.Format("{0}.P_Id,{1}.P_Name", resource.ToAlias(), resource.ToAlias())
            };

            var recordHandler = new GenericRecordManager();
            var result        = recordHandler.ReadRecord <ReadGenericRecordResponse.Success>(requestDic, HttpMethod.Post);

            return(result.IsSuccess ? false : true);
        }
Example #3
0
        private static void VerifyExistedId(ResourceId resource, List <string> ids)
        {
            var requestDic = new Dictionary <string, object>()
            {
                ["resource"] = resource,
                ["idList"]   = ids,
                ["fields"]   = $"{resource.ToAlias()}.P_Id"
            };
            var recordHandler = new GenericRecordManager();
            var response      = recordHandler.ReadRecord <ReadGenericRecordResponse.Success>(requestDic, System.Net.Http.HttpMethod.Post);

            PrAssume.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK));
            PrAssert.That(response.Result.Total, PrIs.EqualTo(0), "The record is not deleted out database.");
        }
        private void PerformTests(Dictionary <string, object> requestDic, HttpMethod method)
        {
            var recordHandler = new GenericRecordManager();
            var result        = recordHandler.ReadRecord <ReadGenericRecordResponse.Success>(requestDic, method);

            PrAssert.That(result, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK));
            var total    = result.Result.Total;
            var expected = requestDic["fields"].ToString().Split(',').Count();

            while (total > 0)
            {
                total--;
                PrAssert.That(result.Result.Items[total].Count, PrIs.EqualTo(expected));
            }
            ;
        }
Example #5
0
        private static void ReadAndVerifyData()
        {
            var fieldAliases = FieldNames.Aggregate((a, b) => $"{Resource.ToAlias()}.{a}" + "," + $"{Resource.ToAlias()}.{b}");

            var requestDic = new Dictionary <string, object>()
            {
                ["resource"] = Resource,
                ["idList"]   = SelectionRecordIds(Record, Filter, Resource, RecordCreator),
                ["fields"]   = fieldAliases
            };
            var recordHandler = new GenericRecordManager();
            var response      = recordHandler.ReadRecord <ReadGenericRecordResponse.Success>(requestDic, HttpMethod.Post);

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

            foreach (var fieldName in FieldNames)
            {
                foreach (var item in response.Result.Items.Select(item => item[$"{Resource.ToAlias()}.{fieldName}"].ToString()))
                {
                    var fieldType = GetFieldTypes();
                    if (Filter == Filters.Append && (fieldType[fieldName].ToString().ContainsStrings(new string[] { InputType.SingleLineText.ToString(), InputType.MultiLinesText.ToString() })))
                    {
                        PrAssert.That(item, PrIs.EqualTo($"{Fields[fieldName]} {Fields[fieldName]}"));
                    }
                    else
                    {
                        if (fieldType[fieldName].ToString().ContainsStrings(new string[] { InputType.UserList.ToString(), InputType.OptionMultipleItems.ToString() }))
                        {
                            PrAssert.That(item.Contains(Fields[fieldName].ToString().Split(',')[0]) && item.Contains(Fields[fieldName].ToString().Split(',')[1]));
                        }
                        else
                        if (fieldType[fieldName].ToString().ContainsStrings(new string[] { "System", InputType.OptionPhase.ToString(), InputType.OptionOnlyItem.ToString() }))
                        {
                            PrAssert.That(item.Contains(Fields[fieldName].ToString()));
                        }
                        else
                        {
                            PrAssert.That(item, PrIs.EqualTo(Fields[fieldName]));
                        }
                    }
                }
            }
        }