当前位置: 首页>>代码示例>>C#>>正文


C# Microsoft.VisualStudio.TestPlatform.UnitTestFramework.Should方法代码示例

本文整理汇总了C#中Microsoft.VisualStudio.TestPlatform.UnitTestFramework.Should方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.VisualStudio.TestPlatform.UnitTestFramework.Should方法的具体用法?C# Microsoft.VisualStudio.TestPlatform.UnitTestFramework.Should怎么用?C# Microsoft.VisualStudio.TestPlatform.UnitTestFramework.Should使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.VisualStudio.TestPlatform.UnitTestFramework的用法示例。


在下文中一共展示了Microsoft.VisualStudio.TestPlatform.UnitTestFramework.Should方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Should_fail_when_asserting_collection_with_items_is_empty

        public void Should_fail_when_asserting_collection_with_items_is_empty()
        {
            IEnumerable<string> collection = new[] { "one", "two", "three" };
            Action act = () => collection.Should().BeEmpty();

            act.ShouldThrow<AssertFailedException>();
        }
开发者ID:rodrigolessa,项目名称:fluentassertions,代码行数:7,代码来源:GenericCollectionAssertionOfStringSpecs.cs

示例2: Should_fail_when_asserting_collection_has_a_count_that_is_different_from_the_number_of_items

        public void Should_fail_when_asserting_collection_has_a_count_that_is_different_from_the_number_of_items()
        {
            IEnumerable<string> collection = new[] { "one", "two", "three" };
            Action act = () => collection.Should().HaveCount(4);

            act.ShouldThrow<AssertFailedException>();
        }
开发者ID:rodrigolessa,项目名称:fluentassertions,代码行数:7,代码来源:GenericCollectionAssertionOfStringSpecs.cs

示例3: Should_fail_with_descriptive_message_when_asserting_collection_with_items_is_empty

 public void Should_fail_with_descriptive_message_when_asserting_collection_with_items_is_empty()
 {
     IEnumerable<string> collection = new[] { "one", "two", "three" };
     var assertions = collection.Should();
     assertions.Invoking(x => x.BeEmpty("because we want to test the failure {0}", "message"))
         .ShouldThrow<AssertFailedException>()
         .WithMessage("Expected collection to be empty because we want to test the failure message, but found 3.");
 }
开发者ID:rodrigolessa,项目名称:fluentassertions,代码行数:8,代码来源:GenericCollectionAssertionOfStringSpecs.cs

示例4: Should_fail_when_asserting_collection_is_not_subset_of_a_superset_collection

        public void Should_fail_when_asserting_collection_is_not_subset_of_a_superset_collection()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            IEnumerable<string> subject = new [] { "one", "two" };
            IEnumerable<string> otherSet = new [] { "one", "two", "three" };

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().NotBeSubsetOf(otherSet, "because I'm {0}", "mistaken");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage(
                "Did not expect collection {\"one\", \"two\"} to be a subset of {\"one\", \"two\", \"three\"} because I'm mistaken.");
        }
开发者ID:rodrigolessa,项目名称:fluentassertions,代码行数:19,代码来源:GenericCollectionAssertionOfStringSpecs.cs

示例5: When_collection_does_not_contain_an_expected_item_matching_a_predicate_it_should_throw

        public void When_collection_does_not_contain_an_expected_item_matching_a_predicate_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            IEnumerable<int> collection = new[] { 1, 2, 3 };

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => collection.Should().Contain(item => item > 3, "at least {0} item should be larger than 3", 1);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage(
                "Collection {1, 2, 3} should have an item matching (item > 3) because at least 1 item should be larger than 3.");
        }
开发者ID:rodolfograve,项目名称:fluentassertions,代码行数:18,代码来源:GenericCollectionAssertionsSpecs.cs

示例6: When_a_collection_of_strings_does_not_contain_the_expected_string_it_should_throw

        public void When_a_collection_of_strings_does_not_contain_the_expected_string_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var strings = new[] { "string1", "string2", "string3" };

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => strings.Should().Contain("string4", "because {0} is required", "4");

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage(
                "Expected collection {\"string1\", \"string2\", \"string3\"} to contain \"string4\" because 4 is required.");
        }
开发者ID:rodolfograve,项目名称:fluentassertions,代码行数:18,代码来源:GenericCollectionAssertionsSpecs.cs

示例7: When_a_collection_contains_a_single_item_matching_a_predicate_it_should_succeed

        public void When_a_collection_contains_a_single_item_matching_a_predicate_it_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            IEnumerable<int> collection = new[] { 1, 2, 3 };

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => collection.Should().ContainSingle(item => (item == 2));

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
开发者ID:rodolfograve,项目名称:fluentassertions,代码行数:17,代码来源:GenericCollectionAssertionsSpecs.cs

示例8: Should_succeed_when_asserting_collection_is_equal_to_the_same_collection

 public void Should_succeed_when_asserting_collection_is_equal_to_the_same_collection()
 {
     IEnumerable<string> collection1 = new[] { "one", "two", "three" };
     IEnumerable<string> collection2 = new[] { "one", "two", "three" };
     collection1.Should().Equal(collection2);
 }
开发者ID:rodrigolessa,项目名称:fluentassertions,代码行数:6,代码来源:GenericCollectionAssertionOfStringSpecs.cs

示例9: When_collections_are_unexpectingly_equivalent_it_should_throw

        public void When_collections_are_unexpectingly_equivalent_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            IEnumerable<string> collection1 = new[] { "one", "two", "three" };
            IEnumerable<string> collection2 = new[] { "three", "one", "two" };

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => collection1.Should().NotBeEquivalentTo(collection2);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage(
                "Expected collection {\"one\", \"two\", \"three\"} not be equivalent with collection {\"three\", \"one\", \"two\"}.");
        }
开发者ID:rodrigolessa,项目名称:fluentassertions,代码行数:19,代码来源:GenericCollectionAssertionOfStringSpecs.cs

示例10: When_both_collections_have_the_same_number_elements_it_should_succeed

        public void When_both_collections_have_the_same_number_elements_it_should_succeed()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            IEnumerable<string> firstCollection = new [] { "one", "two", "three" };
            IEnumerable<string> secondCollection = new [] { "four", "five", "six" };

            var extensions = firstCollection.Should();

            //-------------------------------------------------------------------------------------------------------------------
            // Act / Assert
            //-------------------------------------------------------------------------------------------------------------------
            extensions.HaveSameCount(secondCollection);
        }
开发者ID:rodrigolessa,项目名称:fluentassertions,代码行数:15,代码来源:GenericCollectionAssertionOfStringSpecs.cs

示例11: When_a_collection_contains_duplicate_items_it_should_throw

        public void When_a_collection_contains_duplicate_items_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            IEnumerable<string> collection = new [] { "one", "two", "three", "three" };

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => collection.Should().OnlyHaveUniqueItems("{0} don't like {1}", "we", "duplicates");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage(
                "Expected collection to only have unique items because we don't like duplicates, but item \"three\" is not unique.");
        }
开发者ID:rodrigolessa,项目名称:fluentassertions,代码行数:18,代码来源:GenericCollectionAssertionOfStringSpecs.cs

示例12: When_asserting_the_items_in_an_two_non_intersecting_collections_intersect_it_should_throw

        public void When_asserting_the_items_in_an_two_non_intersecting_collections_intersect_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            IEnumerable<string> collection = new[] { "one", "two", "three" };
            IEnumerable<string> otherCollection = new[] { "four", "five" };

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action = () => collection.Should().IntersectWith(otherCollection, "they should share items");

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            action.ShouldThrow<AssertFailedException>()
                .WithMessage("Expected collection to intersect with {\"four\", \"five\"} because they should share items," +
                    " but {\"one\", \"two\", \"three\"} does not contain any shared items.");
        }
开发者ID:rodrigolessa,项目名称:fluentassertions,代码行数:20,代码来源:GenericCollectionAssertionOfStringSpecs.cs

示例13: When_asserting_the_items_in_an_two_non_intersecting_collections_do_not_intersect_it_should_succeed

        public void When_asserting_the_items_in_an_two_non_intersecting_collections_do_not_intersect_it_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            IEnumerable<string> collection = new[] { "one", "two", "three" };
            IEnumerable<string> otherCollection = new[] { "four", "five" };

            //-----------------------------------------------------------------------------------------------------------
            // Act / Assert
            //-----------------------------------------------------------------------------------------------------------
            collection.Should().NotIntersectWith(otherCollection);
        }
开发者ID:rodrigolessa,项目名称:fluentassertions,代码行数:13,代码来源:GenericCollectionAssertionOfStringSpecs.cs

示例14: When_asserting_the_items_in_an_two_intersecting_collections_do_not_intersect_it_should_throw

        public void When_asserting_the_items_in_an_two_intersecting_collections_do_not_intersect_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            IEnumerable<string> collection = new[] { "one", "two", "three" };
            IEnumerable<string> otherCollection = new[] { "two", "three", "four" };

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action = () => collection.Should().NotIntersectWith(otherCollection, "they should not share items");

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            action.ShouldThrow<AssertFailedException>()
                .WithMessage("Did not expect collection to intersect with {\"two\", \"three\", \"four\"} because they should not share items," +
                    " but found the following shared items {\"two\", \"three\"}.");
        }
开发者ID:rodrigolessa,项目名称:fluentassertions,代码行数:20,代码来源:GenericCollectionAssertionOfStringSpecs.cs

示例15: When_asserting_collection_with_items_is_not_empty_it_should_succeed

 public void When_asserting_collection_with_items_is_not_empty_it_should_succeed()
 {
     IEnumerable<string> collection = new[] { "one", "two", "three" };
     collection.Should().NotBeEmpty();
 }
开发者ID:rodrigolessa,项目名称:fluentassertions,代码行数:5,代码来源:GenericCollectionAssertionOfStringSpecs.cs


注:本文中的Microsoft.VisualStudio.TestPlatform.UnitTestFramework.Should方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。