Giter VIP home page Giter VIP logo

nbuilder's People

Contributors

jjroth avatar

nbuilder's Issues

Multiple WhereRandoms will conflict with each other and take items from each other's declarations

This test fails.


[Test]
        public void Where_random_test()
        {
            var items = Builder<MyClass>.CreateListOfSize(40)
                .WhereRandom(10)
                    .Have(x => x.EnumProperty = MyEnum.EnumValue1)
                .WhereRandom(10)
                    .Have(x => x.EnumProperty = MyEnum.EnumValue2)
                .WhereRandom(10)
                    .Have(x => x.EnumProperty = MyEnum.EnumValue3)
                .WhereRandom(10)
                    .Have(x => x.EnumProperty = MyEnum.EnumValue4)
                .Build();

            Assert.That(items.Count(), Is.EqualTo(40));
            Assert.That(items.Count(x => x.EnumProperty ==
MyEnum.EnumValue1), Is.EqualTo(10));
            Assert.That(items.Count(x => x.EnumProperty ==
MyEnum.EnumValue2), Is.EqualTo(10));
            Assert.That(items.Count(x => x.EnumProperty ==
MyEnum.EnumValue3), Is.EqualTo(10));
            Assert.That(items.Count(x => x.EnumProperty ==
MyEnum.EnumValue4), Is.EqualTo(10));
        }


Original issue reported on code.google.com by [email protected] on 11 Jun 2009 at 8:01

SequentialGenerator to Support DateTime

What steps will reproduce the problem?
1. var lastModDateGenerator = new SequentialGenerator<DateTime>();
2. lastModDateGenerator.StartingWith(DateTime.Parse("2009-01-13 
00:00:00"));

What is the expected output? What do you see instead?
I would expect not receive an Exception, we should be able to use the same 
pattern for incrementing DateTime values.  Instead I get an exception 
because currently DateTime types are not supported.


What version of the product are you using? 2.1.8 On what operating system? 
WinXP

I've updated the file (i just added Ext to the end of the class name) in 
case you want to use it.


Please provide any additional information below.


Original issue reported on code.google.com by scott.w.white on 25 Jun 2009 at 9:34

Attachments:

BuilderSetup.SetPropertyNamerFor<T> does not prevent auto naming properties of some types (probably nesting or something with generics)

What steps will reproduce the problem?
1. Downaload SharpArch's binaries from
http://code.google.com/p/sharp-architecture/ and include them in your project
2. Create your own "Foo" Class that derives from Entity
3. Create a test:
{
 BuilderSetup.DisablePropertyNamingFor<Foo, int>(x => x.Id);
 var output = Builder<Product>.CreateNew().Build().Id;

What is the expected output? What do you see instead?
output = 0; instead: output = 1.

What version of the product are you using? On what operating system?
2.1.8, Vista

Please provide any additional information below.
SharpArch's Entity is inheritance tree looks like this: 

IEntityWithTypedId<TId> (Contains definition: Idt Id { get; }
  -> EntityWithTypedId<IdT> ( contains: public virtual IdT { get; protected
set;}
     -> Entity 
          -> Your custom class like Foo

The problem is with ShouldIgnoreProperty method on BuilderSetup class which
only checks whether propertyInfo that is being currently examined exists in
the disabledAutoNameProperties collection. It uses default Contains()
method on it and I see no comparer specified explicitly, so that means, the
Equals() method of PropertyInfo class is being used to determine equality.
Reflector didn't show me any Equals implementation neither PropertyInfo
class or any base class that derives from. 

I do not really understand why for normal classes (not derived from those
SharpArch's Core) current implementation works, however I this couple of
lines solves my problem:

public static bool ShouldIgnoreProperty(PropertyInfo info)
        {
            foreach(var propertyInfo in disabledAutoNameProperties)
            {
                if (propertyInfo.Name.Equals(info.Name) &&
                    propertyInfo.PropertyType.Equals(info.PropertyType) &&
                    propertyInfo.DeclaringType == propertyInfo.DeclaringType)
                    return true;
            }

            return false;
        }

Original issue reported on code.google.com by [email protected] on 22 Jun 2009 at 5:50

Attachments:

FluentInterface broken

What steps will reproduce the problem?
1. Builder<>.CreateNew() returns an ISingleObjectBuilder<>
2. all relevant methods are in IObjectBuilder<>
3. If I want to specify e.g. constructor args I have to cast the Result of 
CreateNew which breaks the nice FluentInterface

What is the expected output? What do you see instead?
I's expect intellisense to tell me what's possible after typing CreateNew
(), instead I see only Build(). When I write CreateNew().WithConstuctorArgs
() I get build errors.

What version of the product are you using? On what operating system?
2.1.8.0 on XP SP3, VS2005 clr 2.0.50727

Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 17 Aug 2009 at 11:24

Patch To Add Feature To ExtensibleRandomValuePropertyNamer -- Expose Member Info To Namer Delegates

Please accept the attached patch -- an enhancement to the
ExtensibleRandomValuePropertyNamer.  I found a use case where I would like
the custom namer delegate to know about the member being set.  Fortunately
this was a very small and simple change.

One can imagine lots of uses for this.  In my case I have some classes that
are use Data Annotation attributes for validation.  For string members
decorated with the StringLength attibute, I want to set the value to the
max allowed string length.

Original issue reported on code.google.com by [email protected] on 19 Mar 2010 at 10:45

Attachments:

UniqueRandomGenerator is missing one value on Enums

What steps will reproduce the problem?
  class enum TestEnum { One, Two, Three, Four }
  var randomUnique = new UniqueRandomGenerator();
  for (int i=0; i<4; i++)
Console.WriteLine(randomUnique.Enumeration<TestEnum>();


What is the expected output? What do you see instead?
 Expected 4 items, fails with "There are no more unique values available"
on the 4th call.

What version of the product are you using? On what operating system?
v2.1.9.0
Windows XP


Please provide any additional information below.
The problem seems to be with the rangeSize parameter being passed through
as min-max which is one less than expected.

Original issue reported on code.google.com by [email protected] on 6 Apr 2010 at 5:50

Patch

Hi, 

I attached a small patch for some issues I had with creating value objects
where I wanted to test whether the constructor could throw an
ArgumentException. This resulted in a TargetInvocationException being
thrown instead of the exception thrown in the constructor.

Second, I added a new method for using single constructor arguments that I
wanted to set to a null reference. Using the method taking the 'params
Object[]' resulted in an exception being thrown when not casting to a
intented type (added a test for that as well).

Hope you like it.

Original issue reported on code.google.com by [email protected] on 26 Jun 2009 at 10:38

Attachments:

Seed for Random Date

When generating random generated data, is it possible to set the random seed, 
this way any tests that fail can be repeated with the same data

Original issue reported on code.google.com by [email protected] on 4 May 2010 at 4:10

NBuilder.org contact form broken

What steps will reproduce the problem?
1. http://www.nbuilder.org/Contact
2. Fill in Form and submit
3. See Runtime Error occur

I've searched far and wide on the internets and the contact form and this issue 
tracker seems to be the only two ways you've supplied for having people contact 
you.

Can you please fix the contact form so that it is possible to contact you?

Also, I'd like to contact you so I can offer my assistance in helping out 
fixing NBuilder issues as it has been a long time since the last release and 
I'd like to get a couple of my issues resolved and try to help fix others.

Please email me on joshuajroth<REMOVEME>@gmail.com if you'd like me to help.

Original issue reported on code.google.com by [email protected] on 25 Aug 2010 at 12:50

Suggestion: Default properties


It would be nice to be able to specify default properties for a type. I
presume nbuilder currently sets property defaults based on the type of the
property.

Usually I want to create an object with all properties defaulted and one or
two properties set specifically. 

Original issue reported on code.google.com by [email protected] on 23 Sep 2009 at 12:37

RandomItemPicker bug - will never choose last item in list.

What steps will reproduce the problem?
1. Declare a small array of items
2. Call the Pick<T>.RandomItemFrom method a large number of times (i.e. 
using CreateListOfSize() with a large number
3. The last item in the list will be picked.

Original issue reported on code.google.com by kevinkuebler on 28 May 2009 at 3:55

Guids should be true Guids, not sequential numbers

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 [email protected] on 20 Nov 2009 at 1:07

Ignoring property in inherited class

Ignoring a property doesn't work if it's inherited from a base class, for
example if you have the ID property in a entity base class or use the
Fluent NHibernate Entity class.

Replacing the ShouldIgnoreProperty method in BuilderSetup.cs with this will
fix it.

public static bool ShouldIgnoreProperty(PropertyInfo info)
        {
            foreach (var property in disabledAutoNameProperties)
            {
                if (property.DeclaringType.Equals(info.DeclaringType))
                    return true;
            }

            return false;
        }

Original issue reported on code.google.com by [email protected] on 7 Jul 2009 at 7:18

should verify GetGetMethod != null

What steps will reproduce the problem?
1. Put an object with a Property (Units) and a set only ( write only property)
2. try to construct with nbuilder
3. trace is 
Units threw an exception when attempting to read its current value

In the code at Property Namer it is:

 if (memberInfo is PropertyInfo)
            {
                try
                {
                    currentValue = ((PropertyInfo)memberInfo).GetValue(obj,
null);
                }
                catch (Exception)
                {
                    Trace.WriteLine(string.Format("{0} threw an exception
when attempting to read its current value", memberInfo.Name));
                }
            }

Please verify that get method exists :
  try
                {
if((PropertyInfo)memberInfo).GetGetMethod != null)
{

                    currentValue = ((PropertyInfo)memberInfo).GetValue(obj,
null);

}
                }

Original issue reported on code.google.com by [email protected] on 24 Jul 2009 at 10:04

AreConstructedUsing with Child Class Constructor Generates Parent Type

What steps will reproduce the problem?
1. Class model...
public class Parent {}
public class Child : Parent {}

2. Statement in question
var children = Builder<Parent>.CreateListOfSize(3)
                                .WhereAll()
                                  .AreConstructedUsing(() => new Child())
                                .Build();

What is the expected output? What do you see instead?
I expect a list of Parent type containing Child type instances.  Instead 
there is a list of Parent type containing Parent type instances.

What version of the product are you using? On what operating system?
2.1.9.0

Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 16 Feb 2010 at 12:02

Add singular versions of Have(xyz) methods

You should be able to do this:

Builder<Product>.CreateListOfSize(10).WhereTheFirst(1).Has(x => x.Title =
"TheTitle").Build();

Need to have singular versions of:

Have() -> Has()
HaveDoneToThem() -> HasDoneToIt()

And any others I've missed here.

Original issue reported on code.google.com by [email protected] on 29 May 2009 at 3:30

When creating List there doesn't seem to be a way to set the properties on the remaining items?

From the documentation on how to create lists I can see the following:

var list = Builder<Product>
.CreateListOfSize(30)
.WhereTheFirst(10)
    .Have(x => x.Title = "Special Title 1")
.AndTheNext(20)
    .Have(x => x.Title = "Special Title 2")
.Build();

What I'd like to see is the ability to do the following:

var list = Builder<Product>
.CreateListOfSize(30)
.WhereTheFirst(10)
    .Have(x => x.Title = "Special Title 1")
.AndTheRemaining()
    .Have(x => x.Title = "Special Title 2")
.Build()

This way I don't have to ensure that I hard code the exact remaining amount. 

Perhaps there is some syntax that will already do this for me?

Obviously this is a low priority since there is already a workaround...but
I thought it wouldn't hurt to make a suggestion...

Original issue reported on code.google.com by [email protected] on 17 Feb 2010 at 1:13

Population of properties declared as nullable types

1. Create a custom class with a nullable type property, e.g.
public class Foo
{
    public int Bar { get; set; }
    public int? Gum { get; set; }
}

2. Create an instance of this class with NBuilder, eg..

var foo = Builder<Foo>.CreateNew().Build();


The resulting object has Bar set to 1, but Gum is set to null. I would
expect Gum to have a non-null value assigned, e.g. (int?)1

NBuilder version 2.1.9 (beta) on Windows XP SP2 32 bit.

Original issue reported on code.google.com by [email protected] on 28 Jan 2010 at 12:26

Pick<>.RandomItemFrom() picks the same item when creating a list

This test fails.

[Test]
        public void WhenUsedInContextRandomItemPickerShouldPickDifferentItems()
        {
            var stringList = new List<string>();

            for (int i = 0; i < 100; i++)
                stringList.Add("string"+i);

            var strings = stringList.ToArray();

            var vehicles =
                Builder<MyClass>
                    .CreateListOfSize(10)
                    .WhereAll()
                    .Have(x => x.StringOne =
Pick<string>.RandomItemFrom(strings))
                .Build();

            var list = vehicles.Select(x => x.StringOne);

            var distinctList = list.Distinct();
            Assert.That(distinctList.Count(), Is.GreaterThan(1));
        }


Original issue reported on code.google.com by [email protected] on 21 May 2009 at 6:28

Support DDD Scenarios

Please apply this patch.  I have been pondering this for some time and was 
moved to action when I saw this Alt.Net thread today:

  http://tech.groups.yahoo.com/group/altdotnet/message/24168

I planned to suggest using NBuilder, but then I realized NBuilder doesn't 
really support that scenario.

I might term this scenario "DDD" -- entity properties with no public setters 
and a public a c-tor that takes all invariants.  This pattern poses a testing 
challenge -- how to set up entities to a certain state for unit tests without 
going through a lot of business logic during setup.  

This patch makes it easy by doing two things:

1. Support construction of objects with a parameterless c-tor that is private
2. Add WithPrivate method of ISingleObjectBuilder for setting properties with 
private setter

Original issue reported on code.google.com by [email protected] on 10 Sep 2010 at 2:59

Attachments:

New override for GetRandom.Phrase() ?

I'm wondering if this could be considered as an enhancement for this project :-

GetRandom.Phrase(int minNumCharacters, maxNumOfCharacters)

eg.
GetRandom.Phrase(10, 50);

Currently, I'm doing a lot of this .. so i ended up making an extension method 
instead.

GetRandom.Phrase(GetRandom.Int(10, 70))) .. to try and spice up the phrase 
lengths a bit more..

-me- :)

Original issue reported on code.google.com by [email protected] on 3 Sep 2010 at 1:10

Extensible Property Namers

My team has adopted NBuilder on our current project.  Thanks for this very
cool tool!!!

I like the ability to specify my own property namer.  I also appreciate
ability to extend the existing namers by overriding the virtual method,
HandleUnknownType.  However, I would like to suggest making namers much
more extensible.  To illustrate my idea, I have created the following class:

public class ExtensibleRandomValuePropertyNamer : RandomValuePropertyNamer
{
    public IDictionary<Type, Delegate> unknownTypeHandlers = new
Dictionary<Type, Delegate>();

    public ExtensibleRandomValuePropertyNamer NameWith<T>(Func<T> handler) 
    {
        if (unknownTypeHandlers.ContainsKey(typeof(T)))
        {
            unknownTypeHandlers.Remove(typeof (T));
        }
        unknownTypeHandlers.Add(new KeyValuePair<Type, Delegate>(typeof(T),
handler));
        return this;
    }

    protected override void HandleUnknownType<T>(Type memberType, MemberInfo
memberInfo, T obj)
    {
        var handler = GetUnknownTypeHandler(memberType);
        if (handler != null)
        {
            SetValue(memberInfo, obj, handler.DynamicInvoke());
        }
    }

    protected Delegate GetUnknownTypeHandler(Type memberType)
    {
        if (unknownTypeHandlers.ContainsKey(memberType))
        {
            return unknownTypeHandlers[memberType];
        }
        var type = GetTypeWithoutNullability(memberType);
        return unknownTypeHandlers.ContainsKey(type)
            ? unknownTypeHandlers[type]
            : null;
    }

    protected Type GetTypeWithoutNullability(Type type)
    {
        return type.IsGenericType &&
               type.GetGenericTypeDefinition() == typeof(Nullable<>)
            ? new NullableConverter(type).UnderlyingType
            : type;
    }
}

I envision a property namer that uses delegates (instead of hard coded
methods) for all member types (not just unknown types).  The parameterless
c-tor of this class could initialize a dictionary with default handlers for
most CLR types (the same ones that are now hard coded).  Then the user
could swap or remove any of them.  This offers fine grained control of how
the values are set for every type.  We would no longer need ShouldIgnore;
the user can just remove handler for any type.

Here is an example of usage:

var namer = new ExtensibleRandomValuePropertyNamer()
    .NameWith<Address>(AddressBuilder.Build)
    .NameWith<ContactInfo>(ContactInfoBuilder.Build)
    .NameWith(() => PhoneNumber.Parse(GetRandom.PhoneNumber()));
BuilderSetup.SetDefaultPropertyNamer(namer);

Using this approach we can also eliminate the need for minDate and maxDate
fields.  Something like this instead:

namer.NameWith(() => GetRandom.DateTime(new DateTime(2000, 1, 1), new
DateTime(2020, 12, 31)))

Using anonymous delegates in this way the user can exert all kinds of
control over how values are set, without the pains of inheritance.

I would be happy to work on this, but I wanted to show the idea before
making a full blown implementation.

Original issue reported on code.google.com by [email protected] on 22 Jun 2009 at 9:34

Interview Request

Gareth:

First, I apologize for hi-jacking your issues list, but the contact page on
the NBuilder site seems to be broken and I couldn't find any other way to
contact you.

My name is Craig Shoemaker and I host the Polymorphic Podcast
(http://polymorphicpodcast.com). I'd like to invite you to join me for an
interview to discuss NBuilder.

Let me know if you'd be interested.

Thanks,

Craig 
[email protected]

Original issue reported on code.google.com by [email protected] on 26 Aug 2009 at 9:30

Support for sbyte type

sbyte type support is missing from NBuilder. sbyte properties won't be
named and no random generation of sbyte is supported.

Original issue reported on code.google.com by [email protected] on 19 Jun 2009 at 11:11

Abstract classes

NBuilder incorrectly reports that it can't create an instance of an
abstract class because the class requires constructor args, not because the
class is abstract.

e.g.

public abstract class MyClass
{

}

Builder<MyClass>.CreateNew().Build()

This would throw an exception saying that it could not instantiate the
class because it requires constructor args. It should tell say 'Cannot
build an abstract class'.




Original issue reported on code.google.com by [email protected] on 17 Jun 2009 at 2:11

Requested feature: Let NBuilder be able to create test objects by using immutable and private fields/properties

I found NBuilder through a link in the comments in the article "Test Data
Builders: an alternative to the Object Mother pattern" at this link:
http://www.natpryce.com/articles/000714.html
Then there was a comment back saying that the objects NBuilder creates are
having mutable state.

Since those coments were a year old, I thought that the library might have
been improved since then, but I could actually not figure out how to tell
NBuilder to modify immutable and private readonly properties/fields for the
test builder creation of test objects.
If this actually is possible, I would like to see an example but if not,
consider this as a feature request.

If you think it is tricky to write that kind of reflection code yourself,
you might want to use the fasterflect library:
http://fasterflect.codeplex.com/

Code example illustrating how to modify some private and readonly
fields/properties with fasterflect:

using Fasterflect;
...
        [TestMethod]
        public void
VerifyModificationOfPrivatePropertyAndPrivateReadOnlyField()
        {
            Type type = typeof (MyClass);
            object o = type.CreateInstance();
            o.SetPropertyValue("PropertyWithPrivateSetter", "Some string");
            o.SetFieldValue("_readOnlyIntegerProperty", 123);

            MyClass myClass = (MyClass) o;

            Assert.AreEqual("Some string", myClass.PropertyWithPrivateSetter);
            Assert.AreEqual(123, myClass.ReadOnlyInteger);
        }
... 
    public sealed class MyClass {
        private MyClass() {}

        public MyClass(string someString, int someInteger) {
            PropertyWithPrivateSetter = someString;
            _readOnlyInteger = someInteger;
        }

        public string PropertyWithPrivateSetter { get; private set; }

        private readonly int _readOnlyInteger;
        public int ReadOnlyInteger { 
            get {
                return _readOnlyInteger;
            }
        }
    }

In the example above, I am using strings to specify the names of the
properties, but for properties with a public getter it should be possible
to provide a refactoring friendly API with lambda expresions, even though
the fasterflect library does not currently seem to expose that kind of API
for you (at least not as far as I can tell).

Regarding the private fields, which can not be referred to directly from
the client code using NBuilder, you might define an API similar to Fluent
NHibernate, which lets you choose a convention, such as specifying that the
field is named with an underscore with the same name as a public getter.

For example, Fluent NHibernate uses this kind of syntax:
Map(x => x.Title).Access.CamelCaseField(Prefix.Underscore);
when the class has a "private string _title" with a corresponding a "public
string Title get { return _title; }"
(
http://stackoverflow.com/questions/2041712/unit-test-fluent-nhibernate-ordered-l
ist-mapping
)

/ Tomas

Original issue reported on code.google.com by [email protected] on 27 Mar 2010 at 4:59

Add support for running against Silverlight

From looking at the source code, it seems like it should be possible
support the Core CLR for Silverlight so I was wondering whether you would
consider adding support for nbuilder against Silverlight?

Have a look at ninject for a nant build file that caters for compiling
against multiple targets like Compact Framework, Mono, Silverlight etc...

Thanks 

Original issue reported on code.google.com by [email protected] on 8 Jun 2009 at 6:41

Non-Primitives built as null

Hi,

In the absence of being able to submit an email using the nbuilder.org
contact page at http://www.nbuilder.org/Contact due to a Runtime Error that
occurs, I am raising my question as an issue.

Here is the email I attempted to submit...

Hi Gareth,

I'm currently evaluating NBuilder for use at my place of work in order to
replace my own feeble attempt at creating a data builder for use in our
unit tests.

I really like what I see from the examples on your site and am looking
forward to testing it out.

However, I do have one question that I haven't seen answered in the
documentation.

My question has to do with a difference between your implementation and
mine which has left me wondering if my implementation is not using best
practices or whether I should make a feature request/create a patch.

The best way to explain myself is with a code sample...

public class MyClass1
{
    public MyClass2 Property1 { get; set; }
    public int Id { get; set; }
}

When I use NBuilder to create an object of MyClass1, Property1...which is
not a primitive type...is created as null.

In the test data builder that I created, I have my builder call builders
for each of the non-primitive types so that they are not null. My reasons
for doing so is that it allows me to create an object which I only need to
specify the properties I care about.

In the example above I would need to create MyClass1 as follows:

var myObject = Builder<MyClass1>
                         .CreateNew()
                         .With(p => p.Property1 =
Builder<MyClass2>.CreateNew().Build())
                         .With(p => p.Id = 150)
                         .Build();

Since I frequently need to create classes that have many such properties it
seems like noise when used in a test that only requires (in this example)
that the Id be 150.

Is there any way for me to configure NBuilder to automatically build all of
the non-primitive types as well? If not, is there any reason why NBuilder
should not include such a feature? If this is against the best practices of
builder classes I'd be eager to learn so that I can correct my implementation.

If it can be a new feature, I'd be happy to make an attempt at creating a
patch.

Thanks in advance,
Josh

Original issue reported on code.google.com by [email protected] on 5 Jan 2010 at 10:21

DisablePropertyNamingFor Item HOWTO?

What steps will reproduce the problem?

1. Create an object with an indexer:

        public string this[string propertyName]
        {
            get
            {
                return result.GetErrorMessage(propertyName);
            }
        }

2. Set up a static Create() method in a Mother object with some 
DisablePropertyNamingFor statements:

        public static PositionMother CreatePositionMother()
        {
            BuilderSetup.DisablePropertyNamingFor<Position, string>(p => 
p.Error);
            BuilderSetup.DisablePropertyNamingFor<Position, bool>(p => 
p.HasErrors);

            return new PositionMother() { Positions = 
Builder<Position>.CreateListOfSize(5).Build() };
        }

3. Run up the mother object.

What is the expected output? What do you see instead?

It all works but the Warning message is there for the indexer and we'd 
like to avoid it:

NBuilder warning: Item threw an exception when attempting to read its 
current value

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

Debug version: 1.1.2925.23829
Windows 7 x64

Please provide any additional information below.

Minor inconvienience but how do we write a DisablePropertyNamingFor 
statement to ignore the indexer?

Original issue reported on code.google.com by [email protected] on 19 Jan 2010 at 3:53

NBuilder experiences a FieldAccessException when it tries to build a class that has a null char const


What steps will reproduce the problem?
1. Create a class that has a public const char set to '\0'
2. Use NBuilder to build the class
3. Watch NBuilder crash with the following error message: 
System.FieldAccessException: Cannot set a constant field.

What is the expected output? What do you see instead?
I expect NBuilder to build the class and not set the constant.

Instead I see NBuilder attempting to set all fields, including the ones that 
are constants. What's weird is that if you set the public const char to 'Y' 
instead of '\0' it actually succeeds.


What version of the product are you using? On what operating system?
present in both 2.1.8.0 and 2.1.9.0.

Please provide any additional information below.

I have attached a patch which I believe fixes the issue.

I've changed the PropertyNamer class in the SetValuesOf<T> method to restrict 
type.GetFields() to not get literal fields which I can't think of a reason why 
these should be set.

Please have a look at what I've done an consider it for the next release. I've 
written a unit test to demonstrate the issue so if you're not happy with my fix 
you can at least be aware of the issue.

Original issue reported on code.google.com by [email protected] on 25 Aug 2010 at 5:53

Attachments:

Provide ability for the property namer to set properties which are enums

When objects are being built, we would like to have properties which are 
enumeration types to automatically be set the same way string and numeric 
types are set. Provide implementations for both the SequentialPropertyName 
and the RandomPropertyNamer.


Original issue reported on code.google.com by kevinkuebler on 28 May 2009 at 4:55

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.