Append unit tests

pull/1/head
Ogoun 6 years ago
parent c800d3b7fc
commit 2f2703bdc9

@ -0,0 +1,62 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using ZeroLevel.Services.Collections;
namespace ZeroLevel.UnitTests
{
[TestClass]
public class CollectionsTests
{
[TestMethod]
public void RoundRobinCollectionTest()
{
// Arrange
var collection = new RoundRobinCollection<int>();
var iter1 = new int[] { 1, 2, 3 };
var iter2 = new int[] { 2, 3, 1 };
var iter3 = new int[] { 3, 1, 2 };
var iter11 = new int[] { 1, 3 };
var iter12 = new int[] { 3, 1 };
// Act
collection.Add(1);
collection.Add(2);
collection.Add(3);
// Assert
Assert.IsTrue(CollectionComparsionExtensions.OrderingEquals(collection.GetCurrentSeq().ToArray(), iter1));
Assert.IsTrue(CollectionComparsionExtensions.OrderingEquals(collection.GetCurrentSeq().ToArray(), iter1));
Assert.IsTrue(collection.MoveNext());
Assert.IsTrue(CollectionComparsionExtensions.OrderingEquals(collection.GetCurrentSeq().ToArray(), iter2));
Assert.IsTrue(CollectionComparsionExtensions.OrderingEquals(collection.GetCurrentSeq().ToArray(), iter2));
Assert.IsTrue(collection.MoveNext());
Assert.IsTrue(CollectionComparsionExtensions.OrderingEquals(collection.GetCurrentSeq().ToArray(), iter3));
Assert.IsTrue(CollectionComparsionExtensions.OrderingEquals(collection.GetCurrentSeq().ToArray(), iter3));
collection.Remove(2);
Assert.IsTrue(CollectionComparsionExtensions.OrderingEquals(collection.GetCurrentSeq().ToArray(), iter11));
Assert.IsTrue(CollectionComparsionExtensions.OrderingEquals(collection.GetCurrentSeq().ToArray(), iter11));
Assert.IsTrue(collection.MoveNext());
Assert.IsTrue(CollectionComparsionExtensions.OrderingEquals(collection.GetCurrentSeq().ToArray(), iter12));
Assert.IsTrue(CollectionComparsionExtensions.OrderingEquals(collection.GetCurrentSeq().ToArray(), iter12));
}
[TestMethod]
public void RoundRobinOverCollectionTest()
{
var arr = new int[] { 1, 2, 3 };
// Arrange
var collection = new RoundRobinOverCollection<int>(arr);
var iter1 = new int[] { 1, 2, 3 };
var iter2 = new int[] { 2, 3, 1 };
var iter3 = new int[] { 3, 1, 2 };
// Act
// Assert
Assert.IsTrue(CollectionComparsionExtensions.OrderingEquals(collection.GenerateSeq().ToArray(), iter1));
Assert.IsTrue(CollectionComparsionExtensions.OrderingEquals(collection.GenerateSeq().ToArray(), iter2));
Assert.IsTrue(CollectionComparsionExtensions.OrderingEquals(collection.GenerateSeq().ToArray(), iter3));
Assert.IsTrue(CollectionComparsionExtensions.OrderingEquals(collection.GenerateSeq().ToArray(), iter1));
Assert.IsTrue(CollectionComparsionExtensions.OrderingEquals(collection.GenerateSeq().ToArray(), iter2));
Assert.IsTrue(CollectionComparsionExtensions.OrderingEquals(collection.GenerateSeq().ToArray(), iter3));
}
}
}

@ -3,6 +3,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
using ZeroLevel.Services.ObjectMapping;
using ZeroMappingTest.Models;
using System.Collections.Generic;
using BusinessApp.DatabaseTest.Model;
namespace ZeroMappingTest
{
@ -203,5 +204,51 @@ namespace ZeroMappingTest
Assert.AreNotSame(mapper1, mapper3);
Assert.AreNotSame(mapper3, mapper2);
}
[TestMethod]
public void PocoFieldMapper()
{
// Arrange
var date = new DateTime(2005, 09, 27);
var mapper = new TypeMapper(typeof(PocoFields));
var obj = new PocoFields { Id = 1000, Date = date, Title = "Caption" };
// Assert
Assert.AreEqual(mapper.EntityType, typeof(PocoFields));
Assert.IsTrue(mapper.Exists("Id"));
Assert.IsTrue(mapper.Exists("Date"));
Assert.IsTrue(mapper.Exists("Title"));
Assert.AreEqual(mapper.Get(obj, "Id"), (long)1000);
Assert.AreEqual(mapper.Get(obj, "Date"), date);
Assert.AreEqual(mapper.Get(obj, "Title"), "Caption");
mapper.Set(obj, "Id", 1001);
Assert.AreEqual(mapper.Get(obj, "Id"), (long)1001);
}
[TestMethod]
public void PocoPropertiesMapper()
{
// Arrange
var date = new DateTime(2005, 09, 27);
var mapper = new TypeMapper(typeof(PocoProperties));
var obj = new PocoProperties { Id = 1000, Date = date, Title = "Caption" };
// Assert
Assert.AreEqual(mapper.EntityType, typeof(PocoProperties));
Assert.IsTrue(mapper.Exists("Id"));
Assert.IsTrue(mapper.Exists("Date"));
Assert.IsTrue(mapper.Exists("Title"));
Assert.AreEqual(mapper.Get(obj, "Id"), (long)1000);
Assert.AreEqual(mapper.Get(obj, "Date"), date);
Assert.AreEqual(mapper.Get(obj, "Title"), "Caption");
mapper.Set(obj, "Id", 1001);
Assert.AreEqual(mapper.Get(obj, "Id"), (long)1001);
}
}
}

@ -0,0 +1,11 @@
using System;
namespace BusinessApp.DatabaseTest.Model
{
public class PocoFields
{
public long Id;
public string Title;
public DateTime Date;
}
}

@ -0,0 +1,11 @@
using System;
namespace BusinessApp.DatabaseTest.Model
{
public class PocoProperties
{
public long Id { get; set; }
public string Title { get; set; }
public DateTime Date { get; set; }
}
}

@ -0,0 +1,21 @@
using ZeroLevel.Specification;
using ZeroSpecificationPatternsTest.Models;
namespace ZeroSpecificationPatternsTest.Specifications
{
public class IsFlagSpecification :
BaseSpecification<TestDTO>
{
private readonly bool _expected;
public IsFlagSpecification(bool expected)
{
_expected = expected;
}
public override bool IsSatisfiedBy(TestDTO o)
{
return o.IsFlag == _expected;
}
}
}

@ -0,0 +1,21 @@
using ZeroLevel.Specification;
using ZeroSpecificationPatternsTest.Models;
namespace ZeroSpecificationPatternsTest.Specifications
{
public class LongNumberSpecification :
BaseSpecification<TestDTO>
{
private readonly long _expected;
public LongNumberSpecification(long expected)
{
_expected = expected;
}
public override bool IsSatisfiedBy(TestDTO o)
{
return o.LongNumber == _expected;
}
}
}

@ -0,0 +1,21 @@
using ZeroLevel.Specification;
using ZeroSpecificationPatternsTest.Models;
namespace ZeroSpecificationPatternsTest.Specifications
{
public class NumberSpecification :
BaseSpecification<TestDTO>
{
private readonly int _expected;
public NumberSpecification(int expected)
{
_expected = expected;
}
public override bool IsSatisfiedBy(TestDTO o)
{
return o.Number == _expected;
}
}
}

@ -0,0 +1,21 @@
using ZeroLevel.Specification;
using ZeroSpecificationPatternsTest.Models;
namespace ZeroSpecificationPatternsTest.Specifications
{
public class RealSpecification :
BaseSpecification<TestDTO>
{
private readonly double _expected;
public RealSpecification(double expected)
{
_expected = expected;
}
public override bool IsSatisfiedBy(TestDTO o)
{
return o.Real == _expected;
}
}
}

@ -0,0 +1,21 @@
using ZeroLevel.Specification;
using ZeroSpecificationPatternsTest.Models;
namespace ZeroSpecificationPatternsTest.Specifications
{
public class SummarySpecification :
BaseSpecification<TestDTO>
{
private readonly string _expected;
public SummarySpecification(string expected)
{
_expected = expected;
}
public override bool IsSatisfiedBy(TestDTO o)
{
return o.Summary == _expected;
}
}
}

@ -0,0 +1,21 @@
using ZeroLevel.Specification;
using ZeroSpecificationPatternsTest.Models;
namespace ZeroSpecificationPatternsTest.Specifications
{
public class TitleSpecification :
BaseSpecification<TestDTO>
{
private readonly string _expected;
public TitleSpecification(string expected)
{
_expected = expected;
}
public override bool IsSatisfiedBy(TestDTO o)
{
return o.Title == _expected;
}
}
}

@ -0,0 +1,12 @@
namespace ZeroSpecificationPatternsTest.Models
{
public class TestDTO
{
public bool IsFlag { get; set; }
public int Number;
public long LongNumber;
public string Title { get; set; }
public string Summary;
public double Real;
}
}

@ -0,0 +1,114 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using ZeroLevel.Specification;
namespace ZeroSpecificationPatternsTest
{
[TestClass]
public class PredicateBuilderTests
{
[TestMethod]
public void PredicateBuilder_FromExpression_AND()
{
// Arrange
var expression = PredicateBuilder.True<string>();
// Act
var invoker = expression.
And(str => str.Length < 255).
And(str => char.IsLetter(str[0])).
And(str => char.IsUpper(str[0])).Compile();
// Assert
Assert.IsFalse(invoker("test"));
Assert.IsTrue(invoker("Test"));
Assert.IsFalse(invoker("1test"));
Assert.IsFalse(invoker("Test" + new string('_', 260)));
}
[TestMethod]
public void PredicateBuilder_FromFunc_AND()
{
// Arrange
var func = new Func<string, bool>(str => str.Length < 255);
// Act
var invoker = func.
And(str => str.Length < 255).
And(str => Char.IsLetter(str[0])).
And(str => Char.IsUpper(str[0])).Compile();
// Assert
Assert.IsFalse(invoker("test"));
Assert.IsTrue(invoker("Test"));
Assert.IsFalse(invoker("1test"));
Assert.IsFalse(invoker("Test" + new string('_', 260)));
}
[TestMethod]
public void PredicateBuilder_FromExpression_OR()
{
// Arrange
var expression = PredicateBuilder.
Create<string>(str => str.Equals("hello", StringComparison.OrdinalIgnoreCase));
// Act
var invoker = expression.
Or(str => str.Equals("world", StringComparison.OrdinalIgnoreCase)).
Or(str => str.Equals("test", StringComparison.OrdinalIgnoreCase)).
Or(str => str.Equals("wow", StringComparison.OrdinalIgnoreCase)).
Compile();
// Assert
Assert.IsTrue(invoker("hello"));
Assert.IsTrue(invoker("world"));
Assert.IsTrue(invoker("test"));
Assert.IsTrue(invoker("wow"));
Assert.IsFalse(invoker("Tests"));
}
[TestMethod]
public void PredicateBuilder_FromFunc_OR()
{
// Arrange
var func = new Func<string, bool>(str => str.Equals("hello", StringComparison.OrdinalIgnoreCase));
// Act
var invoker = func.
Or(str => str.Equals("world", StringComparison.OrdinalIgnoreCase)).
Or(str => str.Equals("test", StringComparison.OrdinalIgnoreCase)).
Or(str => str.Equals("wow", StringComparison.OrdinalIgnoreCase)).
Compile();
// Assert
Assert.IsTrue(invoker("hello"));
Assert.IsTrue(invoker("world"));
Assert.IsTrue(invoker("test"));
Assert.IsTrue(invoker("wow"));
Assert.IsFalse(invoker("Tests"));
}
[TestMethod]
public void PredicateBuilder_FromExpression_NOT()
{
// Arrange
var expression = PredicateBuilder.
Create<int>(i => i < 100 && i > 0);
// Act
var invoker = expression.Not().
Compile();
// Assert
Assert.IsFalse(invoker(1));
Assert.IsFalse(invoker(50));
Assert.IsTrue(invoker(100));
Assert.IsTrue(invoker(0));
}
[TestMethod]
public void PredicateBuilder_FromFunc_NOT()
{
// Arrange
var expression = new Func<int, bool>(i => i < 100 && i > 0);
// Act
var invoker = expression.Not().
Compile();
// Assert
Assert.IsFalse(invoker(1));
Assert.IsFalse(invoker(50));
Assert.IsTrue(invoker(100));
Assert.IsTrue(invoker(0));
}
}
}

@ -0,0 +1,190 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using ZeroLevel.Patterns.Queries;
using ZeroSpecificationPatternsTest.Models;
namespace ZeroSpecificationPatternsTest
{
/// <summary>
/// Summary description for UnitTest1
/// </summary>
[TestClass]
public class QueriesTests
{
private static bool TestDTOEqual(TestDTO left, TestDTO right)
{
if (left == null && right == null) return true;
if (left == null || right == null) return false;
if (left.IsFlag != right.IsFlag) return false;
if (left.LongNumber != right.LongNumber) return false;
if (left.Number != right.Number) return false;
if (left.Real != right.Real) return false;
if (string.Compare(left.Summary, right.Summary, StringComparison.Ordinal) != 0) return false;
if (string.Compare(left.Title, right.Title, StringComparison.Ordinal) != 0) return false;
return true;
}
[TestMethod]
public void MemoryStoragePostTest()
{
var storage = new MemoryStorage<TestDTO>();
var a1 = storage.Post(new TestDTO
{
IsFlag = false,
LongNumber = 100,
Number = 1000,
Real = 1000.0001,
Summary = "Summary #1",
Title = "Title #1"
});
var a2 = storage.Post(new TestDTO
{
IsFlag = true,
LongNumber = 0,
Number = -500,
Real = 500.005,
Summary = "Summary #2",
Title = "Title #2"
});
var a3 = storage.Post(new TestDTO
{
IsFlag = false,
LongNumber = -1,
Number = 500,
Real = -0.0001,
Summary = "Summary #3",
Title = "Title #3"
});
Assert.IsTrue(a1.Success);
Assert.AreEqual<long>(a1.Count, 1);
Assert.IsTrue(a2.Success);
Assert.AreEqual<long>(a2.Count, 1);
Assert.IsTrue(a3.Success);
Assert.AreEqual<long>(a3.Count, 1);
}
[TestMethod]
public void MemoryStorageGetAllTest()
{
var set = new List<TestDTO>();
set.Add(new TestDTO
{
IsFlag = false,
LongNumber = 100,
Number = 1000,
Real = 1000.0001,
Summary = "Summary #1",
Title = "Title #1"
});
set.Add(new TestDTO
{
IsFlag = true,
LongNumber = 0,
Number = -500,
Real = 500.005,
Summary = "Summary #2",
Title = "Title #2"
});
set.Add(new TestDTO
{
IsFlag = false,
LongNumber = -1,
Number = 500,
Real = -0.0001,
Summary = "Summary #3",
Title = "Title #3"
});
var storage = new MemoryStorage<TestDTO>();
foreach (var i in set)
{
var ar = storage.Post(i);
Assert.IsTrue(ar.Success);
Assert.AreEqual<long>(ar.Count, 1);
}
// Test equals set and storage data
foreach (var i in storage.Get())
{
Assert.IsTrue(set.Exists(dto => TestDTOEqual(i, dto)));
}
// Modify originals
foreach (var i in set)
{
i.Title = "###";
}
// Test independences storage from original
foreach (var i in storage.Get())
{
Assert.IsFalse(set.Exists(dto => TestDTOEqual(i, dto)));
}
}
[TestMethod]
public void MemoryStorageGetByTest()
{
var set = new List<TestDTO>();
set.Add(new TestDTO
{
IsFlag = false,
LongNumber = 100,
Number = 1000,
Real = 1000.0001,
Summary = "Summary #1",
Title = "Title #1"
});
set.Add(new TestDTO
{
IsFlag = true,
LongNumber = 0,
Number = -500,
Real = 500.005,
Summary = "Summary #2",
Title = "Title #2"
});
set.Add(new TestDTO
{
IsFlag = false,
LongNumber = -1,
Number = 500,
Real = -0.0001,
Summary = "Summary #3",
Title = "Title #3"
});
var storage = new MemoryStorage<TestDTO>();
foreach (var i in set)
{
var ar = storage.Post(i);
Assert.IsTrue(ar.Success);
Assert.AreEqual<long>(ar.Count, 1);
}
// Test equals set and storage data
foreach (var i in storage.Get())
{
Assert.IsTrue(set.Exists(dto => TestDTOEqual(i, dto)));
}
foreach (var i in storage.Get(Query.ALL()))
{
Assert.IsTrue(set.Exists(dto => TestDTOEqual(i, dto)));
}
var result_eq = storage.Get(Query.EQ("Title", "Title #1"));
Assert.AreEqual<int>(result_eq.Count(), 1);
Assert.IsTrue(TestDTOEqual(set[0], result_eq.First()));
var result_neq = storage.Get(Query.NEQ("Title", "Title #1"));
Assert.AreEqual<int>(result_neq.Count(), 2);
Assert.IsTrue(TestDTOEqual(set[1], result_neq.First()));
Assert.IsTrue(TestDTOEqual(set[2], result_neq.Skip(1).First()));
var result_gt = storage.Get(Query.GT("Number", 1));
Assert.AreEqual<int>(result_gt.Count(), 2);
Assert.IsTrue(TestDTOEqual(set[0], result_gt.First()));
Assert.IsTrue(TestDTOEqual(set[2], result_gt.Skip(1).First()));
var result_lt = storage.Get(Query.LT("Number", 1));
Assert.AreEqual<int>(result_lt.Count(), 1);
Assert.IsTrue(TestDTOEqual(set[1], result_lt.First()));
}
}
}

@ -0,0 +1,419 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ZeroLevel.Specification;
using ZeroSpecificationPatternsTest.Models;
using ZeroSpecificationPatternsTest.Specifications;
namespace ZeroSpecificationPatternsTest
{
/// <summary>
/// Summary description for SpecificationPatternTest
/// </summary>
[TestClass]
public class SpecificationPatternTest
{
[TestMethod]
public void SimpleSpecificationTest()
{
// Assert
var dto_one = new TestDTO
{
IsFlag = true,
LongNumber = 100,
Number = 1000,
Real = 3.141,
Summary = "Summary",
Title = "Title"
};
var dto_two = new TestDTO
{
IsFlag = false,
LongNumber = 0,
Number = 0,
Real = 0,
Summary = string.Empty,
Title = string.Empty
};
var flag_spec_true = new IsFlagSpecification(true);
var flag_spec_false = new IsFlagSpecification(false);
var long_specification_full = new LongNumberSpecification(100);
var long_specification_empty = new LongNumberSpecification(0);
var number_specification_full = new NumberSpecification(1000);
var number_specification_empty = new NumberSpecification(0);
var real_specification_full = new RealSpecification(3.141);
var real_specification_empty = new RealSpecification(0);
var summary_specification_full = new SummarySpecification("Summary");
var summary_specification_empty = new SummarySpecification(string.Empty);
var title_specification_full = new TitleSpecification("Title");
var title_specification_empty = new TitleSpecification(string.Empty);
// Assert
Assert.IsTrue(flag_spec_true.IsSatisfiedBy(dto_one));
Assert.IsFalse(flag_spec_false.IsSatisfiedBy(dto_one));
Assert.IsTrue(flag_spec_false.IsSatisfiedBy(dto_two));
Assert.IsFalse(flag_spec_true.IsSatisfiedBy(dto_two));
Assert.IsTrue(long_specification_full.IsSatisfiedBy(dto_one));
Assert.IsFalse(long_specification_empty.IsSatisfiedBy(dto_one));
Assert.IsTrue(long_specification_empty.IsSatisfiedBy(dto_two));
Assert.IsFalse(long_specification_full.IsSatisfiedBy(dto_two));
Assert.IsTrue(number_specification_full.IsSatisfiedBy(dto_one));
Assert.IsFalse(number_specification_empty.IsSatisfiedBy(dto_one));
Assert.IsTrue(number_specification_empty.IsSatisfiedBy(dto_two));
Assert.IsFalse(number_specification_full.IsSatisfiedBy(dto_two));
Assert.IsTrue(real_specification_full.IsSatisfiedBy(dto_one));
Assert.IsFalse(real_specification_empty.IsSatisfiedBy(dto_one));
Assert.IsTrue(real_specification_empty.IsSatisfiedBy(dto_two));
Assert.IsFalse(real_specification_full.IsSatisfiedBy(dto_two));
Assert.IsTrue(summary_specification_full.IsSatisfiedBy(dto_one));
Assert.IsFalse(summary_specification_empty.IsSatisfiedBy(dto_one));
Assert.IsTrue(summary_specification_empty.IsSatisfiedBy(dto_two));
Assert.IsFalse(summary_specification_full.IsSatisfiedBy(dto_two));
Assert.IsTrue(title_specification_full.IsSatisfiedBy(dto_one));
Assert.IsFalse(title_specification_empty.IsSatisfiedBy(dto_one));
Assert.IsTrue(title_specification_empty.IsSatisfiedBy(dto_two));
Assert.IsFalse(title_specification_full.IsSatisfiedBy(dto_two));
}
[TestMethod]
public void NotSpecificationTest()
{
// Assert
var dto_one = new TestDTO
{
IsFlag = true,
LongNumber = 100,
Number = 1000,
Real = 3.141,
Summary = "Summary",
Title = "Title"
};
var dto_two = new TestDTO
{
IsFlag = false,
LongNumber = 0,
Number = 0,
Real = 0,
Summary = string.Empty,
Title = string.Empty
};
var flag_spec_true = new IsFlagSpecification(true).Not();
var flag_spec_false = new IsFlagSpecification(false).Not();
var long_specification_full = new LongNumberSpecification(100).Not();
var long_specification_empty = new LongNumberSpecification(0).Not();
var number_specification_full = new NumberSpecification(1000).Not();
var number_specification_empty = new NumberSpecification(0).Not();
var real_specification_full = new RealSpecification(3.141).Not();
var real_specification_empty = new RealSpecification(0).Not();
var summary_specification_full = new SummarySpecification("Summary").Not();
var summary_specification_empty = new SummarySpecification(string.Empty).Not();
var title_specification_full = new TitleSpecification("Title").Not();
var title_specification_empty = new TitleSpecification(string.Empty).Not();
// Assert
Assert.IsFalse(flag_spec_true.IsSatisfiedBy(dto_one));
Assert.IsTrue(flag_spec_false.IsSatisfiedBy(dto_one));
Assert.IsFalse(flag_spec_false.IsSatisfiedBy(dto_two));
Assert.IsTrue(flag_spec_true.IsSatisfiedBy(dto_two));
Assert.IsFalse(long_specification_full.IsSatisfiedBy(dto_one));
Assert.IsTrue(long_specification_empty.IsSatisfiedBy(dto_one));
Assert.IsFalse(long_specification_empty.IsSatisfiedBy(dto_two));
Assert.IsTrue(long_specification_full.IsSatisfiedBy(dto_two));
Assert.IsFalse(number_specification_full.IsSatisfiedBy(dto_one));
Assert.IsTrue(number_specification_empty.IsSatisfiedBy(dto_one));
Assert.IsFalse(number_specification_empty.IsSatisfiedBy(dto_two));
Assert.IsTrue(number_specification_full.IsSatisfiedBy(dto_two));
Assert.IsFalse(real_specification_full.IsSatisfiedBy(dto_one));
Assert.IsTrue(real_specification_empty.IsSatisfiedBy(dto_one));
Assert.IsFalse(real_specification_empty.IsSatisfiedBy(dto_two));
Assert.IsTrue(real_specification_full.IsSatisfiedBy(dto_two));
Assert.IsFalse(summary_specification_full.IsSatisfiedBy(dto_one));
Assert.IsTrue(summary_specification_empty.IsSatisfiedBy(dto_one));
Assert.IsFalse(summary_specification_empty.IsSatisfiedBy(dto_two));
Assert.IsTrue(summary_specification_full.IsSatisfiedBy(dto_two));
Assert.IsFalse(title_specification_full.IsSatisfiedBy(dto_one));
Assert.IsTrue(title_specification_empty.IsSatisfiedBy(dto_one));
Assert.IsFalse(title_specification_empty.IsSatisfiedBy(dto_two));
Assert.IsTrue(title_specification_full.IsSatisfiedBy(dto_two));
}
[TestMethod]
public void ComposedAndSpecificationTest()
{
// Assert
var dto_one = new TestDTO
{
IsFlag = true,
LongNumber = 100,
Number = 1000,
Real = 3.141,
Summary = "Summary",
Title = "Title"
};
var dto_two = new TestDTO
{
IsFlag = false,
LongNumber = 0,
Number = 0,
Real = 0,
Summary = string.Empty,
Title = string.Empty
};
var flag_spec_true = new IsFlagSpecification(true);
var flag_spec_false = new IsFlagSpecification(false);
var long_specification_full = new LongNumberSpecification(100);
var long_specification_empty = new LongNumberSpecification(0);
var number_specification_full = new NumberSpecification(1000);
var number_specification_empty = new NumberSpecification(0);
var real_specification_full = new RealSpecification(3.141);
var real_specification_empty = new RealSpecification(0);
var summary_specification_full = new SummarySpecification("Summary");
var summary_specification_empty = new SummarySpecification(string.Empty);
var title_specification_full = new TitleSpecification("Title");
var title_specification_empty = new TitleSpecification(string.Empty);
// Act
var composed_full = flag_spec_true.
And(long_specification_full).
And(number_specification_full).
And(real_specification_full).
And(summary_specification_full).
And(title_specification_full);
var composed_empty = flag_spec_false.
And(long_specification_empty).
And(number_specification_empty).
And(real_specification_empty).
And(summary_specification_empty).
And(title_specification_empty);
// Assert
Assert.IsTrue(composed_full.IsSatisfiedBy(dto_one));
Assert.IsFalse(composed_empty.IsSatisfiedBy(dto_one));
Assert.IsTrue(composed_empty.IsSatisfiedBy(dto_two));
Assert.IsFalse(composed_full.IsSatisfiedBy(dto_two));
}
[TestMethod]
public void ComposedOrSpecificationTest()
{
// Assert
var dto_one = new TestDTO
{
IsFlag = true,
LongNumber = 100,
Number = 1000,
Real = 3.141,
Summary = "Summary",
Title = "Title"
};
var dto_two = new TestDTO
{
IsFlag = false,
LongNumber = 0,
Number = 0,
Real = 0,
Summary = string.Empty,
Title = string.Empty
};
var flag_spec_true = new IsFlagSpecification(true);
var flag_spec_false = new IsFlagSpecification(false);
var long_specification_full = new LongNumberSpecification(100);
var long_specification_empty = new LongNumberSpecification(0);
var number_specification_full = new NumberSpecification(1000);
var number_specification_empty = new NumberSpecification(0);
var real_specification_full = new RealSpecification(3.141);
var real_specification_empty = new RealSpecification(0);
var summary_specification_full = new SummarySpecification("Summary");
var summary_specification_empty = new SummarySpecification(string.Empty);
var title_specification_full = new TitleSpecification("Title");
var title_specification_empty = new TitleSpecification(string.Empty);
// Act
var composed_full = flag_spec_false.
Or(long_specification_full).
Or(number_specification_full).
Or(real_specification_full).
Or(summary_specification_full).
Or(title_specification_full);
var composed_empty = flag_spec_true.
Or(long_specification_empty).
Or(number_specification_empty).
Or(real_specification_empty).
Or(summary_specification_empty).
Or(title_specification_empty);
// Assert
Assert.IsTrue(composed_full.IsSatisfiedBy(dto_one));
Assert.IsTrue(composed_empty.IsSatisfiedBy(dto_one));
Assert.IsTrue(composed_empty.IsSatisfiedBy(dto_two));
Assert.IsTrue(composed_full.IsSatisfiedBy(dto_two));
}
[TestMethod]
public void ExpressionSpecificationTest()
{
// Assert
var dto_one = new TestDTO
{
IsFlag = true,
LongNumber = 100,
Number = 1000,
Real = 3.141,
Summary = "Summary",
Title = "Title"
};
var dto_two = new TestDTO
{
IsFlag = false,
LongNumber = 0,
Number = 0,
Real = 0,
Summary = string.Empty,
Title = string.Empty
};
var flag_spec_true = new ExpressionSpecification<TestDTO>(o=>o.IsFlag == true);
var flag_spec_false = new ExpressionSpecification<TestDTO>(o => o.IsFlag == false);
var long_specification_full = new ExpressionSpecification<TestDTO>(o => o.LongNumber == 100);
var long_specification_empty = new ExpressionSpecification<TestDTO>(o => o.LongNumber == 0);
var number_specification_full = new ExpressionSpecification<TestDTO>(o => o.Number == 1000);
var number_specification_empty = new ExpressionSpecification<TestDTO>(o => o.Number == 0);
var real_specification_full = new ExpressionSpecification<TestDTO>(o => o.Real == 3.141);
var real_specification_empty = new ExpressionSpecification<TestDTO>(o => o.Real == 0);
var summary_specification_full = new ExpressionSpecification<TestDTO>(o => o.Summary == "Summary");
var summary_specification_empty = new ExpressionSpecification<TestDTO>(o => o.Summary == string.Empty);
var title_specification_full = new ExpressionSpecification<TestDTO>(o => o.Title == "Title");
var title_specification_empty = new ExpressionSpecification<TestDTO>(o => o.Title == string.Empty);
// Assert
Assert.IsTrue(flag_spec_true.IsSatisfiedBy(dto_one));
Assert.IsFalse(flag_spec_false.IsSatisfiedBy(dto_one));
Assert.IsTrue(flag_spec_false.IsSatisfiedBy(dto_two));
Assert.IsFalse(flag_spec_true.IsSatisfiedBy(dto_two));
Assert.IsTrue(long_specification_full.IsSatisfiedBy(dto_one));
Assert.IsFalse(long_specification_empty.IsSatisfiedBy(dto_one));
Assert.IsTrue(long_specification_empty.IsSatisfiedBy(dto_two));
Assert.IsFalse(long_specification_full.IsSatisfiedBy(dto_two));
Assert.IsTrue(number_specification_full.IsSatisfiedBy(dto_one));
Assert.IsFalse(number_specification_empty.IsSatisfiedBy(dto_one));
Assert.IsTrue(number_specification_empty.IsSatisfiedBy(dto_two));
Assert.IsFalse(number_specification_full.IsSatisfiedBy(dto_two));
Assert.IsTrue(real_specification_full.IsSatisfiedBy(dto_one));
Assert.IsFalse(real_specification_empty.IsSatisfiedBy(dto_one));
Assert.IsTrue(real_specification_empty.IsSatisfiedBy(dto_two));
Assert.IsFalse(real_specification_full.IsSatisfiedBy(dto_two));
Assert.IsTrue(summary_specification_full.IsSatisfiedBy(dto_one));
Assert.IsFalse(summary_specification_empty.IsSatisfiedBy(dto_one));
Assert.IsTrue(summary_specification_empty.IsSatisfiedBy(dto_two));
Assert.IsFalse(summary_specification_full.IsSatisfiedBy(dto_two));
Assert.IsTrue(title_specification_full.IsSatisfiedBy(dto_one));
Assert.IsFalse(title_specification_empty.IsSatisfiedBy(dto_one));
Assert.IsTrue(title_specification_empty.IsSatisfiedBy(dto_two));
Assert.IsFalse(title_specification_full.IsSatisfiedBy(dto_two));
}
[TestMethod]
public void ComposedExpressionSpecificationTest()
{
// Assert
var dto_one = new TestDTO
{
IsFlag = true,
LongNumber = 100,
Number = 1000,
Real = 3.141,
Summary = "Summary",
Title = "Title"
};
var dto_two = new TestDTO
{
IsFlag = false,
LongNumber = 0,
Number = 0,
Real = 0,
Summary = string.Empty,
Title = string.Empty
};
var flag_spec_true = new ExpressionSpecification<TestDTO>(o => o.IsFlag == true);
var flag_spec_false = new ExpressionSpecification<TestDTO>(o => o.IsFlag == false);
var long_specification_full = new ExpressionSpecification<TestDTO>(o => o.LongNumber == 100);
var long_specification_empty = new ExpressionSpecification<TestDTO>(o => o.LongNumber == 0);
var number_specification_full = new ExpressionSpecification<TestDTO>(o => o.Number == 1000);
var number_specification_empty = new ExpressionSpecification<TestDTO>(o => o.Number == 0);
var real_specification_full = new ExpressionSpecification<TestDTO>(o => o.Real == 3.141);
var real_specification_empty = new ExpressionSpecification<TestDTO>(o => o.Real == 0);
var summary_specification_full = new ExpressionSpecification<TestDTO>(o => o.Summary == "Summary");
var summary_specification_empty = new ExpressionSpecification<TestDTO>(o => o.Summary == string.Empty);
var title_specification_full = new ExpressionSpecification<TestDTO>(o => o.Title == "Title");
var title_specification_empty = new ExpressionSpecification<TestDTO>(o => o.Title == string.Empty);
// Act
var composed_full = flag_spec_true.
And(long_specification_full).
And(number_specification_full).
And(real_specification_full).
And(summary_specification_full).
And(title_specification_full);
var composed_empty = flag_spec_false.
And(long_specification_empty).
And(number_specification_empty).
And(real_specification_empty).
And(summary_specification_empty).
And(title_specification_empty);
// Assert
Assert.IsTrue(composed_full.IsSatisfiedBy(dto_one));
Assert.IsFalse(composed_empty.IsSatisfiedBy(dto_one));
Assert.IsTrue(composed_empty.IsSatisfiedBy(dto_two));
Assert.IsFalse(composed_full.IsSatisfiedBy(dto_two));
}
}
}

@ -50,15 +50,28 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ArrayToolsTest.cs" />
<Compile Include="CollectionsTests.cs" />
<Compile Include="InvokingTest.cs" />
<Compile Include="MappingTest.cs" />
<Compile Include="Models\BaseClass.cs" />
<Compile Include="Models\BaseFakeClass.cs" />
<Compile Include="Models\ChildClass.cs" />
<Compile Include="Models\FakeClass.cs" />
<Compile Include="Models\PocoFields.cs" />
<Compile Include="Models\PocoProperties.cs" />
<Compile Include="Models\Specifications\IsFlagSpecification.cs" />
<Compile Include="Models\Specifications\LongNumberSpecification.cs" />
<Compile Include="Models\Specifications\NumberSpecification.cs" />
<Compile Include="Models\Specifications\RealSpecification.cs" />
<Compile Include="Models\Specifications\SummarySpecification.cs" />
<Compile Include="Models\Specifications\TitleSpecification.cs" />
<Compile Include="Models\StaticFakeClass.cs" />
<Compile Include="Models\TestDTO.cs" />
<Compile Include="PredicateBuilderTests.cs" />
<Compile Include="QueriesTests.cs" />
<Compile Include="SerializationTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SpecificationPatternTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

Loading…
Cancel
Save

Powered by TurnKey Linux.