OR operator for postman - postman

I treat the test result as pass either field A is "A" or field B is "B". How can i achieve that in postman?
I tried
(pm.expect(responseJson.output.generic[0].fieldA).to.eql(pm.iterationData.get("A"))||pm.expect(responseJson.output.generic[0].fieldB).to.eql(pm.iterationData.get("B")))

You can try
pm.expect(cond1 || cond2).to.be.true;
In your case, I think that would be something like
pm.expect(
responseJson.output.generic[0].fieldA === pm.iterationData.get("A") ||
responseJson.output.generic[0].fieldB === pm.iterationData.get("B")
).to.be.true;

Related

JMeter - How can I use multiple conditions in IF Controller?

Here is my code:
In If Controller -> Condition (Default Javascript) I am providing following
"${responsecode}" == "404" || "${responsecode}" == "500" && "${responseMessage}" == "Not Found"
Yes you can, assuming your current condition SMTP Sampler will be executed:
If ${responsecode} variable is 404
OR
If ${responsecode} variable is 500 AND ${responseMessage} variable is Not Found
I doubt that you will get Not Found message given Response Code 500, most likely you will get an Internal Server Error there so maybe you should amend your condition to look like:
"${responsecode}" == "500" || ("${responsecode}" == "404" && "${responseMessage}" == "Not Found")
In case when If Controller doesn't behave as expected first of all check jmeter.log file for any JavaScript-related errors, it will give you some clue regarding what's wrong with your setup. You can also use __javaScript() function and View Results Tree listener combination to visualize the result of your If Controller condition:
See How to Use JMeter's 'IF' Controller article for more details on conditionally running samplers via If Controller.

Update value in soy template declared with let

I have one value that is tied to a flag that comes from a config file that I need to show in my soy template. It is either true or false.
If true, the value needs to be "x" (for example, but it is a string)
If false, the value needs to be "" (empty)
Notice that I cannot pass in the true or false value from my config. I also cannot omit the value on false, it has to supply an empty string.
I've tried various forms of if statements using let, but according to my interpretations of the docs, a value declared with let cannot be changed (which doesn't make sense)
This is basically what I need:
{if $inputValue.value == 'true'}
{let $myVar: ($someValueThatExistsInMyTemplate) /}
{else}
{let $myVar: '' /}
{/if}
Then I will use $myVar in my template. However, whenever I try that, I get this error:
Found references to data keys that are not declared in SoyDoc: [myVar]
What can I do!?
Got it working using the ternary operator:
{let $dataParent: ($item.preferences.accordionOnOff.value == 'true') ? ($item.name) : '' /}

How could you unit test against this bad Linq-To-SQL predicate?

Given the following example code:
Table<Person> tableToQuery = MethodThatGetsReferenceToPersonTable();
string searchType = "NonUser";
IQueryable<Person> queryResults = tableToQuery.Where(p =>
(p.IsMale == false) && // exclude male people
type.Equals("User", StringComparison.OrdinalIgnoreCase)
? p.User != null : p.User == null);
I am new to L2S, but do have some of experience with EntityFramework. I would not expect the above query to work correctly in an ORM like EF because of the type.Equals that gets invoked in the predicate's ternary expression. I would instead expect EF to throw an exception since it cannot convert that part of the predicate into a (SQL) store expression.
With L2S, it seems that the .Where is returning data, but it is not excluding items where p.Male == true when type == "NonUser. I have already fixed the code above to pull the type.Equals ternary out of the predicate and return correct results, and am now trying to write a test to assert the correct results. The problem I am running into is that the L2S code is actually behind an IRepository<Person> interface.
So the actual code looks more like this:
string searchType = "NonUser";
ICriteria<Person> query = new Query<Person>(p =>
(p.IsMale == false) && // exclude male people
type.Equals("User", StringComparison.OrdinalIgnoreCase)
? p.User != null : p.User == null);
IQueryable<Person> = _peopleRepository.FindByQuery(query)
...and the _peopleRepository implementation just passes the query.Predicate as an argument to the L2S Table<Person>.Where.
Questions:
Is it correct that the L2S Table<Person>.Where is not returning the correct results because of the ternary expression in the lambda predicate? I assume so since taking the ternary out an generating separate ICriteria<Person> objects depending on the value of searchType is yielding correct results. However I am not so certain if this is because L2S cannot convert the ternary into a store expression, or if it is caused by something else.
Since the method under test depends on a IRepository<Person> instance, how could I actually write a unit test around this? Mocking the IRepository<Person> in a unit test would not allow us to test the effects of the lambda on real underlying data. Creating a FakePersonRepository backed by some kind of IList<Person> would not reveal the actual defect either because the above lambda with the ternary expression returns expected results using linq-to-objects. Is there any way we could mock part of L2S so that we can possibly generate SQL using the lambda, and write assertions against that instead?
Is this just something we have to do with an integration test and an actual L2S context with connection string, and cannot properly unit test? My definition of "integration test" means "connect to an actual database running in a separate process from the test runner using some kind of connection string", whereas "unit test" means "do everything in the test runner process".
Is it correct that the L2S (...) is not returning the correct results
It does return correct results, but not the results you expect, because you read the query as a human being and not as a compiler. The latter reads this:
tableToQuery.Where(p =>
((p.IsMale == false) && type.Equals("User", StringComparison.OrdinalIgnoreCase))
? p.User != null
: p.User == null);
We humans tend to read this:
tableToQuery.Where(p => (p.IsMale == false) &&
(type.Equals("User", StringComparison.OrdinalIgnoreCase)
? p.User != null
: p.User == null));
2./3. how could I actually write a unit test around this?
Mocking and unit testing is virtually impossible. I stick to integration tests when I want to test the behavior of a data layer. For Entity Framework I collected some reasons for integration tests here. Much of it applies too LINQ-to-SQL as well.

ASP.NET Web API 2 Model Validation with Regular Expression

In my web api 2 Controller i have a Create method that contains the following logic:
if (((assignment.type).ToLower() != "individual" && (assignment.type).ToLower() != "staff")) {
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "The Assignment Type
must be either 'individual' or 'staff'");
}
I am using model state validation. Is it possible to assign a regular expression to a property to eliminate the need to do the checking in the controller? If so, what would that reg ex look like to return valid only if the exact string (case insensitive) of "individual" or "staff" is passed by the user of the api?
Thanks to some guidance in the comments, I ended up with this, which works well:
[RegularExpression(#"^(?i)(individual|staff)$", ErrorMessage="...")]
public string type { get; set; }
If you want a Regex than use something like
new Regex(#"^(individual|staff)$", RegexOptions.IgnoreCase)
But, I would recommend to create an enum with corresponding values and make your model property of that enum.

accessing session data

I am setting a custom session in the catalog/controller/checkout/cart.php controller. All it does, it checks if a value is set or not.
if (isset($this->request->post['no_tax']) && $this->request->post['no_tax'] == '1')
{
$this->session->data['no_tax'] = true;
}
elseif (isset($this->request->post['no_tax']) && $this->request->post['no_tax'] === '0')
{
unset($this->session->data['no_tax']);
}
I can then access this in the catalog/model/shipping/totalbased.php model file,
isset($this->session->data['no_tax'])
The problem is, I need to send additioanl information in the order to the admin, which is done in the catalog/model/checkout/order.php
I've done a check in there:
if(isset($this->session->data['no_tax']) )
{
//do something
}
$mail->send();
The do something, simply adds a PDF. The problem is, the PDF isn't attached.
In the error.txt, I get: 2012-05-14 14:42:11 - PHP Notice: Undefined index: no_tax in /var/www/vhosts/site.com/httpdocs/catalog/order.php
Can I access the session this way?
Thanks
The code looks fine from what I can see, and yes you can access the data like you've shown. The error you've had looks like you have tried to access the session data directly at some point without checking it's set, causing the notice