Example #1
0
        private static void TestCodeManaged()
        {
            var rnd     = new Random();
            var startup = new TenantContextStartup("jsmith", tenantId1);

            using (var context = new DataContext(startup, connectionString))
            {
                for (var ii = 0; ii < 10; ii++)
                {
                    //The primary key is not an identity. It must be set in code
                    var newItem = new CodeManagedKey
                    {
                        ID   = rnd.Next(10, 999999),
                        Name = $"Hello {DateTime.Now.Ticks}",
                        Data = "hello",
                    };
                    context.Add(newItem);
                }
                context.SaveChanges();

                //Test Versioning. It goes up by +1 on each save
                var item = context.CodeManagedKey.FirstOrDefault();
                Console.WriteLine($"Version #: {item.Version}");
                item.Name = DateTime.Now.Ticks.ToString();
                context.SaveChanges();
                Console.WriteLine($"Version #: {item.Version}");
                item.Name = DateTime.Now.Ticks.ToString();
                context.SaveChanges();
                Console.WriteLine($"Version #: {item.Version}");
            }
        }
Example #2
0
        public void TestVersion()
        {
            var startup = new TenantContextStartup("jsmith", TenantA);

            using (var context = new TestContext(startup, connectionString))
            {
                var newItem = new CodeManagedKey();
                newItem.Name = DateTime.Now.Ticks.ToString();
                context.Add(newItem);
                context.SaveChanges();
                Assert.AreEqual(1, newItem.Version);

                newItem.Name = DateTime.Now.Ticks.ToString();
                context.SaveChanges();
                Assert.AreEqual(2, newItem.Version);

                newItem.Name = DateTime.Now.Ticks.ToString();
                context.SaveChanges();
                Assert.AreEqual(3, newItem.Version);
            }
        }