Ejemplo n.º 1
0
        public void MockContextBuilder_Creates_Correct_Number_Entries()
        {
            var builder = new MockContextBuilder <SimpleContext>();
            var db      = builder.BuildDatabase();

            Assert.IsTrue(db.Customers.Count == 30);
            Assert.IsTrue(db.Products.Count == 30);
        }
Ejemplo n.º 2
0
        public void MockContextBuilder_Creates_Default_Context()
        {
            var builder = new MockContextBuilder <SimpleContext>();
            var db      = builder.BuildDatabase();

            Assert.IsTrue(db.Customers != null);
            Assert.IsTrue(db.Products != null);
        }
Ejemplo n.º 3
0
        public static IServiceCollection RegisterMockDatabase <TContext>(this IServiceCollection serviceCollection, Action <MockContextBuilder <TContext> > builder = null, int dbSize = 30) where TContext : MockContext
        {
            var builderObj = new MockContextBuilder <TContext>();

            builder?.Invoke(builderObj);

            serviceCollection.TryAdd(new ServiceDescriptor(typeof(TContext), builderObj.BuildDatabase(dbSize)));

            return(serviceCollection);
        }
Ejemplo n.º 4
0
        public void MockContextBuilder_Uses_Last_Custom_PropertySeeder()
        {
            var builder = new MockContextBuilder <SimpleContext>();

            builder.CustomizeClassSeeder(c => c.Customers)
            .UseRandomDataPropertySeeder(r => r.Id, new List <int> {
                100
            })
            .UseRandomDataPropertySeeder(r => r.Id, new List <int> {
                999
            });

            var db = builder.BuildDatabase();

            Assert.IsTrue(db.Customers.All(c => c.Id == 999));
        }
Ejemplo n.º 5
0
        public void MockContextBuilder_Can_Add_RandomDataPropertySeeders()
        {
            var builder = new MockContextBuilder <SimpleContext>();

            builder.CustomizeClassSeeder(c => c.Customers)
            .UseRandomDataPropertySeeder(r => r.Id, new List <int> {
                1001
            })
            .UseRandomDataPropertySeeder(r => r.FirstName, new List <string> {
                "Name"
            });


            var db = builder.BuildDatabase();

            Assert.IsTrue(db.Customers.All(i => i.Id == 1001));
            Assert.IsTrue(db.Customers.All(c => c.FirstName == "Name"));
        }