<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ output extension=".cs" #>
using System;
using System.Linq;
using NUnit.Framework;

namespace Xtensive.Orm.Tests.Upgrade.HugeModelUpgrade.TwoPartsModel
{
  namespace PartOne
  {
<# for(int i = 0; i < 100; i++) { #>
    [HierarchyRoot]
    [Index("Int16Field")]
    [Index("Int32Field")]
    [Index("Int64Field")]
    [Index("FloatField")]
    [Index("DoubleField")]
    public class TestEntityOne<#= i #> : Entity {

      [Key, Field]
      public long Id{get;set;}

      [Field]
      public bool BooleanField {get;set;}

      [Field]
      public Int16 Int16Field {get;set;}

      [Field]
      public Int32 Int32Field {get;set;}

      [Field]
      public Int64 Int64Field {get;set;}

      [Field]
      public float FloatField {get;set;}

      [Field]
      public double DoubleField {get;set;}

      [Field]
      public DateTime DateTimeField {get;set;}

      [Field]
      public string StringField {get;set;}

      [Field]
      [FullText("English")]
      public string Text {get;set;}

<# for (int j = i - 1, index = 0; j >= 0; j--, index++) { #>
      [Field]
      public TestEntityOne<#= j #> TestEntityOne<#= j #>{get;set;}
<# if (index > 9) break; #>
<# if (0 - i < -1 )  #>

<# } #>

    }
<# } #>
  }

  namespace PartTwo
  {
  <# for(int i = 0; i < 100; i++) { #>
    [HierarchyRoot]
    [Index("Int16Field")]
    [Index("Int32Field")]
    [Index("Int64Field")]
    [Index("FloatField")]
    [Index("DoubleField")]
    public class TestEntityTwo<#= i #> : Entity {

      [Key, Field]
      public long Id{get;set;}

      [Field]
      public bool BooleanField {get;set;}

      [Field]
      public Int16 Int16Field {get;set;}

      [Field]
      public Int32 Int32Field {get;set;}

      [Field]
      public Int64 Int64Field {get;set;}

      [Field]
      public float FloatField {get;set;}

      [Field]
      public double DoubleField {get;set;}

      [Field]
      public DateTime DateTimeField {get;set;}

      [Field]
      public string StringField {get;set;}

      [Field]
      [FullText("English")]
      public string Text {get;set;}

<# for (int j = i - 1, index = 0; j >= 0; j--, index++) { #>
      [Field]
      public TestEntityTwo<#= j #> TestEntityTwo<#= j #>{get;set;}
<# if (index > 9) break; #>
<# if (0 - i < -1 )  #>

<# } #>

    }
<# } #>
  }

  public class ModelPopulator
  {
    public void Run()
    {
<# for(int i = 0; i < 100; i++) { #>
      new PartOne.TestEntityOne<#= i #> {
          BooleanField = true,
          Int16Field = <#= i #>,
          Int32Field = <#= i #>,
          Int64Field = <#= i #>,
          FloatField = <#= i #>,
          DoubleField = <#= i #>,
          DateTimeField = DateTime.Now.Date,
          StringField = "TestEntityOne<#= i #>",
          Text = "This is an instance of TestEntityOne<#= i #>",
      };
      new PartTwo.TestEntityTwo<#= i #> {
          BooleanField = true,
          Int16Field = <#= i #>,
          Int32Field = <#= i #>,
          Int64Field = <#= i #>,
          FloatField = <#= i #>,
          DoubleField = <#= i #>,
          DateTimeField = DateTime.Now.Date,
          StringField = "TestEntityTwo<#= i #>",
          Text = "This is an instance of TestEntityTwo<#= i #>",
      };
<# } #>
    }
  }

  public class ModelChecker
  {
    public void Run(Session session)
    {
<# for(int i = 0; i < 100; i++) { #>
      var result<#= i #>0 = session.Query.All<PartOne.TestEntityOne<#= i #>>().ToArray();
      Assert.That(result<#= i #>0.Length, Is.EqualTo(1));
      Assert.That(result<#= i #>0[0].BooleanField, Is.True);
      Assert.That(result<#= i #>0[0].Int16Field, Is.EqualTo(<#= i #>));
      Assert.That(result<#= i #>0[0].Int32Field, Is.EqualTo(<#= i #>));
      Assert.That(result<#= i #>0[0].Int64Field, Is.EqualTo(<#= i #>));
      Assert.That(result<#= i #>0[0].FloatField, Is.EqualTo((float)<#= i #>));
      Assert.That(result<#= i #>0[0].DoubleField, Is.EqualTo((double)<#= i #>));
      Assert.That(result<#= i #>0[0].DateTimeField, Is.EqualTo(DateTime.Now.Date));
      Assert.That(result<#= i #>0[0].StringField, Is.EqualTo("TestEntityOne<#= i #>"));
      Assert.That(result<#= i #>0[0].Text, Is.EqualTo("This is an instance of TestEntityOne<#= i #>"));

      var result<#= i #>1 = session.Query.All<PartTwo.TestEntityTwo<#= i #>>().ToArray();
      Assert.That(result<#= i #>1.Length, Is.EqualTo(1));
      Assert.That(result<#= i #>1[0].BooleanField, Is.True);
      Assert.That(result<#= i #>1[0].Int16Field, Is.EqualTo(<#= i #>));
      Assert.That(result<#= i #>1[0].Int32Field, Is.EqualTo(<#= i #>));
      Assert.That(result<#= i #>1[0].Int64Field, Is.EqualTo(<#= i #>));
      Assert.That(result<#= i #>1[0].FloatField, Is.EqualTo((float)<#= i #>));
      Assert.That(result<#= i #>1[0].DoubleField, Is.EqualTo((double)<#= i #>));
      Assert.That(result<#= i #>1[0].DateTimeField, Is.EqualTo(DateTime.Now.Date));
      Assert.That(result<#= i #>1[0].StringField, Is.EqualTo("TestEntityTwo<#= i #>"));
      Assert.That(result<#= i #>1[0].Text, Is.EqualTo("This is an instance of TestEntityTwo<#= i #>"));
<# } #>
    }
  }
}