asiftasleem / nbuilder

Automatically exported from code.google.com/p/nbuilder
0 stars 0 forks source link

Guids should be true Guids, not sequential numbers #34

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
Use NBuilder to instantiate a single object (or list of objects) that has a
Guid field.

What is the expected output? What do you see instead?
Expected a unique Guid, but got a sequential Guid starting from 1, i.e.
00000000-0000-0000-0000-000000000001

What version of the product are you using? On what operating system?
NBuilder 2.1.9 Beta

Please provide any additional information below.
The Guids need to be random for testing NHibernate persistence. I'm using
it to auto-generate a bunch of objects to test that they are persisted to a
database correctly. The Guids need to be true Guids because I'm creating
the same objects over and over again and trying to save them, but
NHibernate is telling me that an object with the same Guid already exists
in the database.

Original issue reported on code.google.com by dft...@gmail.com on 20 Nov 2009 at 1:07

GoogleCodeExporter commented 8 years ago
This appears to be fixed or not broken.
The following code creates real GUIDs.

Builder<Product>
.CreateListOfSize(10)
.WhereAll()
.Has(p => p._Id = Guid.NewGuid())
.Build();

Original comment by dhirs...@gmail.com on 3 Dec 2009 at 6:54

GoogleCodeExporter commented 8 years ago
Hi

Thanks for reporting this, I will look into how this can be fixed. I 
purposefully
made it work this way but perhaps didn't consider the implications like this.

A workaround for now would be to inherit from SequentialPropertyNamer, override
GetGuid and just return Guid.NewGuid() instead.

Set the property namer using BuilderSetup.SetDefaultPropertyNamer()

Hope this helps until I get a proper fix.

Gareth

Original comment by garethdo...@googlemail.com on 12 Jan 2010 at 12:09

GoogleCodeExporter commented 8 years ago
A co-worker of mine made a case for why the GUIDs should remain sequential. You 
want
your test data to remain exactly the same each time it's generated so that you 
know
what the values will be each time. This would include GUIDs.

Perhaps adding some sort of flag to pick between real GUIDs and pseudo-GUIDs?
Although I have noticed that if I assign a GUID in the constructor of my object,
NBuilder won't replace it. Maybe another bug?

Original comment by dft...@gmail.com on 12 Jan 2010 at 6:24

GoogleCodeExporter commented 8 years ago
Hi dftian,

Did dhirshjr's suggestion of assigning the Guid using Guid.NewGuid() help at 
all to give you unique GUIDs? 

Also, I agree with your co-worker's defense of sequential GUIDs for unit tests 
that are the same every time, but I can also see how unique GUIDs would be 
important for persistence tests. Have you considered using Fluent NHibernate's 
PersistenceSpecification 
(http://wiki.fluentnhibernate.org/Persistence_specification_testing) to test 
your NHibernate persistence? Perhaps that combined with Guid.NewGuid() might 
serve you better?

Concerning properties assigned in the constructor being ignored...I believe 
that is a feature of NBuilder designed to respect the design of the class being 
built.

-Josh

Original comment by joshuajr...@gmail.com on 2 Dec 2011 at 3:07

GoogleCodeExporter commented 8 years ago
I wouldn't want to see see unique Guids whilst testing as this would make it 
hard to assert against a random id.

Original comment by rich...@wildesoft.net on 12 May 2012 at 6:55

GoogleCodeExporter commented 8 years ago
this will be achievable with the new conventions (added these stories to github)

Original comment by garethdo...@googlemail.com on 1 Feb 2013 at 4:44

GoogleCodeExporter commented 8 years ago

Original comment by garethdo...@googlemail.com on 1 Feb 2013 at 4:45