context: // <copyright file="LifeCycleTest.cs" company="Allors bvba">
  // Copyright (c) Allors bvba. All rights reserved.
  // Licensed under the LGPL license. See LICENSE file in the project root for full license information.
  // </copyright>
  
  namespace Allors.Database.Adapters
  {
      using System;
      using System.Collections;
      using System.Collections.Generic;
  
      using Allors;
      using Allors.Domain;
      using Allors.Meta;
  
      using Xunit;
  
      public abstract class LifeCycleTest : IDisposable
      {
          protected static readonly bool[] TrueFalse = { true, false };
  
          protected abstract IProfile Profile { get; }
  
          protected ISession Session => this.Profile.Session;
  
          protected Action[] Markers => this.Profile.Markers;
  
          protected Action[] Inits => this.Profile.Inits;
  
          public abstract void Dispose();
  
          [Fact]
          public void NextId()
          {
              foreach (var init in this.Inits)
              {
                  init();
  
                  var c1 = this.Session.Create<C1>();
                  var strategy = c1.Strategy;
                  var id = long.Parse(strategy.ObjectId.ToString());
  
                  var nextId = long.Parse(this.Session.Create<C1>().Strategy.ObjectId.ToString());
  
                  Assert.Equal(id + 1, nextId);
              }
          }
  
          [Fact]
          public void CreateMany()
          {
              foreach (var init in this.Inits)
              {
                  init();
  
                  int[] runs = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048 };
  
                  var total = 0;
                  foreach (var run in runs)
                  {
                      var allorsObjects = this.Session.Create(MetaC1.Instance.ObjectType, run);
  
                      Assert.Equal(run, allorsObjects.Length);
  
                      total += run;
  
                      Assert.Equal(total, this.GetExtent(MetaC1.Instance.ObjectType).Length);
  
                      var ids = new ArrayList();
                      foreach (C1 allorsObject in allorsObjects)
                      {
                          Assert.Equal(MetaC1.Instance.ObjectType, allorsObject.Strategy.Class);
                          ids.Add(allorsObject.Strategy.ObjectId);
                          allorsObject.C1AllorsString = "CreateMany";
                      }
  
                      Assert.Equal(run, ids.Count);
  
                      this.Session.Commit();
  
                      allorsObjects = this.Session.Instantiate((long[])ids.ToArray(typeof(long)));
                      foreach (C1 allorsObject in allorsObjects)
                      {
                          Assert.Equal(MetaC1.Instance.ObjectType, allorsObject.Strategy.Class);
                          allorsObject.C1AllorsString = "CreateMany";
                      }
  
                      var c2s = (C2[])this.Session.Create(MetaC2.Instance.ObjectType, run);
                      Assert.Equal(run, c2s.Length);
                  }
              }
          }
  
          [Fact]
          public void UnitRole()
          {
              foreach (var init in this.Inits)
              {
                  init();
  
                  var c1A = C1.Create(this.Session);
  
                  this.Session.Commit();
  
                  c1A.C1AllorsString = "1";
  
                  this.Session.Commit();
  
                  c1A.C1AllorsString = "2";
  
                  this.Session.Rollback();
  
                  Assert.Equal("1", c1A.C1AllorsString);
              }
          }
  
          [Fact]
          public void CompositeRole()
          {
              foreach (var init in this.Inits)
              {
                  init();
  
                  var c1A = C1.Create(this.Session);
  
                  var c2A = C2.Create(this.Session);
                  var c2B = C2.Create(this.Session);
  
                  this.Session.Commit();
  
                  c1A.C1C2one2one = c2A;
  
                  this.Session.Commit();
  
                  c1A.C1C2one2one = c2B;
  
                  this.Session.Rollback();
  
                  Assert.Equal(c2A, c1A.C1C2one2one);
              }
          }
  
          [Fact]
          public void CompositeRoles()
          {
              foreach (var init in this.Inits)
              {
                  init();
  
                  var c1A = C1.Create(this.Session);
  
                  var c2A = C2.Create(this.Session);
                  var c2B = C2.Create(this.Session);
  
                  this.Session.Commit();
  
                  c1A.AddC1C2one2many(c2A);
  
                  this.Session.Commit();
  
                  c1A.AddC1C2one2many(c2B);
  
                  this.Session.Rollback();
  
                  Assert.Single(c1A.C1C2one2manies);
                  Assert.Equal(c2A, c1A.C1C2one2manies[0]);
              }
          }
  
          [Fact]
          public void Delete()
          {
              foreach (var init in this.Inits)
              {
                  init();
  
                  // Object
                  var anObject = C1.Create(this.Session);
  
                  anObject.Strategy.Delete();
                  Assert.True(anObject.Strategy.IsDeleted);
                  anObject = (C1)this.Session.Instantiate(anObject.Strategy.ObjectId);
                  Assert.Null(anObject);
  
                  //// Commit & Rollback
  
                  anObject = C1.Create(this.Session);
                  anObject.Strategy.Delete();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Commit();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Commit();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  // instantiate
                  anObject = C1.Create(this.Session);
                  var id = anObject.Strategy.ObjectId;
                  anObject.Strategy.Delete();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Commit();
                  anObject = C1.Instantiate(this.Session, id);
                  Assert.Null(anObject);
  
                  this.Session.Commit();
                  anObject = C1.Instantiate(this.Session, id);
                  Assert.Null(anObject);
  
                  //// Commit + Commit + Commit
  
                  anObject = C1.Create(this.Session);
  
                  this.Session.Commit();
  
                  anObject.Strategy.Delete();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Commit();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Commit();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  // instantiate
                  anObject = C1.Create(this.Session);
                  id = anObject.Strategy.ObjectId;
  
                  this.Session.Commit();
  
                  anObject.Strategy.Delete();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Commit();
                  anObject = C1.Instantiate(this.Session, id);
                  Assert.Null(anObject);
  
                  this.Session.Commit();
                  anObject = C1.Instantiate(this.Session, id);
                  Assert.Null(anObject);
  
                  //// Nothing + Commit + Rollback
  
                  anObject = C1.Create(this.Session);
  
                  anObject.Strategy.Delete();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Commit();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Rollback();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  // instantiate
                  anObject = C1.Create(this.Session);
                  id = anObject.Strategy.ObjectId;
  
                  anObject.Strategy.Delete();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Commit();
                  anObject = C1.Instantiate(this.Session, id);
                  Assert.Null(anObject);
  
                  this.Session.Rollback();
                  anObject = C1.Instantiate(this.Session, id);
                  Assert.Null(anObject);
  
                  //// Commit + Commit + Rollback
  
                  anObject = C1.Create(this.Session);
  
                  this.Session.Commit();
  
                  anObject.Strategy.Delete();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Commit();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Rollback();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  // instantiate
                  anObject = C1.Create(this.Session);
                  id = anObject.Strategy.ObjectId;
  
                  this.Session.Commit();
  
                  anObject.Strategy.Delete();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Commit();
                  anObject = C1.Instantiate(this.Session, id);
                  Assert.Null(anObject);
  
                  this.Session.Rollback();
                  anObject = C1.Instantiate(this.Session, id);
                  Assert.Null(anObject);
  
                  //// Nothing + Rollback + Rollback
  
                  anObject = C1.Create(this.Session);
                  anObject.Strategy.Delete();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Rollback();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Rollback();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  // instantiate
                  anObject = C1.Create(this.Session);
                  id = anObject.Strategy.ObjectId;
  
                  anObject.Strategy.Delete();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Rollback();
                  anObject = C1.Instantiate(this.Session, id);
                  Assert.Null(anObject);
  
                  this.Session.Rollback();
                  anObject = C1.Instantiate(this.Session, id);
                  Assert.Null(anObject);
  
                  //// Commit + Rollback + Rollback
  
                  anObject = C1.Create(this.Session);
  
                  this.Session.Commit();
  
                  anObject.Strategy.Delete();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Rollback();
                  Assert.False(anObject.Strategy.IsDeleted);
  
                  this.Session.Rollback();
                  Assert.False(anObject.Strategy.IsDeleted);
  
                  // instantiate
                  anObject = C1.Create(this.Session);
                  id = anObject.Strategy.ObjectId;
  
                  this.Session.Commit();
  
                  anObject.Strategy.Delete();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Rollback();
                  anObject = C1.Instantiate(this.Session, id);
                  Assert.False(anObject.Strategy.IsDeleted);
  
                  this.Session.Rollback();
                  anObject = C1.Instantiate(this.Session, id);
                  Assert.False(anObject.Strategy.IsDeleted);
  
                  //// Nothing + Rollback + Commit
  
                  anObject = C1.Create(this.Session);
  
                  anObject.Strategy.Delete();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Rollback();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Commit();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  // instantiate
                  anObject = C1.Create(this.Session);
                  id = anObject.Strategy.ObjectId;
  
                  anObject.Strategy.Delete();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Rollback();
                  anObject = C1.Instantiate(this.Session, id);
                  Assert.Null(anObject);
  
                  this.Session.Rollback();
                  anObject = C1.Instantiate(this.Session, id);
                  Assert.Null(anObject);
  
                  //// Commit + Rollback + Commit
  
                  anObject = C1.Create(this.Session);
  
                  this.Session.Commit();
  
                  anObject.Strategy.Delete();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Rollback();
                  Assert.False(anObject.Strategy.IsDeleted);
  
                  this.Session.Commit();
                  Assert.False(anObject.Strategy.IsDeleted);
  
                  // instantiate
                  anObject = C1.Create(this.Session);
                  id = anObject.Strategy.ObjectId;
  
                  this.Session.Commit();
  
                  anObject.Strategy.Delete();
                  Assert.True(anObject.Strategy.IsDeleted);
  
                  this.Session.Rollback();
                  anObject = C1.Instantiate(this.Session, id);
                  Assert.False(anObject.Strategy.IsDeleted);
  
                  this.Session.Rollback();
                  anObject = C1.Instantiate(this.Session, id);
                  Assert.False(anObject.Strategy.IsDeleted);
  
                  // Clean up
                  this.Session.Commit();
                  foreach (C1 removeObject in this.GetExtent(MetaC1.Instance.ObjectType))
                  {
                      removeObject.Strategy.Delete();
                  }
  
                  this.Session.Commit();
  
                  // Strategy
                  if (this.Session is ISession databaseSession)
                  {
                      var aStrategy = C1.Create(this.Session).Strategy;
  
                      aStrategy.Delete();
                      Assert.True(aStrategy.IsDeleted);
                      aStrategy = databaseSession.InstantiateStrategy(aStrategy.ObjectId);
                      Assert.Null(aStrategy);
  
                      //// Commit & Rollback
  
                      aStrategy = C1.Create(databaseSession).Strategy;
                      aStrategy.Delete();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Commit();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Commit();
                      Assert.True(aStrategy.IsDeleted);
  
                      // instantiate
                      aStrategy = C1.Create(databaseSession).Strategy;
                      id = aStrategy.ObjectId;
                      aStrategy.Delete();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Commit();
                      aStrategy = databaseSession.InstantiateStrategy(id);
                      Assert.Null(aStrategy);
  
                      databaseSession.Commit();
                      aStrategy = databaseSession.InstantiateStrategy(id);
                      Assert.Null(aStrategy);
  
                      //// Commit + Commit + Commit
  
                      aStrategy = C1.Create(databaseSession).Strategy;
  
                      databaseSession.Commit();
  
                      aStrategy.Delete();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Commit();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Commit();
                      Assert.True(aStrategy.IsDeleted);
  
                      // instantiate
                      aStrategy = C1.Create(databaseSession).Strategy;
                      id = aStrategy.ObjectId;
  
                      databaseSession.Commit();
  
                      aStrategy.Delete();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Commit();
                      aStrategy = databaseSession.InstantiateStrategy(id);
                      Assert.Null(aStrategy);
  
                      databaseSession.Commit();
                      aStrategy = databaseSession.InstantiateStrategy(id);
                      Assert.Null(aStrategy);
  
                      //// Nothing + Commit + Rollback
  
                      aStrategy = C1.Create(databaseSession).Strategy;
  
                      aStrategy.Delete();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Commit();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Rollback();
                      Assert.True(aStrategy.IsDeleted);
  
                      // instantiate
                      aStrategy = C1.Create(databaseSession).Strategy;
                      id = aStrategy.ObjectId;
  
                      aStrategy.Delete();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Commit();
                      aStrategy = databaseSession.InstantiateStrategy(id);
                      Assert.Null(aStrategy);
  
                      databaseSession.Rollback();
                      aStrategy = databaseSession.InstantiateStrategy(id);
                      Assert.Null(aStrategy);
  
                      //// Commit + Commit + Rollback
  
                      aStrategy = C1.Create(databaseSession).Strategy;
  
                      databaseSession.Commit();
  
                      aStrategy.Delete();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Commit();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Rollback();
                      Assert.True(aStrategy.IsDeleted);
  
                      // instantiate
                      aStrategy = C1.Create(databaseSession).Strategy;
                      id = aStrategy.ObjectId;
  
                      databaseSession.Commit();
  
                      aStrategy.Delete();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Commit();
                      aStrategy = databaseSession.InstantiateStrategy(id);
                      Assert.Null(aStrategy);
  
                      databaseSession.Rollback();
                      aStrategy = databaseSession.InstantiateStrategy(id);
                      Assert.Null(aStrategy);
  
                      //// Nothing + Rollback + Rollback
  
                      aStrategy = C1.Create(databaseSession).Strategy;
                      aStrategy.Delete();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Rollback();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Rollback();
                      Assert.True(aStrategy.IsDeleted);
  
                      // instantiate
                      aStrategy = C1.Create(databaseSession).Strategy;
                      id = aStrategy.ObjectId;
  
                      aStrategy.Delete();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Rollback();
                      aStrategy = databaseSession.InstantiateStrategy(id);
                      Assert.Null(aStrategy);
  
                      databaseSession.Rollback();
                      aStrategy = databaseSession.InstantiateStrategy(id);
                      Assert.Null(aStrategy);
  
                      //// Commit + Rollback + Rollback
  
                      aStrategy = C1.Create(databaseSession).Strategy;
  
                      databaseSession.Commit();
  
                      aStrategy.Delete();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Rollback();
                      Assert.False(aStrategy.IsDeleted);
  
                      databaseSession.Rollback();
                      Assert.False(aStrategy.IsDeleted);
  
                      // instantiate
                      aStrategy = C1.Create(databaseSession).Strategy;
                      id = aStrategy.ObjectId;
  
                      databaseSession.Commit();
  
                      aStrategy.Delete();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Rollback();
                      aStrategy = databaseSession.InstantiateStrategy(id);
                      Assert.False(aStrategy.IsDeleted);
  
                      databaseSession.Rollback();
                      aStrategy = databaseSession.InstantiateStrategy(id);
                      Assert.False(aStrategy.IsDeleted);
  
                      //// Nothing + Rollback + Commit
  
                      aStrategy = C1.Create(databaseSession).Strategy;
  
                      aStrategy.Delete();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Rollback();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Commit();
                      Assert.True(aStrategy.IsDeleted);
  
                      // instantiate
                      aStrategy = C1.Create(databaseSession).Strategy;
                      id = aStrategy.ObjectId;
  
                      aStrategy.Delete();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Rollback();
                      aStrategy = databaseSession.InstantiateStrategy(id);
                      Assert.Null(aStrategy);
  
                      databaseSession.Rollback();
                      aStrategy = databaseSession.InstantiateStrategy(id);
                      Assert.Null(aStrategy);
  
                      //// Commit + Rollback + Commit
  
                      aStrategy = C1.Create(databaseSession).Strategy;
  
                      databaseSession.Commit();
  
                      aStrategy.Delete();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Rollback();
                      Assert.False(aStrategy.IsDeleted);
  
                      databaseSession.Commit();
                      Assert.False(aStrategy.IsDeleted);
  
                      // instantiate
                      aStrategy = C1.Create(databaseSession).Strategy;
                      id = aStrategy.ObjectId;
  
                      databaseSession.Commit();
  
                      aStrategy.Delete();
                      Assert.True(aStrategy.IsDeleted);
  
                      databaseSession.Rollback();
                      aStrategy = databaseSession.InstantiateStrategy(id);
                      Assert.False(aStrategy.IsDeleted);
  
                      databaseSession.Rollback();
                      aStrategy = databaseSession.InstantiateStrategy(id);
                      Assert.False(aStrategy.IsDeleted);
  
                      // Clean up
                      databaseSession.Commit();
                      foreach (C1 removeObject in this.GetExtent(MetaC1.Instance.ObjectType))
                      {
                          removeObject.Strategy.Delete();
                      }
  
                      databaseSession.Commit();
                  }
  
                  //// Units
  
                  anObject = C1.Create(this.Session);
                  anObject.C1AllorsString = "a";
                  anObject.Strategy.Delete();
  
                  StrategyAssert.RoleExistHasException(anObject, MetaC1.Instance.C1AllorsString);
  
                  anObject = C1.Create(this.Session);
                  anObject.C1AllorsString = "a";
                  anObject.Strategy.Delete();
  
                  StrategyAssert.RoleGetHasException(anObject, MetaC1.Instance.C1AllorsString);
  
                  var secondObject = C1.Create(this.Session);
                  secondObject.C1AllorsString = "b";
                  var thirdObject = C1.Create(this.Session);
                  thirdObject.C1AllorsString = "c";
  
                  Assert.Equal(2, this.GetExtent(MetaC1.Instance.ObjectType).Length);
                  thirdObject.Strategy.Delete();
  
                  Assert.Single(this.GetExtent(MetaC1.Instance.ObjectType));
                  Assert.Equal("b", ((C1)this.GetExtent(MetaC1.Instance.ObjectType)[0]).C1AllorsString);
  
                  secondObject.Strategy.Delete();
  
                  //// Cached
  
                  anObject = C1.Create(this.Session);
                  anObject.C1AllorsString = "a";
  
                  AllorsTestUtils.ForceRoleCaching(anObject);
  
                  anObject.Strategy.Delete();
  
                  StrategyAssert.RoleExistHasException(anObject, MetaC1.Instance.C1AllorsString);
  
                  anObject = C1.Create(this.Session);
                  anObject.C1AllorsString = "a";
  
                  AllorsTestUtils.ForceRoleCaching(anObject);
  
                  anObject.Strategy.Delete();
  
                  StrategyAssert.RoleGetHasException(anObject, MetaC1.Instance.C1AllorsString);
  
                  secondObject = C1.Create(this.Session);
                  secondObject.C1AllorsString = "b";
                  thirdObject = C1.Create(this.Session);
                  thirdObject.C1AllorsString = "c";
  
                  Assert.Equal(2, this.GetExtent(MetaC1.Instance.ObjectType).Length);
  
                  AllorsTestUtils.ForceRoleCaching(secondObject);
                  AllorsTestUtils.ForceRoleCaching(thirdObject);
  
                  thirdObject.Strategy.Delete();
  
                  Assert.Single(this.GetExtent(MetaC1.Instance.ObjectType));
                  Assert.Equal("b", ((C1)this.GetExtent(MetaC1.Instance.ObjectType)[0]).C1AllorsString);
  
                  secondObject.Strategy.Delete();
  
                  //// Commit
  
                  anObject = C1.Create(this.Session);
                  anObject.C1AllorsString = "a";
                  anObject.Strategy.Delete();
  
                  this.Session.Commit();
  
                  StrategyAssert.RoleExistHasException(anObject, MetaC1.Instance.C1AllorsString);
  
                  anObject = C1.Create(this.Session);
                  anObject.C1AllorsString = "a";
                  anObject.Strategy.Delete();
  
                  this.Session.Commit();
  
                  StrategyAssert.RoleGetHasException(anObject, MetaC1.Instance.C1AllorsString);
  
                  secondObject = C1.Create(this.Session);
                  secondObject.C1AllorsString = "b";
                  thirdObject = C1.Create(this.Session);
                  thirdObject.C1AllorsString = "c";
  
                  Assert.Equal(2, this.GetExtent(MetaC1.Instance.ObjectType).Length);
                  thirdObject.Strategy.Delete();
  
                  this.Session.Commit();
  
                  Assert.Single(this.GetExtent(MetaC1.Instance.ObjectType));
                  Assert.Equal("b", ((C1)this.GetExtent(MetaC1.Instance.ObjectType)[0]).C1AllorsString);
  
                  secondObject.Strategy.Delete();
  
                  this.Session.Commit();
  
                  //// Cached
  
                  anObject = C1.Create(this.Session);
                  anObject.C1AllorsString = "a";
  
                  AllorsTestUtils.ForceRoleCaching(anObject);
  
                  anObject.Strategy.Delete();
                  this.Session.Commit();
  
                  StrategyAssert.RoleExistHasException(anObject, MetaC1.Instance.C1AllorsString);
  
                  anObject = C1.Create(this.Session);
                  anObject.C1AllorsString = "a";
  
                  AllorsTestUtils.ForceRoleCaching(anObject);
  
                  anObject.Strategy.Delete();
                  this.Session.Commit();
  
                  StrategyAssert.RoleGetHasException(anObject, MetaC1.Instance.C1AllorsString);
  
                  secondObject = C1.Create(this.Session);
                  secondObject.C1AllorsString = "b";
                  thirdObject = C1.Create(this.Session);
                  thirdObject.C1AllorsString = "c";
  
                  Assert.Equal(2, this.GetExtent(MetaC1.Instance.ObjectType).Length);
  
                  AllorsTestUtils.ForceRoleCaching(secondObject);
                  AllorsTestUtils.ForceRoleCaching(thirdObject);
  
                  thirdObject.Strategy.Delete();
                  this.Session.Commit();
  
                  Assert.Single(this.GetExtent(MetaC1.Instance.ObjectType));
                  Assert.Equal("b", ((C1)this.GetExtent(MetaC1.Instance.ObjectType)[0]).C1AllorsString);
  
                  secondObject.Strategy.Delete();
                  this.Session.Commit();
  
                  //// Rollback
  
                  anObject = C1.Create(this.Session);
                  anObject.C1AllorsString = "a";
                  this.Session.Commit();
  
                  anObject.Strategy.Delete();
  
                  this.Session.Rollback();
  
                  Assert.Single(this.GetExtent(MetaC1.Instance.ObjectType));
                  Assert.Equal("a", ((C1)this.GetExtent(MetaC1.Instance.ObjectType)[0]).C1AllorsString);
  
                  secondObject = C1.Create(this.Session);
                  secondObject.C1AllorsString = "b";
                  thirdObject = C1.Create(this.Session);
                  thirdObject.C1AllorsString = "c";
  
                  Assert.Equal(3, this.GetExtent(MetaC1.Instance.ObjectType).Length);
                  thirdObject.Strategy.Delete();
  
                  this.Session.Rollback();
  
                  Assert.Single(this.GetExtent(MetaC1.Instance.ObjectType));
                  Assert.Equal("a", ((C1)this.GetExtent(MetaC1.Instance.ObjectType)[0]).C1AllorsString);
  
                  anObject.Strategy.Delete();
  
                  this.Session.Commit();
  
                  //// Cached
  
                  anObject = C1.Create(this.Session);
                  anObject.C1AllorsString = "a";
                  this.Session.Commit();
  
                  AllorsTestUtils.ForceRoleCaching(anObject);
  
                  anObject.Strategy.Delete();
                  this.Session.Rollback();
  
                  Assert.Single(this.GetExtent(MetaC1.Instance.ObjectType));
                  Assert.Equal("a", ((C1)this.GetExtent(MetaC1.Instance.ObjectType)[0]).C1AllorsString);
  
  
gt:                 secondObject = C1.Create(this.Session);