Пример #1
0
        public void UseSuppliedResourceDataTest()
        {
            GenFu.Configure().Data(PropertyType.FirstNames, @"testdata\singlename.txt");
            var people = A.ListOf <Person>(25);

            Assert.Equal(25, people.Where(p => p.FirstName == "Angela").Count());
        }
Пример #2
0
        public static void Populate(string connectionString)
        {
            GenFu.Configure <Genre>().Fill(x => x.Name).AsMusicGenreName();
            GenFu.Configure <Artist>().Fill(x => x.Name).AsMusicArtistName();
            GenFu.Configure <Album>().Fill(x => x.AlbumArtUrl, "/Content/Images/placeholder.gif").Fill(x => x.Price).WithinRange(100, 500);
            var rand = new System.Random(100);

            using (var conn = new Npgsql.NpgsqlConnection(connectionString))
            {
                if (conn.ExecuteScalar <int>("select count(1) from albums ") == 0)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        var genre    = A.New <Genre>();
                        var artist   = A.New <Artist>();
                        var genreid  = conn.ExecuteScalar <int>("insert into genres (name,description) values (@name,@description) returning genreid;", new{ genre.Name, genre.Description });
                        var artistid = conn.ExecuteScalar <int>("insert into artists (name) values (@name) returning artistid;", new{ artist.Name });
                        var albums   = A.ListOf <Album>(10);
                        albums.ForEach(a => {
                            conn.Execute("insert into albums(genreid,artistid,title,price,albumarturl) values(@genreid,@artistid,@title,@price,@albumarturl) returning albumid;", new { genreid, artistid, a.Title, a.Price, a.AlbumArtUrl });
                        });
                    }
                }
            }
        }
Пример #3
0
        public void Should_fill_from_a_configured_list_using_lambda()
        {
            GenFu.Reset();
            GenFu.Configure <BlogPost>().Fill(x => x.Tags, () => new List <string> {
                "default"
            });
            var result = A.New <BlogPost>();

            Assert.Equal("default", result.Tags.Single());
        }
Пример #4
0
        public void Should_fill_a_list_of_objects_from_a_configured_list_using_lambda()
        {
            GenFu.Reset();
            GenFu.Configure <BlogPost>().Fill(x => x.Tags, () => new List <string> {
                "default"
            });
            var results = A.ListOf <BlogPost>(5);

            foreach (var result in results)
            {
                Assert.Equal("default", result.Tags.Single());
            }
        }