public void TestSearchOptionInvalidFieldOrder(ValidOptionField optionField, InvalidOptionOrder optionOrder) { OptionManager optionHandler = new OptionManager(); Dictionary <string, string> requestDic = new Dictionary <string, string>() { ["order"] = $"{ValidFieldMapper[optionField]}:{InvalidOrderMapper[optionOrder]}", }; var response = optionHandler.SearchOption(requestDic); PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(HttpStatusCode.BadRequest).And.ErrorCode((int)ResultCode.InvalidValue), $"Still able to search option with both field = {optionField.ToString()} and order = {optionOrder.ToString()}"); }
public void TestSearchOptionFieldInvalidType(ValidOptionField optionField, InvalidOptionType optionType) { OptionManager optionHandler = new OptionManager(); Dictionary <string, string> requestDic = new Dictionary <string, string>() { ["columns"] = ValidFieldMapper[optionField], ["type"] = InvalidTypeMapper[optionType], }; var response = optionHandler.SearchOption(requestDic); PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(HttpStatusCode.BadRequest).And.ErrorCode((int)ResultCode.InvalidValue), $"Still able to search option with both field = {optionField.ToString()} and type = {optionType.ToString()}"); }
public void TestSearchOptionFieldOrder(ValidOptionField optionField, string optionOrder) { OptionManager optionHandler = new OptionManager(); Dictionary <string, string> requestDic = new Dictionary <string, string>() { ["columns"] = ValidFieldMapper[optionField], ["order"] = ValidFieldMapper[optionField] + ":" + optionOrder, }; var response = optionHandler.SearchOption(requestDic); PrAssert.That(response, PrIs.SuccessfulResponse()); }
public void TestSearchOptionFieldType(ValidOptionField optionField, OptionType optionType) { OptionManager optionHandler = new OptionManager(); Dictionary <string, string> requestDic = new Dictionary <string, string>() { ["columns"] = ValidFieldMapper[optionField], ["type"] = ((int)optionType).ToString(), }; var response = optionHandler.SearchOption(requestDic); PrAssert.That(response, PrIs.SuccessfulResponse()); PrAssert.That(response.Result, PrIs.Not.Null.And.Not.Empty); var listType = response.Result.SelectMany(r => r.ContainsKey("children") ? r.Children?.Select(c => c.ContainsKey("type") ? c["type"] : "") : new List <Object> { "" }).ToList(); listType.RemoveAll(c => c.Equals("")); PrAssert.That(listType, PrIs.All.EqualTo(((int)optionType)), "Found a different type in the search result"); }
public void TestSearchOptionField(ValidOptionField optionField) { OptionManager optionHandler = new OptionManager(); Dictionary <string, string> requestDic = new Dictionary <string, string>() { ["id"] = PrepareUpdatedOption.Data.Id.ToString(), ["self"] = "true", ["columns"] = ValidFieldMapper[optionField], }; var response = optionHandler.SearchOption(requestDic); PrAssert.That(response, PrIs.SuccessfulResponse()); PrAssert.That(response.Result, PrIs.Not.Null.And.Not.Empty); var actualOption = response.Result.SingleOrDefault(); PrAssert.That(actualOption, PrIs.Not.Null.And.Not.Empty); if (optionField == ValidOptionField.CreatedById || optionField == ValidOptionField.CreatedByName) { PrAssert.That(actualOption.ContainsKey(ValidFieldMapper[optionField].Split('.')[0]), PrIs.EqualTo(true), $"The result doesnt contain key {ValidFieldMapper[optionField].Split('.')[0]}"); PrAssert.That(actualOption.CreateBy.ContainsKey(ValidFieldMapper[optionField].Split('.')[1]), PrIs.EqualTo(true), $"The result doesnt contain key {ValidFieldMapper[optionField].Split('.')[1]}"); PrAssert.That(actualOption.CreateBy[ValidFieldMapper[optionField].Split('.')[1]], PrIs.EqualTo(1).Or.EqualTo("Test Tester"), $"The result actual value is {actualOption.CreateBy[ValidFieldMapper[optionField].Split('.')[1]]}"); } else if (optionField == ValidOptionField.UpdatedById || optionField == ValidOptionField.UpdatedByName) { PrAssert.That(actualOption.ContainsKey(ValidFieldMapper[optionField].Split('.')[0]), PrIs.EqualTo(true), $"The result doesnt contain key {ValidFieldMapper[optionField].Split('.')[0]}"); PrAssert.That(actualOption.UpdateBy.ContainsKey(ValidFieldMapper[optionField].Split('.')[1]), PrIs.EqualTo(true), $"The result doesnt contain key {ValidFieldMapper[optionField].Split('.')[1]}"); PrAssert.That(actualOption.UpdateBy[ValidFieldMapper[optionField].Split('.')[1]], PrIs.EqualTo(1).Or.EqualTo("Test Tester"), $"The result actual value is {actualOption.UpdateBy[ValidFieldMapper[optionField].Split('.')[1]]}"); } else if (optionField == ValidOptionField.All) { foreach (var field in Enum.GetValues(typeof(ValidOptionField)).Cast <ValidOptionField>().Where(v => v != ValidOptionField.All)) { PrAssert.That(response.Result.Select(r => r.ContainsKey(ValidFieldMapper[field].Split('.')[0])), PrIs.All.EqualTo(true), $"{field} cannot be found"); } } else { PrAssert.That(response.Result.Select(r => r.ContainsKey(ValidFieldMapper[optionField])), PrIs.All.EqualTo(true), $"{optionField} cannot be found"); } }