Modernize tests, remove Tester project, and automate amalgamation pipeline

This commit is contained in:
root
2026-02-26 09:20:27 +01:00
parent 16ac17cd56
commit fcf44df4ad
30 changed files with 17651 additions and 19236 deletions

View File

@@ -1,64 +1,64 @@
/*
* DynamORM - Dynamic Object-Relational Mapping library.
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace DynamORM.Tests.Helpers
{
/// <summary>Class responsible for users operations testing.</summary>
[TestClass]
public class AttachToDebugger
{
/// <summary>Test anonymous type compatibility.</summary>
[TestMethod]
public void TestAnonType()
{
var a = new { x = 1, y = 2 };
var b = new { x = 3, y = 4 };
Assert.AreEqual(a.GetType(), b.GetType());
}
/// <summary>Test anonymous type value.</summary>
[TestMethod]
public void TestAnonTypeValue()
{
var a = new { x = 1, y = "bla bla" };
var b = new { x = 1, y = "bla bla" };
Assert.AreEqual(a, b);
Assert.IsTrue(a.Equals(b));
Dictionary<object, int> dict = new Dictionary<object, int>() { { a, 999 } };
Assert.IsTrue(dict.ContainsKey(b));
}
}
/*
* DynamORM - Dynamic Object-Relational Mapping library.
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
using System.Collections.Generic;
using System.Diagnostics;
using NUnit.Framework;
namespace DynamORM.Tests.Helpers
{
/// <summary>Class responsible for users operations testing.</summary>
[TestFixture]
public class AttachToDebugger
{
/// <summary>Test anonymous type compatibility.</summary>
[Test]
public void TestAnonType()
{
var a = new { x = 1, y = 2 };
var b = new { x = 3, y = 4 };
Assert.AreEqual(a.GetType(), b.GetType());
}
/// <summary>Test anonymous type value.</summary>
[Test]
public void TestAnonTypeValue()
{
var a = new { x = 1, y = "bla bla" };
var b = new { x = 1, y = "bla bla" };
Assert.AreEqual(a, b);
Assert.IsTrue(a.Equals(b));
Dictionary<object, int> dict = new Dictionary<object, int>() { { a, 999 } };
Assert.IsTrue(dict.ContainsKey(b));
}
}
}

View File

@@ -1,121 +1,121 @@
/*
* DynamORM - Dynamic Object-Relational Mapping library.
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using DynamORM.Helpers.Dynamics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace DynamORM.Tests.Helpers.Dynamic
{
/// <summary><see cref="DynamicParser"/> tests.</summary>
[TestClass]
public class DynamicParserTests
{
/// <summary>
/// Tests the get member.
/// </summary>
[TestMethod]
public void TestGetMember()
{
Func<dynamic, object> f = x => x.SomePropery;
var val = DynamicParser.Parse(f).Result as DynamicParser.Node.GetMember;
Assert.IsNotNull(val);
Assert.AreEqual("SomePropery", val.Name);
}
/// <summary>
/// Tests the set member.
/// </summary>
[TestMethod]
public void TestSetMember()
{
Func<dynamic, object> f = x => x.SomePropery = "value";
var val = DynamicParser.Parse(f).Result as DynamicParser.Node.SetMember;
Assert.IsNotNull(val);
Assert.AreEqual("SomePropery", val.Name);
Assert.AreEqual("value", val.Value);
}
/// <summary>
/// Tests the index of the get.
/// </summary>
[TestMethod]
public void TestGetIndex()
{
Func<dynamic, object> f = x => x.SomePropery[0];
var val = DynamicParser.Parse(f).Result as DynamicParser.Node.GetIndex;
Assert.IsNotNull(val);
}
/// <summary>
/// Tests the index of the set.
/// </summary>
[TestMethod]
public void TestSetIndex()
{
Func<dynamic, object> f = x => x.SomePropery[0] = "value";
var val = DynamicParser.Parse(f).Result as DynamicParser.Node.SetIndex;
Assert.IsNotNull(val);
Assert.AreEqual("value", val.Value);
}
/// <summary>
/// Tests something.
/// </summary>
[TestMethod]
public void TestSomething()
{
Func<dynamic, object> f = x => x.SomePropery == "value" || x.OtherProperty == -1;
var p = DynamicParser.Parse(f);
var val = p.Result as DynamicParser.Node.Binary;
Assert.IsNotNull(val);
var left = val.Host as DynamicParser.Node.Binary;
var right = val.Right as DynamicParser.Node.Binary;
Assert.IsNotNull(left);
Assert.IsNotNull(right);
Assert.IsInstanceOfType(left.Host, typeof(DynamicParser.Node.GetMember));
Assert.IsInstanceOfType(right.Host, typeof(DynamicParser.Node.GetMember));
Assert.AreEqual("value", left.Right);
Assert.AreEqual(-1, right.Right);
}
}
/*
* DynamORM - Dynamic Object-Relational Mapping library.
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using DynamORM.Helpers.Dynamics;
using NUnit.Framework;
namespace DynamORM.Tests.Helpers.Dynamic
{
/// <summary><see cref="DynamicParser"/> tests.</summary>
[TestFixture]
public class DynamicParserTests
{
/// <summary>
/// Tests the get member.
/// </summary>
[Test]
public void TestGetMember()
{
Func<dynamic, object> f = x => x.SomePropery;
var val = DynamicParser.Parse(f).Result as DynamicParser.Node.GetMember;
Assert.IsNotNull(val);
Assert.AreEqual("SomePropery", val.Name);
}
/// <summary>
/// Tests the set member.
/// </summary>
[Test]
public void TestSetMember()
{
Func<dynamic, object> f = x => x.SomePropery = "value";
var val = DynamicParser.Parse(f).Result as DynamicParser.Node.SetMember;
Assert.IsNotNull(val);
Assert.AreEqual("SomePropery", val.Name);
Assert.AreEqual("value", val.Value);
}
/// <summary>
/// Tests the index of the get.
/// </summary>
[Test]
public void TestGetIndex()
{
Func<dynamic, object> f = x => x.SomePropery[0];
var val = DynamicParser.Parse(f).Result as DynamicParser.Node.GetIndex;
Assert.IsNotNull(val);
}
/// <summary>
/// Tests the index of the set.
/// </summary>
[Test]
public void TestSetIndex()
{
Func<dynamic, object> f = x => x.SomePropery[0] = "value";
var val = DynamicParser.Parse(f).Result as DynamicParser.Node.SetIndex;
Assert.IsNotNull(val);
Assert.AreEqual("value", val.Value);
}
/// <summary>
/// Tests something.
/// </summary>
[Test]
public void TestSomething()
{
Func<dynamic, object> f = x => x.SomePropery == "value" || x.OtherProperty == -1;
var p = DynamicParser.Parse(f);
var val = p.Result as DynamicParser.Node.Binary;
Assert.IsNotNull(val);
var left = val.Host as DynamicParser.Node.Binary;
var right = val.Right as DynamicParser.Node.Binary;
Assert.IsNotNull(left);
Assert.IsNotNull(right);
Assert.IsInstanceOf<DynamicParser.Node.GetMember>(left.Host);
Assert.IsInstanceOf<DynamicParser.Node.GetMember>(right.Host);
Assert.AreEqual("value", left.Right);
Assert.AreEqual(-1, right.Right);
}
}
}

View File

@@ -1,100 +1,100 @@
/*
* DynamORM - Dynamic Object-Relational Mapping library.
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace DynamORM.Tests.Helpers
{
/// <summary>Pooling tests.</summary>
[TestClass]
public class PoolingTests : TestsBase
{
/// <summary>Setup test parameters.</summary>
[TestInitialize]
public virtual void SetUp()
{
CreateTestDatabase();
}
/// <summary>Tear down test objects.</summary>
[TestCleanup]
public virtual void TearDown()
{
DestroyDynamicDatabase();
DestroyTestDatabase();
}
/// <summary>Test single mode command disposing.</summary>
[TestMethod]
public void TestSingleModeCommand()
{
CreateDynamicDatabase();
var cmd = Database.Open().CreateCommand();
cmd.SetCommand("SELECT COUNT(0) FROM sqlite_master;");
Database.Dispose();
Database = null;
Assert.ThrowsException<DynamicQueryException>(() => cmd.ExecuteScalar());
}
/// <summary>Test single mode transaction disposing.</summary>
[TestMethod]
public void TestSingleModeTransaction()
{
try
{
CreateDynamicDatabase();
using (var conn = Database.Open())
using (var trans = conn.BeginTransaction())
using (var cmd = conn.CreateCommand())
{
Assert.AreEqual(1, cmd.SetCommand("INSERT INTO \"users\" (\"code\") VALUES ('999');").ExecuteNonQuery());
Database.Dispose();
Database = null;
trans.Commit();
}
// Verify (rollback)
CreateDynamicDatabase();
Assert.AreEqual(0, Database.Table("users").Count(columns: "id", code: "999"));
}
finally
{
// Remove for next tests
Database.Dispose();
Database = null;
}
}
}
/*
* DynamORM - Dynamic Object-Relational Mapping library.
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
using NUnit.Framework;
namespace DynamORM.Tests.Helpers
{
/// <summary>Pooling tests.</summary>
[TestFixture]
public class PoolingTests : TestsBase
{
/// <summary>Setup test parameters.</summary>
[SetUp]
public virtual void SetUp()
{
CreateTestDatabase();
}
/// <summary>Tear down test objects.</summary>
[TearDown]
public virtual void TearDown()
{
DestroyDynamicDatabase();
DestroyTestDatabase();
}
/// <summary>Test single mode command disposing.</summary>
[Test]
public void TestSingleModeCommand()
{
CreateDynamicDatabase();
var cmd = Database.Open().CreateCommand();
cmd.SetCommand("SELECT COUNT(0) FROM sqlite_master;");
Database.Dispose();
Database = null;
Assert.Throws<DynamicQueryException>(() => cmd.ExecuteScalar());
}
/// <summary>Test single mode transaction disposing.</summary>
[Test]
public void TestSingleModeTransaction()
{
try
{
CreateDynamicDatabase();
using (var conn = Database.Open())
using (var trans = conn.BeginTransaction())
using (var cmd = conn.CreateCommand())
{
Assert.AreEqual(1, cmd.SetCommand("INSERT INTO \"users\" (\"code\") VALUES ('999');").ExecuteNonQuery());
Database.Dispose();
Database = null;
trans.Commit();
}
// Verify (rollback)
CreateDynamicDatabase();
Assert.AreEqual(0, Database.Table("users").Count(columns: "id", code: "999"));
}
finally
{
// Remove for next tests
Database.Dispose();
Database = null;
}
}
}
}

View File

@@ -1,80 +1,80 @@
/*
* DynamORM - Dynamic Object-Relational Mapping library.
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
using DynamORM.Mapper;
using DynamORM.Validation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace DynamORM.Tests.Helpers.Validation
{
[TestClass]
public class ObjectValidationTest
{
public class TestObject
{
[Required(1f, 10f)]
public int TestInt { get; set; }
[Required(7, false, false)]
public string CanBeNull { get; set; }
[Required(2, true)]
[Required(7, 18, ElementRequirement = true)]
public decimal[] ArrayTest { get; set; }
}
[TestMethod]
public void ValidateCorrectObject()
{
var result = DynamicMapperCache.GetMapper<TestObject>().ValidateObject(
new TestObject
{
TestInt = 2,
ArrayTest = new decimal[] { 7, 18 },
});
Assert.IsNotNull(result);
Assert.AreEqual(0, result.Count);
}
[TestMethod]
public void ValidateIncorrectObject()
{
var result = DynamicMapperCache.GetMapper<TestObject>().ValidateObject(
new TestObject
{
TestInt = 0,
CanBeNull = string.Empty,
ArrayTest = new decimal[] { 0, 0 },
});
Assert.IsNotNull(result);
Assert.AreEqual(4, result.Count);
}
}
/*
* DynamORM - Dynamic Object-Relational Mapping library.
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
using DynamORM.Mapper;
using DynamORM.Validation;
using NUnit.Framework;
namespace DynamORM.Tests.Helpers.Validation
{
[TestFixture]
public class ObjectValidationTest
{
public class TestObject
{
[Required(1f, 10f)]
public int TestInt { get; set; }
[Required(7, false, false)]
public string CanBeNull { get; set; }
[Required(2, true)]
[Required(7, 18, ElementRequirement = true)]
public decimal[] ArrayTest { get; set; }
}
[Test]
public void ValidateCorrectObject()
{
var result = DynamicMapperCache.GetMapper<TestObject>().ValidateObject(
new TestObject
{
TestInt = 2,
ArrayTest = new decimal[] { 7, 18 },
});
Assert.IsNotNull(result);
Assert.AreEqual(0, result.Count);
}
[Test]
public void ValidateIncorrectObject()
{
var result = DynamicMapperCache.GetMapper<TestObject>().ValidateObject(
new TestObject
{
TestInt = 0,
CanBeNull = string.Empty,
ArrayTest = new decimal[] { 0, 0 },
});
Assert.IsNotNull(result);
Assert.AreEqual(4, result.Count);
}
}
}