예제 #1
0
            public void IsEmpty_OnGenericCollectionSingleItem_ReturnsFalse()
            {
                var fixture = new MultipleMockingFixture(1);
                var singleItemCollection = fixture.Create<ICollection<object>>();

                Assert.That(() => singleItemCollection.IsEmpty(), Is.False);
            }
예제 #2
0
            public void NullableMin_OnSequence_WithNullSelector_ThrowsValidationException()
            {
                var fixture = new MultipleMockingFixture();
                var sequence = fixture.Create<IEnumerable<GenericComparableStruct>>();
                Func<GenericComparableStruct, GenericComparableStruct> nullFunc = null;

                Assert.That(() => sequence.NullableMin(nullFunc), Throws.TypeOf<ValidationException>().With.InnerException.TypeOf<ArgumentNullException>());
            }
예제 #3
0
            public void IsEmpty_OnGenericCollectionEmpty_ReturnsTrue()
            {
                var fixture = new MultipleMockingFixture();
                ICollection<object> emptyGenericCollection = fixture.Create<ICollection<object>>();
                emptyGenericCollection.Clear();

                Assert.That(() => emptyGenericCollection.IsEmpty(), Is.True);
            }
예제 #4
0
            public void Exclude_OnEmptySequence_WithSequence_ReturnsEmptySequence()
            {
                var emptySequence = Enumerable.Empty<object>();
                var fixture = new MultipleMockingFixture();
                var sequence = fixture.Create<IEnumerable<object>>();

                Assert.That(() => emptySequence.Exclude(sequence), Is.Empty);
            }
            public void FlattenStrings_OnValidEnumerable_ReturnsCorrectString()
            {
                var fixture = new MultipleMockingFixture();
                var testStrings = fixture.CreateMany<string>(5).ToList();
                var expected = testStrings.Aggregate((result, current) => result + current);

                Assert.That(testStrings.FlattenStrings(), Is.EqualTo(expected));
            }
예제 #6
0
            public void Strip_OnEmptySource_WithMultiCharacters_ReturnsEmptyString()
            {
                var emptyString = string.Empty;
                var fixture = new MultipleMockingFixture();
                var multipleCharacters = fixture.Create<IEnumerable<char>>();

                Assert.That(() => emptyString.Strip(multipleCharacters), Is.Empty);
            }
예제 #7
0
            public void ToHexString_OnValidArray_ConvertsToStringCorrectly()
            {
                var fixture = new MultipleMockingFixture(512);
                var validBytes = fixture.Create<byte[]>();
                var expected = BitConverter.ToString(validBytes).Replace("-", string.Empty).ToLowerInvariant();

                Assert.That(() => validBytes.ToHexString(), Is.EqualTo(expected));
            }
예제 #8
0
            public void Shuffle_OnSequenceOfOne_WithRandom_ReturnsSequenceOfOne()
            {
                var fixture = new MultipleMockingFixture(1);
                var sequenceOfOne = fixture.Create<object[]>();
                var random = fixture.Create<Random>();

                Assert.That(() => sequenceOfOne.Shuffle(random), Is.EqualTo(sequenceOfOne));
            }
예제 #9
0
            public void ToByteArray_OnValidHexString_ReturnsProperByteArray()
            {
                var fixture = new MultipleMockingFixture(256);
                var bytes = fixture.Create<byte[]>();
                var hexString = BitConverter.ToString(bytes).Strip('-');

                Assert.That(() => hexString.ToByteArray(), Is.EqualTo(bytes));
            }
예제 #10
0
            public void DistinctBy_OnDoubledSequence_WithKeySelector_ReturnsSingleSequence()
            {
                var fixture = new MultipleMockingFixture();
                var singleSequence = fixture.Create<object[]>();
                var doubleSequence = singleSequence.Concat(singleSequence);
                Func<object, object> objectFunc = o => o;

                Assert.That(() => doubleSequence.DistinctBy(objectFunc), Is.EqualTo(singleSequence));
            }
예제 #11
0
            public void RandomElement_OnCollectionSequence_EventuallyChoosesEachItem()
            {
                var fixture = new MultipleMockingFixture(10);
                var checkList = fixture.Create<object[]>();
                var dic = checkList.ToDictionary(i => i, e => 0);
                var random = fixture.Create<Random>();
                var maxIterations = 1000 * checkList.Count();
                var iterations = 0;

                while (dic.ContainsValue(0))
                {
                    dic[checkList.RandomElement(random)]++;
                    var i = iterations++;
                    Assert.That(() => i, Is.LessThan(maxIterations), string.Format("Dictionary contains {0} items", dic.Values.Sum()));
                }
            }
예제 #12
0
            public void DistinctBy_OnDoubledSequence_WithKeySelector_WithEqualityComparer_ReturnsSingleSequence()
            {
                var fixture = new MultipleMockingFixture();
                var singleSequence = fixture.Create<object[]>();
                var doubleSequence = singleSequence.Concat(singleSequence);
                Func<object, object> objectFunc = o => o;

                var mock = fixture.Create<Mock<IEqualityComparer<object>>>();
                mock.Setup(e => e.GetHashCode()).Returns((object o) => o.GetHashCode());
                mock.Setup(e => e.GetHashCode(It.IsAny<object>())).Returns((object o) => o.GetHashCode());
                mock.Setup(e => e.Equals(It.IsAny<object>())).Returns((object o, object b) => o.GetHashCode() == b.GetHashCode());
                mock.Setup(e => e.Equals(It.IsAny<object>(), It.IsAny<object>())).Returns((object o, object b) => o.GetHashCode() == b.GetHashCode());

                var equalityComparer = mock.Object;

                Assert.That(() => doubleSequence.DistinctBy(objectFunc, equalityComparer), Is.EqualTo(singleSequence));
            }
예제 #13
0
            public void ContainsAny_OnEnumerableCharacters_OnEmptyString_ReturnsFalse()
            {
                string emptyString = string.Empty;
                var fixture = new MultipleMockingFixture();
                var characters = fixture.Create<IEnumerable<char>>();

                Assert.That(() => emptyString.ContainsAny(characters), Is.False);
            }
예제 #14
0
            public void Append_OnSequence_WithElement_ReturnsAppendedSequence()
            {
                var fixture = new MultipleMockingFixture();
                var objectArray = fixture.Create<object[]>();
                var objectValue = fixture.Create<object>();
                var appendedSequence = objectArray.Concat(objectValue.ToEnumerable());

                Assert.That(() => objectArray.Append(objectValue), Is.EqualTo(appendedSequence));
            }
        public void ContainsOnlyOne_OnSequenceOfOne_ReturnsTrue()
        {
            var fixture = new MultipleMockingFixture();
            var sequenceOfOne = fixture.CreateMany<object>(1);

            Assert.That(() => sequenceOfOne.ContainsOnlyOne(), Is.True);
        }
        public void ContainsOnlyOne_OnSequenceOfThree_ReturnsFalse()
        {
            var fixture = new MultipleMockingFixture();
            var sequenceOfThree = fixture.Create<object[]>();

            Assert.That(() => sequenceOfThree.ContainsOnlyOne(), Is.False);
        }
        public void ContainsOnlyOne_OnSequenceOfThree_PredicateNull_ThrowsValidationException()
        {
            var fixture = new MultipleMockingFixture();
            var sequenceOfThree = fixture.Create<object[]>();
            Func<object, bool> nullPredicate = null;

            Assert.That(() => sequenceOfThree.ContainsOnlyOne(nullPredicate), Throws.TypeOf<ValidationException>().With.InnerException.TypeOf<ArgumentNullException>());
        }
예제 #18
0
            public void Shuffle_OnSequence_WithRandom_ReturnsAllOriginalElements()
            {
                const int count = 100;
                var fixture = new MultipleMockingFixture(count);
                var sequence = fixture.Create<object[]>();
                var random = fixture.Create<Random>();
                var shuffled = sequence.Shuffle(random).ToArray();

                Assert.That(() => shuffled, Is.EquivalentTo(sequence));
            }
예제 #19
0
            public void IsEmpty_OnGenericEnumerableMultipleItem_ReturnsFalse()
            {
                var fixture = new MultipleMockingFixture();
                var nonEmptyEnumerable = fixture.Create<IEnumerable<object>>();

                Assert.That(() => nonEmptyEnumerable.IsEmpty(), Is.False);
            }
예제 #20
0
            public void Prepend_OnSequence_WithElement_ReturnsElementPrependedToSequence()
            {
                var fixture = new MultipleMockingFixture();
                var sequence = fixture.Create<IList<object>>();
                var element = fixture.Create<object>();
                var expected = element.ToEnumerable().Concat(sequence);

                Assert.That(sequence.Prepend(element), Is.EqualTo(expected));
            }
예제 #21
0
            public void MaxOrDefault_OnGenericEnumerable_WithNullValue_ReturnsGenericEnumerableMax()
            {
                var fixture = new MultipleMockingFixture();
                var comparableArray = fixture.Create<GenericComparable[]>();
                GenericComparable nullComparable = null;
                var comparableArrayMax = comparableArray.Max();

                Assert.That(() => comparableArray.MaxOrDefault(nullComparable), Is.EqualTo(comparableArrayMax));
            }
예제 #22
0
            public void MaxOrDefault_OnGenericEnumerable_WithValue_WithFunc_ReturnsGenericEnumerableMax()
            {
                var fixture = new MultipleMockingFixture();
                var comparableArray = fixture.Create<GenericComparable[]>();
                var comparableValue = fixture.Create<GenericComparable>();
                var comparableFunc = fixture.Create<Func<GenericComparable, GenericComparable>>();
                var comparableArrayMax = comparableArray.Max(comparableFunc);

                Assert.That(() => comparableArray.MaxOrDefault(comparableFunc, comparableValue), Is.EqualTo(comparableArrayMax));
            }
예제 #23
0
            public void MaxOrDefault_OnGenericEnumerable_WithValue_WithNullFunc_ThrowsValidationException()
            {
                var fixture = new MultipleMockingFixture();
                var comparableArray = fixture.Create<GenericComparable[]>();
                var comparableValue = fixture.Create<GenericComparable>();
                Func<GenericComparable, GenericComparable> nullFunc = null;

                Assert.That(() => comparableArray.MaxOrDefault(nullFunc, comparableValue), Throws.TypeOf<ValidationException>().With.InnerException.TypeOf<ArgumentNullException>());
            }
예제 #24
0
            public void Shuffle_OnSequence_WithRandom_ReturnsDifferentSequence()
            {
                const int count = 100;
                var fixture = new MultipleMockingFixture(count);
                var sequence = fixture.Create<object[]>();
                var random = fixture.Create<Random>();
                var shuffled = sequence.Shuffle(random).ToArray();

                var matches = 0;
                for (var i = 0; i < count; i++)
                {
                    if (sequence[i] == shuffled[i])
                    {
                        matches++;
                    }
                    else
                    {
                        break;
                    }
                }

                Assert.That(() => matches, Is.LessThan(count));
            }
예제 #25
0
            public void ContainsAny_OnEnumerableCharacters_OnNullString_ThrowsValidationException()
            {
                string nullString = null;
                var fixture = new MultipleMockingFixture();
                var characters = fixture.Create<char[]>();

                Assert.That(() => nullString.ContainsAny(characters), Throws.TypeOf<ValidationException>().With.InnerException.TypeOf<ArgumentNullException>());
            }
        public void ContainsOnlyOne_OnSequenceOfThree_OneMatchesPredicate_ReturnsTrue()
        {
            var fixture = new MultipleMockingFixture();
            var sequenceOfThree = fixture.Create<object[]>();
            Func<object, bool> objectFunc = o => o == sequenceOfThree.First();

            Assert.That(() => sequenceOfThree.ContainsOnlyOne(objectFunc), Is.True);
        }
예제 #27
0
            public void IsEmpty_OnNonGenericCollectionEmpty_ReturnsTrue()
            {
                var fixture = new MultipleMockingFixture();
                var mock = fixture.Create<Mock<IEnumerable>>();
                IEnumerable emptyNonGenericCollection = mock.Object;

                Assert.That(() => emptyNonGenericCollection.IsEmpty(), Is.True);
            }
예제 #28
0
            public void Shuffle_OnSequence_WithNullRandom_ThrowsValidationException()
            {
                var fixture = new MultipleMockingFixture();
                var sequence = fixture.Create<IEnumerable<object>>();
                Random nullRandom = null;

                Assert.That(() => sequence.Shuffle(nullRandom), Throws.TypeOf<ValidationException>().With.InnerException.TypeOf<ArgumentNullException>());
            }
예제 #29
0
            public void NullableMin_OnSequence_WithSelector_ReturnsMin()
            {
                var fixture = new MultipleMockingFixture();
                var sequence = fixture.Create<IList<GenericComparableStruct>>();
                var selector = fixture.Create<Func<GenericComparableStruct, GenericComparableStruct>>();
                var min = sequence.Min(selector);

                Assert.That(() => sequence.NullableMin(selector), Is.EqualTo(min));
            }
예제 #30
0
            public void IsEmpty_OnNonGenericCollectionMultipleItem_ReturnsFalse()
            {
                var fixture = new MultipleMockingFixture();
                IEnumerable nonEmptyNonGenericCollection = fixture.CreateMany<object>();

                Assert.That(() => nonEmptyNonGenericCollection.IsEmpty(), Is.False);
            }