public void NullConflictThrows()
        {
            var entity = new TestEntity
            {
                Property         = "prop",
                ConcurrencyToken = "573dfb98237e4f51bafaab0317777960"
            };

            using (var context = InMemoryContextBuilder.Build <TestDataContext>())
            {
                context.Add(entity);
                context.SaveChanges();
            }

            using (var context = InMemoryContextBuilder.Build <TestDataContext>())
            {
                var update = new TestEntity
                {
                    Id               = entity.Id,
                    Property         = "Something new",
                    ConcurrencyToken = "4b39590ea0894ab9a05912456bf700b6"
                };
                context.Attach(update);
                context.Entry(update).Property("Property").IsModified = true;
                var exception = Assert.Throws <DbUpdateConcurrencyException>(() => context.SaveChanges());
                Approvals.Verify(exception.Message);
            }
        }
Пример #2
0
 static DataContextBuilder()
 {
     using (var myDataContext = InMemoryContextBuilder.Build <MyDataContext>())
     {
         Model = myDataContext.Model;
     }
 }
Пример #3
0
    public void AssertIdIsReset()
    {
        using (var context = InMemoryContextBuilder.Build <TestDataContext>())
        {
            var entity = new TestEntity
            {
                Property = "prop1"
            };
            context.Add(entity);
            context.SaveChanges();
            var id = context.TestEntities.Single().Id;
            Assert.Equal(1, id);
        }

        using (var context = InMemoryContextBuilder.Build <TestDataContext>())
        {
            var entity = new TestEntity
            {
                Property = "prop2"
            };
            context.Add(entity);
            context.SaveChanges();
            var id = context.TestEntities.Single().Id;
            Assert.Equal(1, id);
        }
    }
Пример #4
0
        public void NullConflictThrows()
        {
            var entity = new TestEntity
            {
                Property = "prop"
            };

            using (var context = InMemoryContextBuilder.Build <TestDataContext>())
            {
                context.Add(entity);
                context.SaveChanges();
            }

            using (var context = InMemoryContextBuilder.Build <TestDataContext>())
            {
                var update = new TestEntity
                {
                    Id       = entity.Id,
                    Property = "Something new"
                };
                context.Entry(update).Property("Property").IsModified = true;
                var exception = Assert.Throws <DbUpdateConcurrencyException>(() => context.SaveChanges());
                Approvals.Verify(exception.Message);
            }
        }
        public void ValueConflictThrows()
        {
            var entity = new TestEntity
            {
                Property         = "prop",
                ConcurrencyToken = "19ec62bea4f94ef1a8e4723707d3cc85"
            };

            using (var context = InMemoryContextBuilder.Build <TestDataContext>())
            {
                context.Add(entity);
                context.SaveChanges();
            }

            using (var context = InMemoryContextBuilder.Build <TestDataContext>())
            {
                var update = new TestEntity
                {
                    Id               = entity.Id,
                    Property         = "Something new",
                    ConcurrencyToken = "dbd48fc43d9244f7a08cd54bae94b15a"
                };
                context.Attach(update);
                context.Entry(update).Property("Property").IsModified = true;
                var exception = Assert.Throws <DbUpdateConcurrencyException>(() => context.SaveChanges());
                Approvals.Verify(exception.Message);
            }
        }
        public void SetConcurrencyTokenToNullThrows()
        {
            var entity = new TestEntity
            {
                Property         = "prop",
                ConcurrencyToken = "616e2ca1a52a4c57afbfe80ecc54125c"
            };

            using (var context = InMemoryContextBuilder.Build <TestDataContext>())
            {
                context.Add(entity);
                context.SaveChanges();
            }

            using (var context = InMemoryContextBuilder.Build <TestDataContext>())
            {
                var update = new TestEntity
                {
                    Id               = entity.Id,
                    Property         = "Something new",
                    ConcurrencyToken = null
                };
                context.Attach(update);
                context.Entry(update).Property("Property").IsModified = true;
                var exception = Assert.Throws <DbUpdateConcurrencyException>(() => context.SaveChanges());
                Approvals.Verify(exception.Message);
            }
        }
    public static NorthwindContext BuildDataContext()
    {
        var category      = new Category {
        };
        var myDataContext = InMemoryContextBuilder.Build <NorthwindContext>();

        myDataContext.AddRange(category);
        myDataContext.SaveChanges();
        return(myDataContext);
    }
Пример #8
0
 public void WithQueryTypeShouldNotThrow()
 {
     using (var context = InMemoryContextBuilder.Build <TestDataContext>())
     {
         var entity = new TestEntity
         {
             Property = "prop"
         };
         context.Add(entity);
         context.SaveChanges();
     }
 }
Пример #9
0
 void Simple()
 {
     using (var context = InMemoryContextBuilder.Build <MyDataContext>())
     {
         var entity = new MyEntity
         {
             Property = "prop"
         };
         context.Add(entity);
         context.SaveChanges();
     }
 }
        /*
         * protected override void OnModelCreating(ModelBuilder modelBuilder)
         * {
         *  base.OnModelCreating(modelBuilder);
         *  /*
         *  modelBuilder.Entity<ArticleType>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<Article>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<ArticleBom>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<ArticleToBusinessPartner>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<BusinessPartner>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<DemandToProvider>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<Kpi>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<Machine>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<MachineTool>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<MachineGroup>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<Order>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<OrderPart>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<ProductionOrder>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<ProductionOrderBom>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<ProductionOrderWorkSchedule>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<Purchase>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<PurchasePart>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<Stock>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<Unit>().Property(p => p.Id).ValueGeneratedNever();
         *  modelBuilder.Entity<WorkSchedule>().Property(p => p.Id).ValueGeneratedNever();
         * }
         */
        public static ProductionDomainContext CreateInMemoryContext()
        {
            // In-memory database only exists while the connection is open
            var options = new DbContextOptionsBuilder <MasterDBContext>();

            options.UseSecondLevelCache();

            InMemoryContext _inMemmoryContext = InMemoryContextBuilder.Build <InMemoryContext>(builder: options);

            _inMemmoryContext.Database.EnsureCreated();

            return(_inMemmoryContext);
        }
Пример #11
0
    void WithConstructor()
    {
        var builder = new DbContextOptionsBuilder <MyDataContext>();

        using (var context = InMemoryContextBuilder.Build(builder, options => new MyDataContext(options)))
        {
            var entity = new MyEntity
            {
                Property = "prop"
            };
            context.Add(entity);
            context.SaveChanges();
        }
    }
Пример #12
0
 public void UpdateSameEntity()
 {
     using (var context = InMemoryContextBuilder.Build <TestDataContext>())
     {
         var entity = new TestEntity
         {
             Property = "prop"
         };
         context.Add(entity);
         context.SaveChanges();
         entity.Property = "Something new";
         context.SaveChanges();
     }
 }
 public void RespectsUniqueIndexOrder()
 {
     using (var context = InMemoryContextBuilder.Build <TestDataContext>())
     {
         var entity1 = new TestEntityUnique {
             A = "a", B = "b"
         };
         var entity2 = new TestEntityUnique {
             A = "b", B = "a"
         };
         context.AddRange(entity1, entity2);
         context.SaveChanges();
     }
 }
Пример #14
0
 public void GetInMemoryContextWithSpecifiedDbName()
 {
     using (var context = InMemoryContextBuilder.Build <TestDataContext>("MyDatabase"))
     {
         var entity = new TestEntity
         {
             Property = "prop"
         };
         context.Add(entity);
         context.SaveChanges();
         var item = context.TestEntities.ToList();
         Assert.Single(item);
     }
 }
Пример #15
0
    public static MyDataContext BuildDataContext()
    {
        var company1 = new Company
        {
            Id      = 1,
            Content = "Company1"
        };
        var employee1 = new Employee
        {
            Id        = 2,
            CompanyId = company1.Id,
            Content   = "Employee1",
            Age       = 25
        };
        var employee2 = new Employee
        {
            Id        = 3,
            CompanyId = company1.Id,
            Content   = "Employee2",
            Age       = 31
        };
        var company2 = new Company
        {
            Id      = 4,
            Content = "Company2"
        };
        var employee4 = new Employee
        {
            Id        = 5,
            CompanyId = company2.Id,
            Content   = "Employee4",
            Age       = 34
        };
        var company3 = new Company
        {
            Id      = 6,
            Content = "Company3"
        };
        var company4 = new Company
        {
            Id      = 7,
            Content = "Company4"
        };
        var myDataContext = InMemoryContextBuilder.Build <MyDataContext>();

        myDataContext.AddRange(company1, employee1, employee2, company2, company3, company4, employee4);
        myDataContext.SaveChanges();
        return(myDataContext);
    }
 public void UpdateSameEntity()
 {
     using (var context = InMemoryContextBuilder.Build <TestDataContext>())
     {
         var entity = new TestEntity
         {
             Property         = "prop",
             ConcurrencyToken = "28f4fc79da8f43b887d2eef4e82a2be5"
         };
         context.Add(entity);
         context.SaveChanges();
         entity.Property = "Something new";
         context.SaveChanges();
     }
 }
Пример #17
0
 public void SetRowVersionToNullThrows()
 {
     using (var context = InMemoryContextBuilder.Build <TestDataContext>())
     {
         var entity = new TestEntity
         {
             Property = "prop"
         };
         context.Add(entity);
         context.SaveChanges();
         entity.Timestamp = null;
         var exception = Assert.Throws <Exception>(() => context.SaveChanges());
         Approvals.Verify(exception.Message);
     }
 }
Пример #18
0
 void WithBuilder()
 {
     #region withBuilder
     var builder = new DbContextOptionsBuilder <MyDataContext>();
     using (var context = InMemoryContextBuilder.Build <MyDataContext>(builder))
     {
         var entity = new MyEntity
         {
             Property = "prop"
         };
         context.Add(entity);
         context.SaveChanges();
     }
     #endregion
 }
Пример #19
0
 void WithDatabaseName()
 {
     #region withDatabaseName
     var builder = new DbContextOptionsBuilder <MyDataContext>();
     using (var context = InMemoryContextBuilder.Build(builder, options => new MyDataContext(options)))
     {
         var entity = new MyEntity
         {
             Property = "prop"
         };
         context.Add(entity);
         context.SaveChanges();
     }
     #endregion
 }
Пример #20
0
 public void UpdateSucceeds()
 {
     using (var context = InMemoryContextBuilder.Build <TestDataContext>())
     {
         var entity = new TestEntity
         {
             Property = "prop"
         };
         context.Add(entity);
         context.SaveChanges();
         var firstTimestamp = entity.Timestamp;
         entity.Property = "Something new";
         context.SaveChanges();
         Assert.NotEqual(firstTimestamp, entity.Timestamp);
     }
 }
 public void UpdateSucceeds()
 {
     using (var context = InMemoryContextBuilder.Build <TestDataContext>())
     {
         var entity = new TestEntity
         {
             Property         = "prop",
             ConcurrencyToken = "d6f321a1320846a49b81595c4d41d25d"
         };
         context.Add(entity);
         context.SaveChanges();
         var firstToken = entity.ConcurrencyToken.ToString();
         entity.Property = "Something new";
         context.SaveChanges();
         Assert.Equal(firstToken, entity.ConcurrencyToken);
     }
 }
 public void UniqueIndexThrows()
 {
     using (var context = InMemoryContextBuilder.Build <TestDataContext>())
     {
         var entity1 = new TestEntity
         {
             Property = "prop"
         };
         context.Add(entity1);
         var user2 = new TestEntity
         {
             Property = "prop"
         };
         context.Add(user2);
         var exception = Assert.Throws <Exception>(() => context.SaveChanges());
         Approvals.Verify(exception.Message);
     }
 }
Пример #23
0
 public void UpdateMultipleSameEntity()
 {
     using (var context = InMemoryContextBuilder.Build <TestDataContext>())
     {
         var entity1 = new TestEntity
         {
             Property = "prop"
         };
         var entity2 = new TestEntity
         {
             Property = "prop"
         };
         context.AddRange(entity1, entity2);
         context.SaveChanges();
         entity1.Property = "Something new";
         entity2.Property = "Something new";
         context.SaveChanges();
     }
 }
 public void UpdateMultipleSameEntity()
 {
     using (var context = InMemoryContextBuilder.Build <TestDataContext>())
     {
         var entity1 = new TestEntity
         {
             Property         = "prop",
             ConcurrencyToken = "3c615ac3734046bc8bf6fd58d979c1ae"
         };
         var entity2 = new TestEntity
         {
             Property         = "prop",
             ConcurrencyToken = "cc4c1ce921e6457b89d00c7c2c6de2a9"
         };
         context.AddRange(entity1, entity2);
         context.SaveChanges();
         entity1.Property = "Something new";
         entity2.Property = "Something new";
         context.SaveChanges();
     }
 }
 public void UpdateSucceeds()
 {
     using (var context = InMemoryContextBuilder.Build <TestDataContext>())
     {
         var entity = new TestEntity
         {
             Property = "prop"
         };
         context.Add(entity);
         context.SaveChanges();
         var firstTimestamp = entity.Timestamp;
         var update         = new TestEntity
         {
             Id        = entity.Id,
             Property  = "Something new",
             Timestamp = firstTimestamp
         };
         context.Entry(update).Property("Property").IsModified = true;
         context.SaveChanges();
         Assert.NotEqual(firstTimestamp.GetGuid(), update.Timestamp.GetGuid());
     }
 }
 public void UpdateSucceeds()
 {
     using (var context = InMemoryContextBuilder.Build <TestDataContext>())
     {
         var entity = new TestEntity
         {
             Property         = "prop",
             ConcurrencyToken = "d6f321a1320846a49b81595c4d41d25d"
         };
         context.Add(entity);
         context.SaveChanges();
         var firstToken = entity.ConcurrencyToken;
         var update     = new TestEntity
         {
             Id               = entity.Id,
             Property         = "Something new",
             ConcurrencyToken = firstToken
         };
         context.Entry(update).Property("Property").IsModified = true;
         context.SaveChanges();
         Assert.Equal(firstToken, update.ConcurrencyToken);
     }
 }
Пример #27
0
    public void ReusabilitySucceeds()
    {
        const string dbName = "MyDatabase";
        const string value  = "prop";

        using (var context = InMemoryContextBuilder.Build <TestDataContext>(dbName))
        {
            var entity = new TestEntity
            {
                Property = value
            };
            context.Add(entity);
            context.SaveChanges();
        }

        TestEntity res;

        using (var context = InMemoryContextBuilder.Build <TestDataContext>(dbName))
        {
            res = context.TestEntities.First(e => e.Property == value);
        }
        Assert.NotNull(res);
    }