<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ output extension=".cs" #>

using System;
using System.Linq;
using NUnit.Framework;

namespace Xtensive.Orm.Tests.Upgrade.HugeModelUpgrade.ModelWithMappings
{
<# for(int i = 0; i < 200; i++) { #>
  [HierarchyRoot]
  [Index("Int16Field")]
  [Index("Int32Field")]
  [Index("Int64Field")]
  [Index("FloatField")]
  [Index("DoubleField")]
  [TableMapping("MappedEntity<#= i #>")]
  public class TestEntity<#= i #> : Entity {

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

    [Field]
    [FieldMapping("MappedBooleanField")]
    public bool BooleanField {get;set;}

    [Field]
    [FieldMapping("MappedInt16Field")]
    public Int16 Int16Field {get;set;}

    [Field]
    [FieldMapping("MappedInt32Field")]
    public Int32 Int32Field {get;set;}

    [Field]
    [FieldMapping("MappedInt64Field")]
    public Int64 Int64Field {get;set;}

    [Field]
    [FieldMapping("MappedFloatField")]
    public float FloatField {get;set;}

    [Field]
    [FieldMapping("MappedDoubleField")]
    public double DoubleField {get;set;}

    [Field]
    [FieldMapping("MappedDateTimeField")]
    public DateTime DateTimeField {get;set;}

    [Field]
    [FieldMapping("MappedStringField")]
    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 TestEntity<#= j #> TestEntity<#= j #>{get;set;}
<# if (index > 9) break; #>
<# if (0 - i < -1 )  #>

<# } #>

  }
<# } #>

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

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

<# } #>
    }
  }

}
