コード例 #1
0
ファイル: EntityHistoryTest.cs プロジェクト: Rhetos/Rhetos
        public void UpdateHistoryFuture()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestHistory.Simple" });
                var repository = container.Resolve<Common.DomRepository>();

                var now = GetServerTime(container).Rounded();
                DateTime future1 = now.AddMinutes(1);
                DateTime future2 = future1.AddMinutes(1);
                DateTime future3 = future2.AddMinutes(1);

                TestUtility.Dump(new[] { future1, future2, future3 }, item => item.ToString("o"));

                // The last record (whether in future or not) should be regarded as "current record" by the History concept.
                var lastRecordInFuture = new TestHistory.Simple { ID = Guid.NewGuid(), Code = 1, ActiveSince = future3 };
                repository.TestHistory.Simple.Insert(new[] { lastRecordInFuture });

                var historyRecord = new TestHistory.Simple_Changes { EntityID = lastRecordInFuture.ID, Code = 2, ActiveSince = future1 };
                repository.TestHistory.Simple_Changes.Insert(new[] { historyRecord });

                historyRecord.ActiveSince = future2;
                repository.TestHistory.Simple_Changes.Update(new[] { historyRecord });

                var currentRecord = repository.TestHistory.Simple.All().Single();
                Console.WriteLine("currentRecord.ActiveSince: " + currentRecord.ActiveSince.Value.ToString("o"));
                Assert.AreEqual("1  " + future3.Dump(), DumpFull(new[] { currentRecord }));
            }
        }
コード例 #2
0
ファイル: EntityHistoryTest.cs プロジェクト: koav/Rhetos
        public void UpdateHistoryFuture()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestHistory.Simple" });
                var repository = new Common.DomRepository(executionContext);

                var s = new TestHistory.Simple { ID = Guid.NewGuid(), Code = 1, ActiveSince = Day(2) };
                repository.TestHistory.Simple.Insert(new[] { s });

                var h = new TestHistory.Simple_Changes { EntityID = s.ID, Code = 2, ActiveSince = Day(1) };
                repository.TestHistory.Simple_Changes.Insert(new[] { h });

                var future = SqlUtility.GetDatabaseTime(executionContext.SqlExecuter).AddMinutes(1);
                h.ActiveSince = future;

                TestUtility.ShouldFail(
                    () => repository.TestHistory.Simple_Changes.Update(new[] { h }),
                    "ActiveSince", "TestHistory.Simple_Changes", "future");
            }
        }