Case Insensitive comparison for collection against multiple options - nunit

I am trying to use NUnit to write an assertion that all the (string) members of a collection are one of a set of possibilities in a case insensitive manner. I thought I had figured it out, but it won't compile.
I thought this syntax would work:
Assert.That(new string[] { "red", "red", "red", "green" },
Is.All.AnyOf(new string[] { "RED", "BLUE", "GREEN" }).IgnoreCase);
However this errors with
'Constraint' does not contain a definition for 'IgnoreCase' and no
extension method 'IgnoreCase' accepting a first argument of
type 'Constraint' could be found (are you missing a using directive or an
assembly reference?)
The simpler test of a single item is one of a set of possibilities in a case insensitive manner works as expected.
Assert.That("red", Is.AnyOf(new string[] { "RED", "BLUE" }).IgnoreCase);
How should I phrase this assertion? Or is it a bug that this does not work?

You are running into the issue because of the order of precedence of the operations. You want the .IgnoreCase modifier to apply to the AnyOfConstraint, but it is being applied to the result of IsAll, which is a base level Constraint that doesn't support that modifier.
Barring changes to NUnit, you need a workaround. The simplest would appear to be
Assert.That(new string[] { "red", "red", "red", "green" },
new AllItemsConstraint(
Is.AnyOf(new string[] { "RED", "BLUE", "GREEN" }).IgnoreCase));
I haven't tried this, so check my syntax, spelling, etc.

Related

Multi-line problem matcher algorithm clarification - rollup matcher not working as expected

Can anyone clarify the exact algorithm used for the VS code multi-line problem matcher? Specifically curious what the behavior is when there are more than 2 patterns defined.
The context is that I'm trying to write a multi-line problem matcher in VS Code for a rollup task. A sample of the output would look like:
(!) Plugin typescript: #rollup/plugin-typescript TS2345: Argument of type 'FirstType' is not assignable to parameter of type 'SecondType'.
Types of property 'PropertyOne' are incompatible.
Type 'FirstType' is missing the following properties from type 'PropertyOne': X, Y
src/main/pathToFile/file.ts: (174:37)
I've tried a number of options. Here's the most recent attempt:
"pattern": [
{
"regexp":"^[(][!][)](.*)$",
"message": 1
},
{
"regexp":"^\\s+(.*)$",
},
{
"regexp": "^([^:\\s]+):\\s+\\((\\d+):(\\d+)\\)$",
"file": 1,
"line": 2,
"column":3
}],
I would expect this to match the output described, but it doesn't match at all.
If I remove the first pattern, I'm able to get a match, but this doesn't give me all of the information I need.

firestore query inside array values

Does firestore know how to query inside this structure for red shirts ?
Products:{
"prod_1_key": ["red","xl","shoes"],
"prod_2_key": ["blue","xs","hats"],
"prod_3_key": ["blue","xs","shirt"],
"prod_4_key": ["yellow","xxl","pants"],
"prod_5_key": ["green","xl","shirts"],
"prod_6_key": ["red","xxl","shirt"],
}
The only operation that Firestore has to [query an array field(https://firebase.google.com/docs/firestore/query-data/queries#array_membership) is arrayContains, which checks whether the exact item you pass to the query exists in a specifically named field. You can use at most one arrayContains operation in a query.
So you can check whether prod_6_key contains red, or prod_5_key contains shirt, but you can't check whether any of the 6 product fields contains both red and shirt.
To allow this query, consider adding a new field that combines the two values of each product that you want to search on. Say:
product_colors: [
{ color: "red", product: "shoes" },
{ color: "blue", product: "hats" },
{ color: "blue", product: "shirt" },
...
]
Now you can query this field with a single arrayContains for a red shirt.
Adding additional fields to allow a specific use-case is quite common in NoSQL databases. If you are new to this, I recommend checking out NoSQL data modeling and Getting to know Cloud Firestore.

Filter Lookup Results from values in Second Lookup in Azure Data Factory

I have two lookups within an Until activity in ADF. The first lookup (BookList) is a list of books that look like the JSON listed below.
[
{
"BookID": 1,
"BookName": "Book A"
},
{
"BookID": 2,
"BookName": "Book B"
}
]
The second lookup is a list of books that I want to exclude from the first list (ExcludedBooks) which is listed below.
[
{
"BookID": 2,
"BookName": "Book B"
}
]
After these two lookups, I have a Filter activity whose items are the values from BookList lookup. I would like the filter condition to be based on the BookID value not being listed in the ExcludedBooks values, but I'm not sure how to write this condition based on the collection functions in ADF. What I have is listed below which does not work.
#not(contains(activity('ExcludedBooks').output.value, item().BookID))
I realize one way to solve this is to loop through each record of the ExcludedBooks and use a SetVariable
activity to build an array of BookIDs which WOULD work with the collection function Contains(), but ADF does not allow nested activity groups for some reason (ForEach within an Until).
I also cannot set the list of excluded books outside of the Until activtity as it will change with each iteration of the Until activity. I also realize the workaround to the nested group activity restriction is to create a completely different pipeline, but that is not ideal and creates unnecessary complexity when trying to return the results.
Does anyone have any suggestions for how to filter the results of a lookup based on the results of another lookup?
Below expression doesn't work because item of activity('ExcludedBooks').output.value is object,item().BookID is number.
#not(contains(activity('ExcludedBooks').output.value, item().BookID))
If your each item in ExcludedBooks is the same as your item in BookList(like your provide sample),you can use this expression:#not(contains(activity('ExcludedBooks').output.value, item())).
My test result:
For another hand,if your item in ExcludedBooks like this json(BookList is the same as your provided):
[
{
"BookID": 2,
"BookName": "Book B",
"num": 22
}
]
you can only compare their BookID by using this expression:
#not(contains(join(activity('ExcludedBooks').output.value,','),concat('"BookID":',item().BookID,',')))
(cast activity('ExcludedBooks').output.value to string,concat item() in 'BookList' as "BookID":2, and check whether 'ExcludedBooks' string contains 'BookList' item string)
My test result:
Hope this can help you.

Orion Context Broker How to filter an object by name contains a keyword

We are using Orion Context Broker as our database.
Recently, We have meet an requirement that user want to find a City by name of this City container a keyword.
For example:
We have city name likes this. Hanoi, Madrid, London, Barcelona, Paris, Lyon.
If user type: "on", we should show Lyon, London.
The city object like this.
{
"type": "City",
"isPattern": "false",
"id": "city1",
"attributes": [
{
"name": "name",
"type": "string",
"value": "London"
}
]
}
So I am wondering if any queryContext filtering can help us to sort out this case.
I have done some research and there is no good sounds on this.
Many thanks.
You can use idPattern in GET /v2/entities which value is a regular expression. Thus the following query:
GET /v2/entities?idPattern=on
should return any City with the "on" substring in its id.
EDIT: if you want to apply a pattern to the value of some attribute, then you have to use q query parameter and the ~= NGSIv2 Simple Query Operator. Something like this:
GET /v2/entities?q=colour~=or
I have figured out that we use ~= operation to do that.
Please see the follow quote.
Match pattern: ~=. The value matches a given pattern, expressed as a regular expression, e.g. color~=ow. For an entity to match, it must contain the target property (color) and the target property value must match the string in the right-hand side, 'ow' in this example (brown and yellow would match, black and white would not). This operation is only valid for target properties of type string.
http://telefonicaid.github.io/fiware-orion/api/v2/stable/
Section: Simple Query Language
Many thanks.

How to use AND and OR when using Algolia's numerical filter

Consider an Algolia index filled with objects like this:
{
"objectID": 1,
"name": "My project title",
"contributor_ids": [12, 42, 34]
}
Does this query get all objects that have contributor_ids 42 OR contributor_ids=12 ?
"numericFilters: 'contributor_ids=42, contributor_ids=12"
And if so, what is the right query to get all objects that have contributor_ids 42 AND contributor_ids=12 ?
The default behavior is a AND, you can have a OR with parenthesis:
numericFilters: "contributor_ids=42, contributor_ids=12"
Means contributor_ids=42 AND contributor_ids=12, only match if you have a record containing both values
numericFilters: "(contributor_ids=42, contributor_ids=12)"
Means contributor_ids=42 OR contributor_ids=12
numericFilters: "contributor_ids=10,(contributor_ids=42, contributor_ids=12)"
Means contributor_ids=10 AND (contributor_ids=42 OR contributor_ids=12)