Fluent Assertions message for mismatched item in a collection comparison - fluent-assertions

I am comparing two collections using fluent assertions and given that number of items match but the item property values don't match, i get messages saying Expected item[2].Required to be False, but found True. Now what i am looking to do is to rather than saying item[2].Required it should say name.Required, i.e. i want to some how use one of the properties to be used in message so that i can straight away know that which item is it talking about. at the moment i have to look for the item in the table at that index to see which item is not matching , which becomes bit inconvenient when there are so many of them.
For e.g. comparing collections with following class where expected collection has say 5 elements with "Name" property set to A,B,C,D and E. I want to make fluent assertions tell me that A.Required or B.Required or C.Required is expected to be something but its something else and A.Address is expected to be something but it is something else B.Address is... and so on, instead of saying item[0].Required is expected to be something but its something else item[1].Required is expected to be something but is something else and so on.
public class Element
{
public string Name {get;set;}
public Required {get;set;}
public Address {get;set;}
}
I tried looking for some answers but don't know what exactly to search for.
Please let me know if i can make question bit more clear if it isn't
Thanks

You could enable tracing for more details with
actual.Should().BeEquivalentTo(expected, options => options.WithTracing());
And then if you would override ToString() on your Element you get your desired details in the trace.

Related

How can I get all of the properties related to one node type?

I have a node Country. I know that this node has some properties, but I don't know which. I mean, I know since I've take a look at model. Here is what I've found in documentation:
Country
name: String
iso_2_code: String
iso_3_code: String
region: String
sub.region: String
I know that if I run
MATCH (c:Country)
RETURN c.iso_2_code
I'll get result for one specific property. Is there a query that would as a result return me something like: name, iso_2_code, iso_3_code, region, sub.region?
If I didn't have access to the model how could I list all of the properties that are attached to some node type?
Answering more from a Cypher or openCypher perspective than for a specific implementation. Using the air-routes dataset. There are three things to consider.
Firstly if you know the properties you want, as you mentioned, you can just ask for them explicitly.
MATCH (a:airport {icao:'KDFW'})
RETURN a.city, a.desc
However, if you want all properties, but do not want to list them all, you can just do:
MATCH (a:airport {icao:'KDFW'})
RETURN properties(a)
If you just want the property keys:
MATCH (a:airport {icao:'KDFW'})
RETURN keys(properties(a))
Lastly, if you want the properties plus the label and ID information you can just do:
MATCH (a:airport {icao:'KDFW'})
RETURN a

What is the correct term for a "universal accessor"

In the active record pattern and in the builder pattern one may encounter so called "fluid" methods with non-verb names such as
public function carRadio(...);
public function driver(...);
The ellipsis (...) indicates zero or more arguments.
The purpose of the above is brevity. Sometimes exposing a public property is enough, but sometimes you want to do more stuff than simply assign an object.
e.g.
$kid = Kindergarden::find(33);
$kid->food($carrot);
assert($carrot == $kid->food());
Roughly, this means give some food to the child, but in the food method you may want to check for allergies or some such.
A bulilder-pattern example could look like:
$threeThousandWatts = Generator::create();
$threeThousandWatts->wires($w)->fuel($gas)->schedule($timeSlot);
...you get the idea.
The question is, what do you (literature you have read) call a mutator that is also a an accessor?
PS. This is not a for a public API. It's just a generic question.

A function that will convert input string to the actual object

I am unsure how to describe what I am looking for, so hopefully the situation will make it somewhat clear.
I have an object with a number of properties (let's say object.one, object.two, object.three). There are about 30 of these properties and they all hold a string ("Pass" or "Fail").
Right now the existing code checks whether the property has value "Pass" or "Fail" and then runs some code that prints stuff out. That is, the same snippet of code is duplicated 30 times, one for each of these properties.
The code looks something like this
If (object.one = ... )
...
End if
If (object.two = ... )
...
End if
If (object.three = ... )
...
End if
I want to use a loop to clean this mess up (each block is huge), but am not sure how to do it. I was thinking perhaps there was a way such that I might be able to construct a string like "object.one" and run some function that will tell the compiler that this is actually an object's property?
That way I could create an array containing the object's name like my array = {"object.one", "object.two", "object.three"} and then do something like, in pseudocode
For each string in my array
If (some_function(string) = ...)
...
End If
Essentially, it would take those massive blocks of duplicated code and reduce it to just one block. Is there such a some_function that I am looking for?
This is in VB.net.
I'm not sure i've understand but you can use reflection and get object properties runtime ?
With reflection you can access public object properties, use PropertyFiled.GetValue() to get one, two, etc. and build an array (i suppose that one, two, etc are object Properties, true?)
Here you can find more information: http://msdn.microsoft.com/en-us/library/system.reflection.aspx
Sorry for my bad english, i'm italian.
You seem to be describing serialization, which is the act of converting object state to a format that can be stored/transmitted and deserialization, which is the opposite.
The .NET framework has several different serializers that can work with text - either XML or JSON - the DataContractSerializer for XML and the DataContractJsonSerizlizer for JSON amongst them.

C# Dynamic Type in a GenericCollection Property

I have a control mycontrol.ascx
This control has a property:
private GenericCollection<Item> myCollection;
public GenericCollection<Item> MyCollection
{
get { return myCollection; }
set { myCollection= value; }
}
Does anyone know how i could dynamically change from type Item to say type Product?
You can't. One of the main ideas with generics is that they are type safe. If you want to be able to alter which type that is stored MyCollection, you will need to use some type from which both Item and Product are derived.
As you have specified C# 2.0 then I think the answer will be that you can't. C# is statically typed and this code types the generic collection to a collection of Item. If Product were a superclass of Item then I believe you could store them in this collection but you'd need to query the object type when you retrieved it from the collection as it'll always come back as an Item.
I'll throw a question back at you, what are you trying to achieve in this dynamic replacement and why? There may be a better answer.
EDIT
Thinking about it further, following the comment, you might be able to do it using an interface, i.e.:
public IList myCollection { get; set; }
I haven't tried it, away from my dev station but might spark some others to either agree or correct me :)

Complex Searching with NHibernate

I am curious about what methods do you use for complex searching with NHibernate ?
I am using Ayende's
What is yours ?
Thanks for your advices and answers.
If we have a complex dynamic search, we will usually construct a SearchParameter object and then pass that into a method that will build our criteria for us.
For example, if we were searching for a person we might have a search object that looks like this:
public class PersonSearchParameters
{
public string FirstName {get; set;}
public string LastName {get; set;}
public ICriteria GetSearchCriteria()
{
DetachedCriteria query = DetachedCriteria.For(typeof (Person));
//Add query parameters
Return query;
}
}
Then for each type of search, we'll be able to create the single criteria from the class, or we could have multple search parameter classes and chain them together
We use HQL, but we're still trying to wrap our heads around the Criteria API for complex queries. We have to manage a lot of duplication when using HQL.
I use pretty much Ayende's too jsut a bit more complex, what do you want to do that you cant do with that?
Basically what we added is that we have an interface where we define all the fields where we want to search and we call this when we are about to make the search which means that we can easily change what we are searching for.
Also we are using Active Record in the project ( on top of Hibernate) and tis pretty cool, loads of tasks gets simplified , thou the lack of docs does hurt sometimes
Cheer