Exemple #1
0
        public void IsTrueForAll_Predicate_CollectionEmpty_ThrowsException()
        {
            var collection = new List <string>();
            var ex         = Assert.ThrowsException <AssertFailedException>(() => EnumerableAssert.IsTrueForAll(collection, s => s.IndexOf("e") == 0));

            Assert.AreEqual("EnumerableAssert.IsTrueForAll failed. Collection is empty.", ex.Message);
        }
Exemple #2
0
        public void CollectAndAssert()
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();

            EnumerableAssert.IsTrueForAll(ReferencesExpectedToBeCollected, wr => wr.Target == null, "Object should have been collected.");
            EnumerableAssert.IsTrueForAll(ReferencesNotExpectedToBeCollected, wr => wr.Target != null, "Object should be have NOT been collected.");
        }
Exemple #3
0
        public void IsTrueForAll_Predicate_AllElementsMatch()
        {
            var collection = new List <string> {
                "expected", "extra expected", "expected as well"
            };

            EnumerableAssert.IsTrueForAll(collection, s => s.IndexOf("e") == 0);
        }
Exemple #4
0
        public void IsTrueForAll_Predicate_OneElementMatches_Size1()
        {
            var collection = new List <string> {
                "expected"
            };

            EnumerableAssert.IsTrueForAll(collection, s => s.IndexOf("e") == 0);
        }
Exemple #5
0
        public void IsTrueForAll_Predicate_NotAllElementsMatch()
        {
            var collection = new List <string> {
                "expected", "notexpected", "expected as well"
            };
            var ex = Assert.ThrowsException <AssertFailedException>(() => EnumerableAssert.IsTrueForAll(collection, s => s.IndexOf("e") == 0));

            Assert.AreEqual("EnumerableAssert.IsTrueForAll failed. Not all elements match the predicate.", ex.Message);
        }
Exemple #6
0
        public void IsTrueForAll_Predicate_NoElementMatches_ThrowsException()
        {
            var collection = new List <string> {
                "element"
            };
            var ex = Assert.ThrowsException <AssertFailedException>(() => EnumerableAssert.IsTrueForAll(collection, s => s.IndexOf("e") == 1));

            Assert.AreEqual("EnumerableAssert.IsTrueForAll failed. No elements match the predicate.", ex.Message);
        }
Exemple #7
0
        public void IsTrueForAll_Predicate_ExpectedItemNull_ThrowsException()
        {
            var collection = new List <string> {
                "element"
            };
            var ex = Assert.ThrowsException <ArgumentNullException>(() => EnumerableAssert.IsTrueForAll(collection, null as Func <string, bool>));

            Assert.AreEqual($"Value cannot be null.{Environment.NewLine}Parameter name: predicate", ex.Message);
        }
            public void VerifyImport(params int[] expectedValues)
            {
                object[] untypedExpectedValues = expectedValues.Cast <object>().ToArray();

                ExportsAssert.AreEqual(CollectionPlain, untypedExpectedValues);
                ExportsAssert.AreEqual(CollectionPlainRawMetadata, untypedExpectedValues);
                EnumerableAssert.IsTrueForAll(CollectionPlainRawMetadata, i => true.Equals(i.Metadata["PropertyName"]));
                EnumerableAssert.IsEmpty(CollectionPlainEmpty);
                EnumerableAssert.IsEmpty(CollectionPlainEmptyRawMetadata);

                // Add a new Export to this collection to ensure that it doesn't
                // modifiy the other collections because they should each have there
                // own collection instance
                CollectionPlain.Add(ExportFactory.Create <object>("Value"));

                ExportsAssert.AreEqual(CollectionTyped, expectedValues);
                ExportsAssert.AreEqual(CollectionTypedRawMetadata, expectedValues);
                EnumerableAssert.IsTrueForAll(CollectionTypedRawMetadata, i => true.Equals(i.Metadata["PropertyName"]));
                EnumerableAssert.IsEmpty(CollectionTypedEmpty);

                ExportsAssert.AreEqual(CollectionTypedMetadata, expectedValues);
#if !SILVERLIGHT // Silverlight doesn't support strongly typed metadata
                EnumerableAssert.IsTrueForAll(CollectionTypedMetadata, i => true == i.Metadata.PropertyName);
#endif //!SILVERLIGHT
                EnumerableAssert.IsEmpty(CollectionTypedMetadataEmpty);

                EnumerableAssert.AreEqual(ReadWriteEnumerable, expectedValues);
                EnumerableAssert.IsEmpty(ReadWriteEnumerableEmpty);

                ExportsAssert.AreEqual(MetadataUntypedEnumerable, untypedExpectedValues);
                ExportsAssert.AreEqual(MetadataUntypedEnumerableRawMetadata, untypedExpectedValues);
                EnumerableAssert.IsTrueForAll(MetadataUntypedEnumerableRawMetadata, i => true.Equals(i.Metadata["PropertyName"]));
                EnumerableAssert.IsEmpty(MetadataUntypedEnumerableEmpty);
                EnumerableAssert.IsEmpty(MetadataUntypedEnumerableEmptyRawMetadata);

                ExportsAssert.AreEqual(MetadataTypedEnumerable, expectedValues);
                ExportsAssert.AreEqual(MetadataTypedEnumerableRawMetadata, expectedValues);
                EnumerableAssert.IsTrueForAll(MetadataTypedEnumerableRawMetadata, i => true.Equals(i.Metadata["PropertyName"]));
                EnumerableAssert.IsEmpty(MetadataTypedEnumerableEmpty);

                ExportsAssert.AreEqual(MetadataFullyTypedEnumerable, expectedValues);
#if !SILVERLIGHT // Silverlight doesn't support strongly typed metadata
                EnumerableAssert.IsTrueForAll(MetadataFullyTypedEnumerable, i => true == i.Metadata.PropertyName);
#endif //!SILVERLIGHT
                EnumerableAssert.IsEmpty(MetadataFullyTypedEnumerableEmpty);
            }
Exemple #9
0
        public void IsTrueForAll_Predicate_CollectionNull_ThrowsException()
        {
            var ex = Assert.ThrowsException <AssertFailedException>(() => EnumerableAssert.IsTrueForAll <string>(null, s => s.IndexOf("e") == 0));

            Assert.AreEqual("EnumerableAssert.IsTrueForAll failed. Collection is null.", ex.Message);
        }