예제 #1
0
            public void WhenHaveReceivedTooMany_ShouldThrow()
            {
                // Arrange
                var sub   = Substitute.For <IFoo>();
                var count = GetRandomInt(1, 10);

                // Act
                PyLike.Range(0, count + GetRandomInt(1, 10)).ForEach(_ => sub.Bar());
                Assert.That(() => Expect(sub).To.Have.Received(count).Bar(),
                            Throws.Exception.InstanceOf <ReceivedCallsException>());
                // Assert
            }
예제 #2
0
            public void WhenHaveReceivedTheCorrectAmount_ShouldNotThrow()
            {
                // Arrange
                var sub   = Substitute.For <IFoo>();
                var count = GetRandomInt(1, 5);

                // Act
                PyLike.Range(0, count).ForEach(_ => sub.Bar());
                // Assert
                Expect(sub).To.Have
                .Received(count)
                .Bar();
            }
예제 #3
0
            public void Contain_All_MatchedByWithIndex_WhenCollectionHasMismatchesWithMatcher_ShouldThrow()
            {
                // Arrange
                var items = PyLike.Range(10).Select(i => i).ToArray();

                // Pre-Assert
                // Act
                Assert.That(
                    () =>
                {
                    Expect(items).To.Contain.All().Matched.By((idx, item) => item == idx);
                },
                    Throws.Nothing);
                // Assert
            }
예제 #4
0
파일: All.cs 프로젝트: tammylotter/NExpect
        public void WhenAllMatch_ShouldNotThrow()
        {
            // Arrange
            var search     = GetRandomString(4);
            var collection = PyLike.Range(GetRandomInt(3, 5)).Select(i => search);

            // Pre-Assert

            // Act
            Assert.That(() =>
            {
                Expect(collection).To.Contain.All().Equal.To(search);
            },
                        Throws.Nothing);
            // Assert
        }
예제 #5
0
            public void Contain_All_WhenCollectionHasNoMismatches_ShouldNotThrow()
            {
                // Arrange
                var search     = GetRandomString();
                var collection = PyLike.Range(2, 4).Select(i => search);

                // Pre-Assert
                // Act
                Assert.That(
                    () =>
                {
                    Expect(collection).To.Contain.All().Equal.To(search);
                },
                    Throws.Nothing);
                // Assert
            }
예제 #6
0
파일: All.cs 프로젝트: tammylotter/NExpect
        public void NegatedAlt_WhenAllMatch_ShouldThrow()
        {
            // Arrange
            var search     = GetRandomString(4);
            var collection = PyLike.Range(GetRandomInt(3, 5)).Select(i => search);

            // Pre-Assert

            // Act
            Assert.That(() =>
            {
                Expect(collection).To.Not.Contain.All().Equal.To(search);
            },
                        Throws.Exception.InstanceOf <UnmetExpectationException>());

            // Assert
        }
예제 #7
0
            public void Contain_Any_MatchedByWithIndex_WhenCollectionHasMismatchesWithMatcher_ShouldThrow()
            {
                // Arrange
                var items = PyLike.Range(10).Select(i => i + 1).ToArray();

                // Pre-Assert
                // Act
                Assert.That(
                    () =>
                {
                    Expect(items).To.Contain.Any().Matched.By((idx, item) => item == idx);
                },
                    Throws.Exception
                    .InstanceOf <UnmetExpectationException>()
                    .With.Message.Contains("Expected to find any matching but found none"));
                // Assert
            }
예제 #8
0
파일: Any.cs 프로젝트: tammylotter/NExpect
        public void WhenHaveActualAllMatchingSearch_ShouldNotThrow()
        {
            // Arrange
            var search = GetRandomString();
            var actual = PyLike.Range(GetRandomInt(2, 4)).Select(i => search);

            // Pre-Assert

            // Act
            Assert.That(() =>
            {
                Expect(actual).To.Contain.Any().Equal.To(search);
            },
                        Throws.Nothing);

            // Assert
        }
예제 #9
0
파일: All.cs 프로젝트: tammylotter/NExpect
        public void WhenNotAllMatch_ShouldNotThrow()
        {
            // Arrange
            var search     = GetRandomString(4);
            var collection = PyLike.Range(GetRandomInt(3, 5))
                             .Select(i => search)
                             .Union(new[] { GetAnother(search) });

            // Pre-Assert

            // Act
            Assert.That(() =>
            {
                Expect(collection).To.Contain.All().Equal.To(search);
            },
                        Throws.Exception.InstanceOf <UnmetExpectationException>());
            // Assert
        }
예제 #10
0
        public void CopyTo_ShouldCopy_AllUniqueByKey_ToTheGivenIndexOfTheArray()
        {
            // Arrange
            var       array  = new KeyValuePair <string, string> [10];
            const int index  = 1;
            var       kvp1   = new KeyValuePair <string, string>("key1", "value1");
            var       kvp2   = new KeyValuePair <string, string>("key2", "value2");
            var       kvp3   = new KeyValuePair <string, string>("key3", "value3");
            var       inner1 = new Dictionary <string, string>
            {
                [kvp1.Key] = kvp1.Value,
                [kvp2.Key] = kvp2.Value
            };

            var inner2 = new Dictionary <string, string>()
            {
                ["key1"]   = "moocakes",
                [kvp3.Key] = kvp3.Value
            };

            var sut = Create(inner1, inner2);

            // Pre-assert

            // Act
            sut.CopyTo(array, index);

            // Assert
            var defaultVal = default(KeyValuePair <string, string>);

            Expectations.Expect(array[0]).To.Equal(defaultVal);
            Expectations.Expect(array.Any(e => e.Equals(kvp1))).To.Be.True();
            Expectations.Expect(array.Any(e => e.Equals(kvp2))).To.Be.True();
            Expectations.Expect(array.Any(e => e.Equals(kvp3))).To.Be.True();
            PyLike.Range(4, 10).ForEach(i => Expectations.Expect(array[i]).To.Equal(defaultVal));
        }
        public void CopyTo_ShouldCopyKnownKeyValuePairs()
        {
            // Arrange
            var start     = RandomValueGen.GetRandomInt(2, 4);
            var arraySize = RandomValueGen.GetRandomInt(10, 15);
            var items     = RandomValueGen.GetRandomArray <KeyValuePair <string, string> >(2, 4);
            var target    = new KeyValuePair <string, string> [arraySize];
            var sut       = Create <string, string>();

            items.ForEach(sut.Add);

            // Pre-assert

            // Act
            sut.CopyTo(target, start);

            // Assert
            var defaultValue = default(KeyValuePair <string, string>);

            PyLike.Range(start).ForEach(i => Expect(target[i]).To.Equal(defaultValue));
            PyLike.Range(start + items.Length, arraySize).ForEach(
                i => Expect(target[i]).To.Equal(defaultValue));
            items.ForEach(i => Expect(target).To.Contain.Exactly(1).Equal.To(i));
        }