This commit is contained in:
@@ -49,7 +49,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="nunit.framework, Version=2.5.10.11092, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
|
||||
<Reference Include="nunit.framework, Version=2.6.2.12296, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.SQLite">
|
||||
@@ -61,6 +61,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DynamicClassBuilderTest.cs" />
|
||||
<Compile Include="Helpers\Dynamic\DynamicParserTests.cs" />
|
||||
<Compile Include="Helpers\PoolingTests.cs" />
|
||||
<Compile Include="Modify\DynamicModificationTests.cs" />
|
||||
|
||||
108
DynamORM.Tests/DynamicClassBuilderTest.cs
Normal file
108
DynamORM.Tests/DynamicClassBuilderTest.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace DynamORM.Tests
|
||||
{
|
||||
public class DynamicProduct : IDictionary
|
||||
{
|
||||
private IDictionary _dict = null;
|
||||
|
||||
public DynamicProduct(IDictionary dict)
|
||||
{
|
||||
_dict = dict;
|
||||
}
|
||||
|
||||
// Properties from dict
|
||||
public int ID
|
||||
{
|
||||
get { return (int)(_dict["ID"] ?? 0); }
|
||||
set
|
||||
{
|
||||
if (!IsReadOnly)
|
||||
_dict["ID"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return (string)(_dict["Name"] ?? 0); }
|
||||
set
|
||||
{
|
||||
if (!IsReadOnly)
|
||||
_dict["Name"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime Delivery
|
||||
{
|
||||
get { return (DateTime)(_dict["Delivery"] ?? 0); }
|
||||
set
|
||||
{
|
||||
if (!IsReadOnly)
|
||||
_dict["Delivery"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public object Data
|
||||
{
|
||||
get { return (object)(_dict["Data"] ?? 0); }
|
||||
set
|
||||
{
|
||||
if (!IsReadOnly)
|
||||
_dict["Data"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
// IDictionary implementation
|
||||
public void Add(object key, object value)
|
||||
{
|
||||
_dict.Add(key, value);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_dict.Clear();
|
||||
}
|
||||
|
||||
public bool Contains(object key)
|
||||
{
|
||||
return _dict.Contains(key);
|
||||
}
|
||||
|
||||
public IDictionaryEnumerator GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public void Remove(object key)
|
||||
{
|
||||
_dict.Remove(key);
|
||||
}
|
||||
|
||||
public void CopyTo(System.Array array, int index)
|
||||
{
|
||||
_dict.CopyTo(array, index);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return _dict.GetEnumerator();
|
||||
}
|
||||
|
||||
public bool IsFixedSize { get { return _dict.IsFixedSize; } }
|
||||
|
||||
public bool IsReadOnly { get { return _dict.IsReadOnly; } }
|
||||
|
||||
public ICollection Keys { get { return _dict.Keys; } }
|
||||
|
||||
public ICollection Values { get { return _dict.Values; } }
|
||||
|
||||
public object this[object key] { get { return _dict[key]; } set { _dict[key] = value; } }
|
||||
|
||||
public int Count { get { return _dict.Count; } }
|
||||
|
||||
public bool IsSynchronized { get { return _dict.IsSynchronized; } }
|
||||
|
||||
public object SyncRoot { get { return _dict.SyncRoot; } }
|
||||
}
|
||||
}
|
||||
@@ -180,6 +180,19 @@ namespace DynamORM.Tests.Select
|
||||
Assert.AreEqual("SELECT * FROM (SELECT * FROM \"dbo\".\"Users\") AS u", cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests from method using invoke with sub query.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestFromSubQuery3()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.SubQuery((b, s) => b.From(y => y(s.From(x => x.dbo.Users)).As("u")));
|
||||
|
||||
Assert.AreEqual("SELECT * FROM (SELECT * FROM \"dbo\".\"Users\") AS u", cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests where method with alias.
|
||||
/// </summary>
|
||||
@@ -341,6 +354,21 @@ namespace DynamORM.Tests.Select
|
||||
Assert.AreEqual(string.Format("SELECT usr.*, uc.\"Users\" FROM \"dbo\".\"Users\" AS usr INNER JOIN \"dbo\".\"UserClients\" AS uc ON ((usr.\"Id_User\" = uc.\"User_Id\") AND (uc.\"Users\" IS NOT NULL))"), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests from method using invoke with sub query.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestInnerJoin3()
|
||||
{
|
||||
IDynamicSelectQueryBuilder cmd = new DynamicSelectQueryBuilder(Database);
|
||||
|
||||
cmd.From(u => u.dbo.Users.As(u.usr))
|
||||
.SubQuery((b, s) => b.Join(usr => usr(s.From(x => x.dbo.UserClients)).Inner().As(usr.uc).On(usr.Id_User == usr.uc.User_Id && usr.uc.Users != null)))
|
||||
.Select(usr => usr.All(), uc => uc.Users);
|
||||
|
||||
Assert.AreEqual(string.Format("SELECT usr.*, uc.\"Users\" FROM \"dbo\".\"Users\" AS usr INNER JOIN (SELECT * FROM \"dbo\".\"UserClients\") AS uc ON ((usr.\"Id_User\" = uc.\"User_Id\") AND (uc.\"Users\" IS NOT NULL))"), cmd.CommandText());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests left outer join method.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user