context: // --------------------------------------------------------------------------------------------------------------------
  // <copyright file="ValuesTest.cs" company="Allors bvba">
  //   Copyright 2002-2012 Allors bvba.
  // Dual Licensed under
  //   a) the Lesser General Public Licence v3 (LGPL)
  //   b) the Allors License
  // The LGPL License is included in the file lgpl.txt.
  // The Allors License is an addendum to your contract.
  // Allors Platform is distributed in the hope that it will be useful,
  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  // GNU General Public License for more details.
  // For more information visit http://www.allors.com/legal
  // </copyright>
  // --------------------------------------------------------------------------------------------------------------------
  
  namespace Allors1.Adapters.General
  {
      using System;
  
      using Allors.Meta;
  
      using NUnit.Framework;
  
      public abstract class ValuesTest : Test
      {
          protected TestValues testValues = new TestValues();
  
          protected virtual int[] BinarySizes
          {
              get
              {
                  return new[]
                             {
                                 0, 
                                 1, 
                                 2, 
                                 8000 - 1, 
                                 8000, // SqlClient
                                 8000 + 1, 
                                 2 ^ 16 - 1, 
                                 2 ^ 16, // MySqlClient
                                 2 ^ 16 + 1, 
                                 2 ^ 32 - 1, 
                                 2 ^ 32, // MySqlClient
                                 2 ^ 32 + 1
                             };
              }
          }
  
          protected virtual int[] StringSizes
          {
              get
              {
                  return new[]
                             {
                                 0, 
                                 1, 
                                 2, 
                                 4000 - 1, 
                                 4000, // SqlClient
                                 4000 + 1, 
                                 8000 - 1, 
                                 8000, // SqlClient
                                 8000 + 1, 
                                 2 ^ 16 - 1, 
                                 2 ^ 16, // MySqlClient
                                 2 ^ 16 + 1, 
                                 2 ^ 32 - 1, 
                                 2 ^ 32, // MySqlClient
                                 2 ^ 32 + 1
                             };
              }
          }
  
          [Test]
          [Category("Dynamic")]
          public void AllorsBinary()
          {
              bool[] transactionFlags = { false, true };
  
              for (int transactionFlagIndex = 0; transactionFlagIndex < transactionFlags.Length; transactionFlagIndex++)
              {
                  var transactionFlag = transactionFlags[transactionFlagIndex];
  
                  // Set
                  for (int binarySizeIndex = 0; binarySizeIndex < this.BinarySizes.Length; binarySizeIndex++)
                  {
                      int binarySize = this.BinarySizes[binarySizeIndex];
  
                      for (int testTypeIndex = 0; testTypeIndex < this.GetTestTypes().Length; testTypeIndex++)
                      {
                          var testType = this.GetTestTypes()[testTypeIndex];
                          var allorsObject = this.GetSession().Create(testType);
                          if (transactionFlag)
                          {
                              this.GetSession().Commit();
                          }
  
                          var testRoleTypes = this.GetBinaryRoles(testType);
                          for (int testRoleTypeIndex = 0; testRoleTypeIndex < testRoleTypes.Length; testRoleTypeIndex++)
                          {
                              var testRoleType = testRoleTypes[testRoleTypeIndex];
                              byte[] value = this.ValueGenerator.GenerateBinary(binarySize);
  
                              if (binarySize < testRoleType.Size)
                              {
                                  allorsObject.Strategy.SetUnitRole(testRoleType, value);
                                  if (transactionFlag)
                                  {
                                      this.GetSession().Commit();
                                  }
  
                                  Assert.AreEqual(value, allorsObject.Strategy.GetUnitRole(testRoleType));
                                  Assert.AreEqual(value, allorsObject.Strategy.GetUnitRole(testRoleType));
                              }
                          }
                      }
                  }
              }
          }
  
          [Test]
          [Category("Dynamic")]
          public void AllorsBoolean()
          {
              bool[] transactionFlags = { false, true };
              bool[] values = this.testValues.Booleans;
  
              for (int transactionFlagIndex = 0; transactionFlagIndex < transactionFlags.Length; transactionFlagIndex++)
              {
                  var transactionFlag = transactionFlags[transactionFlagIndex];
                  
                  // Set
                  for (int valueIndex = 0; valueIndex < values.Length; valueIndex++)
                  {
                      bool value = values[valueIndex];
                      for (int testTypeIndex = 0; testTypeIndex < this.GetTestTypes().Length; testTypeIndex++)
                      {
                          var testType = this.GetTestTypes()[testTypeIndex];
                          var allorsObject = this.GetSession().Create(testType);
                          if (transactionFlag)
                          {
                              this.GetSession().Commit();
                          }
  
                          var testRoleTypes = this.GetBooleanRoles(testType);
                          for (int testRoleTypeIndex = 0; testRoleTypeIndex < testRoleTypes.Length; testRoleTypeIndex++)
                          {
                              var testRoleType = testRoleTypes[testRoleTypeIndex];
                              allorsObject.Strategy.SetUnitRole(testRoleType, value);
                              if (transactionFlag)
                              {
                                  this.GetSession().Commit();
                              }
  
                              Assert.AreEqual(value, (bool)allorsObject.Strategy.GetUnitRole(testRoleType));
                              Assert.AreEqual(value, (bool)allorsObject.Strategy.GetUnitRole(testRoleType));
                          }
                      }
                  }
  
                  // Initial empty
                  for (int testTypeIndex = 0; testTypeIndex < this.GetTestTypes().Length; testTypeIndex++)
                  {
                      var testType = this.GetTestTypes()[testTypeIndex];
                      var allorsObject = this.GetSession().Create(testType);
                      if (transactionFlag)
                      {
                          this.GetSession().Commit();
                      }
  
                      var testRoleTypes = this.GetBooleanRoles(testType);
                      for (int testRoleTypeIndex = 0; testRoleTypeIndex < testRoleTypes.Length; testRoleTypeIndex++)
                      {
                          var testRoleType = testRoleTypes[testRoleTypeIndex];
  
                          Assert.IsFalse(allorsObject.Strategy.ExistRole(testRoleType));
                          Assert.IsFalse(allorsObject.Strategy.ExistRole(testRoleType));
  
                          if (transactionFlag)
                          {
                              this.GetSession().Commit();
                          }
  
                          Assert.IsFalse(allorsObject.Strategy.ExistRole(testRoleType));
                          Assert.IsFalse(allorsObject.Strategy.ExistRole(testRoleType));
                      }
                  }
  
                  // Remove
                  for (int valueIndex = 0; valueIndex < values.Length; valueIndex++)
                  {
                      bool value = values[valueIndex];
                      for (int testTypeIndex = 0; testTypeIndex < this.GetTestTypes().Length; testTypeIndex++)
                      {
                          var testType = this.GetTestTypes()[testTypeIndex];
                          var allorsObject = this.GetSession().Create(testType);
  
                          var testRoleTypes = this.GetBooleanRoles(testType);
                          for (int testRoleTypeIndex = 0; testRoleTypeIndex < testRoleTypes.Length; testRoleTypeIndex++)
                          {
                              var testRoleType = testRoleTypes[testRoleTypeIndex];
                              allorsObject.Strategy.SetUnitRole(testRoleType, value);
                              if (transactionFlag)
                              {
                                  this.GetSession().Commit();
                              }
  
                              Assert.IsTrue(allorsObject.Strategy.ExistRole(testRoleType));
                              Assert.IsTrue(allorsObject.Strategy.ExistRole(testRoleType));
  
                              allorsObject.Strategy.RemoveRole(testRoleType);
                              if (transactionFlag)
                              {
                                  this.GetSession().Commit();
                              }
  
                              if (transactionFlag)
                              {
                                  this.GetSession().Commit();
                              }
  
                              Assert.IsFalse(allorsObject.Strategy.ExistRole(testRoleType));
                              Assert.IsFalse(allorsObject.Strategy.ExistRole(testRoleType));
  
                              Assert.IsFalse(allorsObject.Strategy.ExistRole(testRoleType));
                              Assert.IsFalse(allorsObject.Strategy.ExistRole(testRoleType));
                          }
                      }
                  }
              }
  
              if (this.IsRollbackSupported())
              {
                  // Set
                  for (int valueIndex = 0; valueIndex < values.Length; valueIndex++)
                  {
                      bool value = values[valueIndex];
                      for (int testTypeIndex = 0; testTypeIndex < this.GetTestTypes().Length; testTypeIndex++)
                      {
                          var testType = this.GetTestTypes()[testTypeIndex];
                          var allorsObject = this.GetSession().Create(testType);
                          this.GetSession().Commit();
  
                          var testRoleTypes = this.GetBooleanRoles(testType);
                          for (int testRoleTypeIndex = 0; testRoleTypeIndex < testRoleTypes.Length; testRoleTypeIndex++)
                          {
                              var testRoleType = testRoleTypes[testRoleTypeIndex];
                              allorsObject.Strategy.SetUnitRole(testRoleType, value);
  
                              this.GetSession().Rollback();
  
                              Assert.IsFalse(allorsObject.Strategy.ExistRole(testRoleType));
                              Assert.IsFalse(allorsObject.Strategy.ExistRole(testRoleType));
                          }
                      }
                  }
  
                  // Commit Set Rollback
                  for (int valueIndex = 0; valueIndex < values.Length; valueIndex++)
                  {
                      bool value = values[valueIndex];
                      for (int testTypeIndex = 0; testTypeIndex < this.GetTestTypes().Length; testTypeIndex++)
                      {
                          var testType = this.GetTestTypes()[testTypeIndex];
                          var allorsObject = this.GetSession().Create(testType);
  
                          var testRoleTypes = this.GetBooleanRoles(testType);
                          for (int testRoleTypeIndex = 0; testRoleTypeIndex < testRoleTypes.Length; testRoleTypeIndex++)
                          {
                              var testRoleType = testRoleTypes[testRoleTypeIndex];
                              allorsObject.Strategy.SetUnitRole(testRoleType, value);
  
                              this.GetSession().Commit();
  
                              bool value2 = !value;
  
                              allorsObject.Strategy.SetUnitRole(testRoleType, value2);
  
                              this.GetSession().Rollback();
  
                              Assert.IsTrue(allorsObject.Strategy.ExistRole(testRoleType));
                              Assert.IsTrue(allorsObject.Strategy.ExistRole(testRoleType));
                              Assert.AreEqual(value, (bool)allorsObject.Strategy.GetUnitRole(testRoleType));
                              Assert.AreEqual(value, (bool)allorsObject.Strategy.GetUnitRole(testRoleType));
                          }
                      }
                  }
  
                  // Commit Remove Rollback
                  for (int valueIndex = 0; valueIndex < values.Length; valueIndex++)
                  {
                      bool value = values[valueIndex];
                      for (int testTypeIndex = 0; testTypeIndex < this.GetTestTypes().Length; testTypeIndex++)
                      {
  
gt:                         var testType = this.GetTestTypes()[testTypeIndex];