Exemplo n.º 1
0
        public void ReadReviewBad()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CtorDbContext>();

            using (var context = new CtorDbContext(options, false))
            {
                context.Database.EnsureCreated();
                var newEntity = new ReviewBad("John Doe")
                {
                    NumStars = -1
                };
                newEntity.VoterName.ShouldEqual("Name: John Doe");
                context.Add(newEntity);
                context.SaveChanges();
            }
            using (var context = new CtorDbContext(options, false))
            {
                //ATTEMPT
                var entity = context.ReviewBads.Single();

                //VERIFY
                entity.VoterName.ShouldEqual("Name: Name: John Doe");
                entity.NumStars.ShouldEqual(-1);
            }
        }
Exemplo n.º 2
0
        public void ReadReviewBadCtor1()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CtorDbContext>();

            using var context = new CtorDbContext(options, true);
            //ATTEMPT
            var ex = Assert.Throws <InvalidOperationException>(() => context.Database.EnsureCreated());

            //VERIFY
            ex.Message.ShouldStartWith("No suitable constructor found for entity type 'ReviewBadCtor1'.");
        }
Exemplo n.º 3
0
        public void ReadReviewsGood2WhichCtorUsed()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CtorDbContext>();

            using var context = new CtorDbContext(options, false);
            context.Database.EnsureCreated();
            var newEntity = new ReviewGood2("John Doe", 1);

            context.Add(newEntity);
            context.SaveChanges();

            context.ChangeTracker.Clear();

            //ATTEMPT
            var entity = context.Review2Goods.Single();

            //VERIFY
            entity.VoterName.ShouldEqual("John Doe");
            entity.NumStars.ShouldEqual(1);
        }