Giter VIP home page Giter VIP logo

datagenerator's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

datagenerator's Issues

Is there any way to intialize an object in it's constructor?

I've been using DataGenerator to do things like:

var data = DataGenerator.Generator.Default.Single<MyType>();

But sometimes I need to be able to do this:

class MyType
{...}

class MyTypeMocked : MyType
{
    void MyTypeMocked()
    {
         //initialize the class in place here, not via object creation by DataGenerator
    }
}

Is there any way to use DataGenerator to update the current object in this way?

FieldAccessor has isReadonly incorrectly set

snippet from your code

            bool isReadonly = !fieldInfo.IsInitOnly && !fieldInfo.IsLiteral;
            if (!isReadonly)
                _setter = new Lazy<Action<object, object>>(() => DelegateFactory.CreateSet(_fieldInfo));

            HasSetter = !isReadonly;

I stumbled on this when trying to seed data into my database using linqpad connecting with LinqToSql. I had to override MappingProfile.Property to allow for Fields. When I did I was getting an exception that there is no setter.

I spit out the all the fields of the class and all of them had IsInitOnly = false and IsLiteral = false. So as a test I made the following test

void Main()
{
    //Setup();
    object a = new ClientSurveyItem();
    a = new Clown();
    var fieldInfo = a.GetType().GetField("Section");
    bool isReadonly = !fieldInfo.IsInitOnly && !fieldInfo.IsLiteral;
    fieldInfo.Dump($"isReadonly:{isReadonly}");
    //var clientSurveyItem = _dataManager.CreateClientSurveyItem().Result;
}
class Clown
{
    public string Section;
}

my output is isReadonly:True

yet I can very easily do a.Section = "somethign";

tried the same thing with a struct and I get same results

The expression is not a member access expression.

The class that I am generating my random data from has nullable numeral types and the IntegerSource and DecimalSource does not like them. So I tried using Convert but I get a runtime error that says...

The expression is not a member access expression.

Is there any way around this other than changing my properties?

Support for a provided Random() seed

I believe it would be useful (certainly for my own use but probably for others) if this library supported the ability to provide the seed used for the Random() RNG. This would allow test data to be duplicated simply by tracking the seed that was used to generate the data instead of having to hold onto all of the data generated at the time.

My initial thoughts on how this would work:

Generator.Default.Configure(c => c
  .Seed(133)
  .Entity<User>(e => 
  {
        e.Property(p => p.FirstName).DataSource<FirstNameSource>();
        e.Property(p => p.LastName).DataSource<LastNameSource>();
        e.Property(p => p.Address1).DataSource<StreetSource>();
        e.Property(p => p.City).DataSource<CitySource>();
        e.Property(p => p.State).DataSource<StateSource>();
        e.Property(p => p.Zip).DataSource<PostalCodeSource>();
        
        e.Property(p => p.Note).DataSource<LoremIpsumSource>();
        e.Property(p => p.Password).DataSource<PasswordSource>();
        
        // array of values
        e.Property(p => p.Status).DataSource(new[] { Status.New, Status.Verified });
        
        
        // don't generate
        e.Property(p => p.Budget).Ignore();
        
        // static value
        e.Property(p => p.IsActive).Value(true);
        
        // delegate value
        e.Property(p => p.Created).Value(() => DateTime.Now);
    })
);

var users = Generator.Default.List<User>(10);

This would produce the exact same results each time. I will look into creating a PR for this support if you are willing to accept PRs. At first glance though, it appears to be non-trivial due to the static ThreadLocal<Random> usage for the RNGs. I believe this is just to keep your library thread safe but that your library doesn't actually create any threads?

If no seed is configured then it could default to the way things are done now. If a seed IS provided and there are multiple threads or at minimum things must remain thread safe, it could be handled in a few different ways:

  • Each thread's RNG would get a seed starting at the provided seed value and increasing by 1 each thread.
  • A single RNG could be used with a lock around it's access. This would scope the change to a transparent change of the RandomGenerator class. There would be a theoretical performance hit due to the lock but I believe it would be negligible and could be benchmarked to compare.
  • Allow the developer to specify their own RNG through an interface to push the thread safety concerns to the consumer if a custom solution such as this is needed.
  • Instead of passing in an RNG interface, allow for the configuration of a "SeedProvider" that has a threadsafe call to a single method such as GetNextSeed() where each ThreadLocal would call that to get its seed.

Ignore entity property

Hi, I want ignore some properties of entity, but i don't know how.
I would grateful if you can help me.
Thx.

Properties of type ICollection<T> cannot be generated

When your model contains a property of type ICollection, the property cannot be assigned from the generator. It results in an exception mentioning "the object should implement IConvertible". This happens when the Convert.ChangeType is hit.

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.