Index: Core/Common/src/Core.Common.Utils/Core.Common.Utils.csproj =================================================================== diff -u -r00c8bc7fed580b4a9820a7d85b3b6d2346599f65 -r2a1dc72ed9a202b720c26828e5d53cecc5a0e6c8 --- Core/Common/src/Core.Common.Utils/Core.Common.Utils.csproj (.../Core.Common.Utils.csproj) (revision 00c8bc7fed580b4a9820a7d85b3b6d2346599f65) +++ Core/Common/src/Core.Common.Utils/Core.Common.Utils.csproj (.../Core.Common.Utils.csproj) (revision 2a1dc72ed9a202b720c26828e5d53cecc5a0e6c8) @@ -105,7 +105,6 @@ - True True Index: Core/Common/src/Core.Common.Utils/Extensions/CollectionExtensions.cs =================================================================== diff -u -rfa33f7c078c5d17f92f6a519f147a0a371593944 -r2a1dc72ed9a202b720c26828e5d53cecc5a0e6c8 --- Core/Common/src/Core.Common.Utils/Extensions/CollectionExtensions.cs (.../CollectionExtensions.cs) (revision fa33f7c078c5d17f92f6a519f147a0a371593944) +++ Core/Common/src/Core.Common.Utils/Extensions/CollectionExtensions.cs (.../CollectionExtensions.cs) (revision 2a1dc72ed9a202b720c26828e5d53cecc5a0e6c8) @@ -4,12 +4,21 @@ namespace Core.Common.Utils.Extensions { + /// + /// Class defining extension methods for collections. + /// public static class CollectionExtensions { + /// + /// Remove all elements from a collection where a given check returns true. + /// + /// The type of the elements in the collection. + /// The collection from which elements should be removed. + /// The filtering method, that should return true if the + /// given element should be removed from . public static void RemoveAllWhere(this ICollection source, Func condition) { - var list = source.Where(condition).ToList(); - foreach (T item in list) + foreach (T item in source.Where(condition).ToArray()) { source.Remove(item); } Index: Core/Common/src/Core.Common.Utils/Extensions/ComparableExtensions.cs =================================================================== diff -u -rfa33f7c078c5d17f92f6a519f147a0a371593944 -r2a1dc72ed9a202b720c26828e5d53cecc5a0e6c8 --- Core/Common/src/Core.Common.Utils/Extensions/ComparableExtensions.cs (.../ComparableExtensions.cs) (revision fa33f7c078c5d17f92f6a519f147a0a371593944) +++ Core/Common/src/Core.Common.Utils/Extensions/ComparableExtensions.cs (.../ComparableExtensions.cs) (revision 2a1dc72ed9a202b720c26828e5d53cecc5a0e6c8) @@ -2,18 +2,43 @@ namespace Core.Common.Utils.Extensions { + /// + /// Class defines extension methods for objects. + /// public static class ComparableExtensions { + /// + /// Determines whether one object is greater then another. + /// + /// The first object. + /// The second object. + /// True if is considered greater then , + /// false otherwise. + /// Object type of + /// is not the same as that of . public static bool IsBigger(this IComparable object1, IComparable object2) { if (object1 == null) { - return false; // null is not bigger than anything + return false; // Null not bigger then anything (or equal to null). } + if (object2 == null) + { + return true; // Anything is greater then null. + } return object1.CompareTo(object2) > 0; } + /// + /// Determines whether one object is smaller then another. + /// + /// The first object. + /// The second object. + /// True if is considered smaller then , + /// false otherwise. + /// Object type of + /// is not the same as that of . public static bool IsSmaller(this IComparable object1, IComparable object2) { if (object1 == null) @@ -24,6 +49,15 @@ return object1.CompareTo(object2) < 0; } + /// + /// Determines where one object is within the inclusive bounds of some range. + /// + /// Value to be checked. + /// First range value. + /// Second range value. + /// True if falls within the inclusive bounds, false otherwise. + /// Object type of + /// is not the same as that of or . public static bool IsInRange(this IComparable value, IComparable limitOne, IComparable limitTwo) { IComparable min; Index: Core/Common/src/Core.Common.Utils/Extensions/EnumerableExtensions.cs =================================================================== diff -u -rfa33f7c078c5d17f92f6a519f147a0a371593944 -r2a1dc72ed9a202b720c26828e5d53cecc5a0e6c8 --- Core/Common/src/Core.Common.Utils/Extensions/EnumerableExtensions.cs (.../EnumerableExtensions.cs) (revision fa33f7c078c5d17f92f6a519f147a0a371593944) +++ Core/Common/src/Core.Common.Utils/Extensions/EnumerableExtensions.cs (.../EnumerableExtensions.cs) (revision 2a1dc72ed9a202b720c26828e5d53cecc5a0e6c8) @@ -5,8 +5,18 @@ namespace Core.Common.Utils.Extensions { + /// + /// This class defines extension methods for and . + /// public static class EnumerableExtensions { + /// + /// Perform a certain action for each element in a sequence. + /// + /// The element type of the sequence. + /// A sequence that contains elements to be acted upon. + /// The action that should be performed on each element. + /// Do not define an action that effect . public static void ForEachElementDo(this IEnumerable source, Action action) { foreach (var item in source) Fisheye: Tag 2a1dc72ed9a202b720c26828e5d53cecc5a0e6c8 refers to a dead (removed) revision in file `Core/Common/src/Core.Common.Utils/Extensions/StringExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj =================================================================== diff -u -rd53a27a49d8db860ff0894554dab040a1b6204a5 -r2a1dc72ed9a202b720c26828e5d53cecc5a0e6c8 --- Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj (.../Core.Common.Utils.Test.csproj) (revision d53a27a49d8db860ff0894554dab040a1b6204a5) +++ Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj (.../Core.Common.Utils.Test.csproj) (revision 2a1dc72ed9a202b720c26828e5d53cecc5a0e6c8) @@ -97,9 +97,9 @@ + - Index: Core/Common/test/Core.Common.Utils.Test/Extensions/CollectionExtensionsTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Utils.Test/Extensions/CollectionExtensionsTest.cs (revision 0) +++ Core/Common/test/Core.Common.Utils.Test/Extensions/CollectionExtensionsTest.cs (revision 2a1dc72ed9a202b720c26828e5d53cecc5a0e6c8) @@ -0,0 +1,78 @@ +using System.Collections.Generic; + +using Core.Common.Utils.Extensions; + +using NUnit.Framework; + +namespace Core.Common.Utils.Test.Extensions +{ + [TestFixture] + public class CollectionExtensionsTest + { + [Test] + public void RemoveAllWhere_FilterReturningTrueForAllElements_CollectionIsCleared() + { + // Setup + var collection = new List(); + collection.AddRange(new[] + { + new object(), + new object(), + new object() + }); + + // Call + collection.RemoveAllWhere(o => true); + + // Assert + CollectionAssert.IsEmpty(collection); + } + + [Test] + public void RemoveAllWhere_FilterReturningFalseForAllElements_CollectionRemainsUnchanged() + { + // Setup + var originalContents = new[] + { + new object(), + new object(), + new object() + }; + + var collection = new List(); + collection.AddRange(originalContents); + + // Call + collection.RemoveAllWhere(o => false); + + // Assert + CollectionAssert.AreEqual(originalContents, collection); + } + + [Test] + public void RemoveAllWhere_FilterReturningAlternatesForAllElements_CollectionHasSomeElementsRemoved() + { + // Setup + var expectedElementToKeep = 2; + + var collection = new List(); + collection.AddRange(new[] + { + 1, + expectedElementToKeep, + 3 + }); + + // Call + bool alternatingFilterValue = false; + collection.RemoveAllWhere(o => + { + alternatingFilterValue = !alternatingFilterValue; + return alternatingFilterValue; + }); + + // Assert + CollectionAssert.AreEqual(new[] { expectedElementToKeep }, collection); + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.Utils.Test/Extensions/ComparableExtensionsTest.cs =================================================================== diff -u -r35de88b42154ea1615b81903f20e2d7f4fa9f6ca -r2a1dc72ed9a202b720c26828e5d53cecc5a0e6c8 --- Core/Common/test/Core.Common.Utils.Test/Extensions/ComparableExtensionsTest.cs (.../ComparableExtensionsTest.cs) (revision 35de88b42154ea1615b81903f20e2d7f4fa9f6ca) +++ Core/Common/test/Core.Common.Utils.Test/Extensions/ComparableExtensionsTest.cs (.../ComparableExtensionsTest.cs) (revision 2a1dc72ed9a202b720c26828e5d53cecc5a0e6c8) @@ -10,31 +10,120 @@ public class ComparableExtensionsTest { [Test] - public void NullIsSmallerThanAnything() + [TestCase(null, 1, false)] // Null is smaller then any "not-null" + [TestCase(null, null, false)] // Null can be considered equal to Null + [TestCase(1, null, true)] // Any "not-null" is greater then Null + [TestCase(2, 1, true)] + [TestCase(1, 1, false)] + [TestCase(1, 2, false)] + public void IsBigger_VariousUseCases_ReturnExpectedResult( + IComparable first, IComparable second, bool expectedResult) { - IComparable b = null; - Assert.IsTrue(b.IsSmaller("anything")); + // Call + var isFirstBiggerThenSecond = first.IsBigger(second); + + // Assert + Assert.AreEqual(expectedResult, isFirstBiggerThenSecond); } [Test] - public void NullIsNotSmallerThanNull() + public void IsBigger_FirstObjectNotSameTypeAsSecond_ThrowArgumentException() { - IComparable b = null; - Assert.IsFalse(b.IsSmaller(null)); + // Setup + int first = 1; + string second = "one"; + + // Call + TestDelegate call = () => first.IsBigger(second); + + // Assert + Assert.Throws(call); } [Test] - public void NullIsNotBiggerThanAnything() + [TestCase(null, 1, true)] // Null is smaller then any "not-null" + [TestCase(null, null, false)] // Null can be considered equal to Null + [TestCase(1, null, false)] // Any "not-null" is greater then Null + [TestCase(2, 1, false)] + [TestCase(1, 1, false)] + [TestCase(1, 2, true)] + public void IsSmaller_VariousUseCases_ReturnExpectedResult( + IComparable first, IComparable second, bool expectedResult) { - IComparable b = null; - Assert.IsFalse(b.IsBigger("anything")); + // Call + var isFirstBiggerThenSecond = first.IsSmaller(second); + + // Assert + Assert.AreEqual(expectedResult, isFirstBiggerThenSecond); } [Test] - public void NullIsNotBiggerThanNull() + public void IsSmaller_FirstObjectNotSameTypeAsSecond_ThrowArgumentException() { - IComparable b = null; - Assert.IsFalse(b.IsBigger((null))); + // Setup + int first = 1; + string second = "one"; + + // Call + TestDelegate call = () => first.IsSmaller(second); + + // Assert + Assert.Throws(call); } + + [Test] + [TestCase(-5, 1, 3, false)] + [TestCase(-5, 3, 1, false)] + [TestCase(1 - 1e-6, 1.0, 3.0, false)] + [TestCase(1 - 1e-6, 3.0, 1.0, false)] + [TestCase(1, 1, 3, true)] + [TestCase(1, 3, 1, true)] + [TestCase(2.01, 1.0, 3.0, true)] + [TestCase(2.01, 3.0, 1.0, true)] + [TestCase(3, 1, 3, true)] + [TestCase(3, 3, 1, true)] + [TestCase(3 + 1e-6, 1.0, 3.0, false)] + [TestCase(3 + 1e-6, 3.0, 1.0, false)] + [TestCase(5, 1, 3, false)] + [TestCase(5, 3, 1, false)] + public void IsInRange_VariousUseCases_ReturnExpectedResult( + IComparable sample, IComparable firstLimit, IComparable secondLimit, bool expectedResult) + { + // Call + var isSampleInRange = sample.IsInRange(firstLimit, secondLimit); + + // Assert + Assert.AreEqual(expectedResult, isSampleInRange); + } + + [Test] + public void IsInRange_SampleObjectTypeNotSameAsFirstLimit_ThrowArgumentException() + { + // Setup + int sample = 1; + string firstLimit = "one"; + int secondLimit = 2; + + // Call + TestDelegate call = () => sample.IsInRange(firstLimit, secondLimit); + + // Assert + Assert.Throws(call); + } + + [Test] + public void IsInRange_SampleObjectTypeNotSameAsSecondLimit_ThrowArgumentException() + { + // Setup + int sample = 1; + int firstLimit = 2; + string secondLimit = "one"; + + // Call + TestDelegate call = () => sample.IsInRange(firstLimit, secondLimit); + + // Assert + Assert.Throws(call); + } } } \ No newline at end of file Index: Core/Common/test/Core.Common.Utils.Test/Extensions/EnumerableExtensionsTest.cs =================================================================== diff -u -r35de88b42154ea1615b81903f20e2d7f4fa9f6ca -r2a1dc72ed9a202b720c26828e5d53cecc5a0e6c8 --- Core/Common/test/Core.Common.Utils.Test/Extensions/EnumerableExtensionsTest.cs (.../EnumerableExtensionsTest.cs) (revision 35de88b42154ea1615b81903f20e2d7f4fa9f6ca) +++ Core/Common/test/Core.Common.Utils.Test/Extensions/EnumerableExtensionsTest.cs (.../EnumerableExtensionsTest.cs) (revision 2a1dc72ed9a202b720c26828e5d53cecc5a0e6c8) @@ -13,8 +13,9 @@ public class EnumerableExtensionsTest { [Test] - public void ForEach() + public void ForEachElementDo_PerformTheActionForEachElement() { + // Setup var items = new[] { 1, @@ -23,19 +24,39 @@ }; var results = new List(); + Action action = results.Add; - items.ForEachElementDo(results.Add); + // Call + items.ForEachElementDo(action); + // Assert CollectionAssert.AreEqual(items, results, "elements should be equal"); } [Test] - public void Count_ForRandomRange_ReturnsRangeElementCount() + public void Count_ForRandomRange_ReturnsElementCount([Random(0, 100, 1)] int expectedCount) { - var expectedCount = new Random().Next(100); + // Setup IEnumerable enumerable = Enumerable.Range(1, expectedCount); - Assert.AreEqual(expectedCount, enumerable.Count()); + // Call + var count = enumerable.Count(); + + // Assert + Assert.AreEqual(expectedCount, count); } + + [Test] + public void Count_SequenceIsNull_ThrowArgumentNullException() + { + // Setup + IEnumerable sequence = null; + + // Call + TestDelegate call = () => sequence.Count(); + + // Assert + Assert.Throws(call); + } } } \ No newline at end of file Fisheye: Tag 2a1dc72ed9a202b720c26828e5d53cecc5a0e6c8 refers to a dead (removed) revision in file `Core/Common/test/Core.Common.Utils.Test/Extensions/StringExtensionsTests.cs'. Fisheye: No comparison available. Pass `N' to diff?