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


C# System.Should方法代码示例

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


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

示例1: Collections

        public void Collections()
        {
            var stringCollection = new[] {"abc", "jkl", "qwe", "zxc",};

            stringCollection.Should().NotContainNulls();
            stringCollection.Should().OnlyContain(s => s.Length == 3);

            stringCollection.Should().ContainSingle(x => x == "zxc");
            stringCollection.Should().BeInAscendingOrder();
        }
开发者ID:still-adam-k,项目名称:readable-tests,代码行数:10,代码来源:FluentAssertionShowoff.cs

示例2: When_two_different_objects_are_expected_to_be_the_same_it_should_fail_with_a_clear_explanation

        public void When_two_different_objects_are_expected_to_be_the_same_it_should_fail_with_a_clear_explanation()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var subject = new
            {
                Name = "John Doe"
            };

            var otherObject = new
            {
                UserName = "JohnDoe"
            };

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().BeSameAs(otherObject, "they are {0} {1}", "the", "same");

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act
                .ShouldThrow<AssertFailedException>()
                .WithMessage(
                    "Expected object to refer to \r\n{ UserName = JohnDoe } because " +
                    "they are the same, but found \r\n{ Name = John Doe }.");
        }
开发者ID:somewhatabstract,项目名称:fluentassertions,代码行数:29,代码来源:ReferenceTypeAssertionsSpecs.cs

示例3: PropertiesToRouteValueDictionary_NotNull_ReturnsCorrectList

        public void PropertiesToRouteValueDictionary_NotNull_ReturnsCorrectList ()
        {
            var result = new { a = "b" }.PropertiesToRouteValueDictionary ();

            result.Should ().Equal (new Dictionary<string, object>
                                    {
                                        { "a", "b" }
                                    });
        }
开发者ID:grieg,项目名称:Rocks.Helpers,代码行数:9,代码来源:UrlExtensionsTests.cs

示例4: When_a_collection_of_strings_contains_the_expected_string_it_should_not_throw

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

            //-----------------------------------------------------------------------------------------------------------
            // Act / Assert
            //-----------------------------------------------------------------------------------------------------------
            strings.Should().Contain("string2");
        }
开发者ID:uhaciogullari,项目名称:FluentAssertions.MonoTouch,代码行数:12,代码来源:GenericCollectionAssertionsSpecs.cs

示例5: When_collection_does_contain_an_expected_item_matching_a_predicate_it_should_not_throw

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

            //-----------------------------------------------------------------------------------------------------------
            // Act / Assert
            //-----------------------------------------------------------------------------------------------------------
            collection.Should().Contain(item => item == 2);
        }
开发者ID:uhaciogullari,项目名称:FluentAssertions.MonoTouch,代码行数:12,代码来源:GenericCollectionAssertionsSpecs.cs

示例6: 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:lothrop,项目名称:fluentassertions,代码行数:18,代码来源:GenericCollectionAssertionsSpecs.cs

示例7: When_collection_does_contain_an_expected_item_matching_a_predicate_it_should_allow_chaining_it

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

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => collection.Should().Contain(item => item == 2).Which.Should().BeGreaterThan(4);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage(
                "Expected*greater*4*2*");
        }
开发者ID:lothrop,项目名称:fluentassertions,代码行数:18,代码来源:GenericCollectionAssertionsSpecs.cs

示例8: 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:uhaciogullari,项目名称:FluentAssertions.MonoTouch,代码行数:18,代码来源:GenericCollectionAssertionsSpecs.cs

示例9: SomePipelineFailuresAreRecoverable

		/** == Unrecoverable exceptions 
		* Unrecoverable exceptions are excepted exceptions that are grounds to exit the client pipeline immediately. 
		* By default the client won't throw on any ElasticsearchClientException but return an invalid response. 
		* You can configure the client to throw using ThrowExceptions() on ConnectionSettings. The following test
		* both a client that throws and one that returns an invalid response with an `.OriginalException` exposed 
		*/

		[U] public void SomePipelineFailuresAreRecoverable()
		{
			var recoverablExceptions = new[]
			{
				new PipelineException(PipelineFailure.BadResponse),
				new PipelineException(PipelineFailure.PingFailure),
			};
			recoverablExceptions.Should().OnlyContain(e => e.Recoverable);

			var unrecoverableExceptions = new[]
			{
				new PipelineException(PipelineFailure.CouldNotStartSniffOnStartup),
				new PipelineException(PipelineFailure.SniffFailure),
				new PipelineException(PipelineFailure.Unexpected),
				new PipelineException(PipelineFailure.BadAuthentication),
				new PipelineException(PipelineFailure.MaxRetriesReached),
				new PipelineException(PipelineFailure.MaxTimeoutReached)
			};
			unrecoverableExceptions.Should().OnlyContain(e => !e.Recoverable);
		}
开发者ID:emohebi,项目名称:elasticsearch-net,代码行数:27,代码来源:UnrecoverableExceptions.doc.cs

示例10: Context_should_be_empty_if_execute_not_called_with_any_context_data

        public void Context_should_be_empty_if_execute_not_called_with_any_context_data()
        {
            IDictionary<string, object> contextData = new { key1 = "value1", key2 = "value2" }.AsDictionary();

            Action<Exception, TimeSpan, Context> onBreak = (_, __, context) => { contextData = context; };
            Action<Context> onReset = _ => { };

            var time = 1.January(2000);
            SystemClock.UtcNow = () => time;

            CircuitBreakerPolicy breaker = Policy
                .Handle<DivideByZeroException>()
                .AdvancedCircuitBreaker(
                    failureThreshold: 0.5,
                    samplingDuration: TimeSpan.FromSeconds(10),
                    minimumThroughput: 4,
                    durationOfBreak: TimeSpan.FromSeconds(30),
                    onBreak: onBreak,
                    onReset: onReset
                );

            // Four of four actions in this test throw handled failures.
            breaker.Invoking(x => x.RaiseException<DivideByZeroException>())
                .ShouldThrow<DivideByZeroException>();
            breaker.CircuitState.Should().Be(CircuitState.Closed);

            breaker.Invoking(x => x.RaiseException<DivideByZeroException>())
                .ShouldThrow<DivideByZeroException>();
            breaker.CircuitState.Should().Be(CircuitState.Closed);

            breaker.Invoking(x => x.RaiseException<DivideByZeroException>())
                .ShouldThrow<DivideByZeroException>();
            breaker.CircuitState.Should().Be(CircuitState.Closed);

            breaker.Invoking(x => x.RaiseException<DivideByZeroException>())
                .ShouldThrow<DivideByZeroException>();

            breaker.CircuitState.Should().Be(CircuitState.Open);

            contextData.Should().BeEmpty();
        }
开发者ID:reisenberger,项目名称:Polly,代码行数:41,代码来源:AdvancedCircuitBreakerSpecs.cs

示例11: Context_should_be_empty_if_execute_not_called_with_any_context_data

        public void Context_should_be_empty_if_execute_not_called_with_any_context_data()
        {
            IDictionary<string, object> contextData = new { key1 = "value1", key2 = "value2" }.AsDictionary();

            Action<DelegateResult<ResultPrimitive>, TimeSpan, Context> onBreak = (_, __, context) => { contextData = context; };
            Action<Context> onReset = _ => { };

            CircuitBreakerPolicy<ResultPrimitive> breaker = Policy
                .HandleResult(ResultPrimitive.Fault)
                .CircuitBreaker(2, TimeSpan.FromMinutes(1), onBreak, onReset);

            breaker.RaiseResultSequence(ResultPrimitive.Fault)
                .Should().Be(ResultPrimitive.Fault);

            breaker.RaiseResultSequence(ResultPrimitive.Fault)
                .Should().Be(ResultPrimitive.Fault);

            breaker.CircuitState.Should().Be(CircuitState.Open);

            contextData.Should().BeEmpty();
        }
开发者ID:reisenberger,项目名称:Polly,代码行数:21,代码来源:CircuitBreakerTResultSpecs.cs

示例12: Context_should_be_empty_if_execute_not_called_with_any_context_data

        public void Context_should_be_empty_if_execute_not_called_with_any_context_data()
        {
            IDictionary<string, object> contextData = new {key1 = "value1", key2 = "value2"}.AsDictionary();

            Action<Exception, TimeSpan, Context> onBreak = (_, __, context) => { contextData = context; };
            Action<Context> onReset = _ => { };

            CircuitBreakerPolicy breaker = Policy
                .Handle<DivideByZeroException>()
                .CircuitBreaker(2, TimeSpan.FromMinutes(1), onBreak, onReset);

            breaker.Invoking(x => x.RaiseException<DivideByZeroException>())
                .ShouldThrow<DivideByZeroException>();

            breaker.Invoking(x => x.RaiseException<DivideByZeroException>())
                .ShouldThrow<DivideByZeroException>();

            breaker.CircuitState.Should().Be(CircuitState.Open);

            contextData.Should().BeEmpty();
        }
开发者ID:reisenberger,项目名称:Polly,代码行数:21,代码来源:CircuitBreakerSpecs.cs

示例13: GetSameMappingFromTwoDifferentIndices

		public void GetSameMappingFromTwoDifferentIndices()
		{
			var indices = new[]
			{
				ElasticsearchConfiguration.NewUniqueIndexName(),
				ElasticsearchConfiguration.NewUniqueIndexName()
			};

			var x = this.Client.CreateIndex(indices.First(), s => s
				.AddMapping<ElasticsearchProject>(m => m.MapFromAttributes())
			);
			Assert.IsTrue(x.Acknowledged, x.ConnectionStatus.ToString());

			x = this.Client.CreateIndex(indices.Last(), s => s
				.AddMapping<ElasticsearchProject>(m => m.MapFromAttributes())
			);
			Assert.IsTrue(x.Acknowledged, x.ConnectionStatus.ToString());

			var response = this.Client.GetMapping<ElasticsearchProject>(i => i
				.Index(string.Join(",", indices))
				.Type("elasticsearchprojects")
			);
			response.Should().NotBeNull();
			response.Mappings.Should().NotBeEmpty()
				.And.HaveCount(2);
			foreach (var indexMapping in response.Mappings)
			{
				var indexName = indexMapping.Key;
				indices.Should().Contain(indexName);
				var mappings = indexMapping.Value;
				mappings.Should().NotBeEmpty().And.HaveCount(1);
				foreach (var mapping in mappings)
				{
					mapping.TypeName.Should().Be("elasticsearchprojects");
					TestElasticsearchProjectMapping(mapping.Mapping);
				}
			}


		}
开发者ID:strongant,项目名称:elasticsearch-net,代码行数:40,代码来源:GetMultipleMappingTests.cs

示例14:

        public static void Returns_unmodified_sequence_when_sequence_does_not_contain_any_element_to_remove_with_equality_comparer()
        {
            IEnumerable<string> stringNumbers = new[] { "1", "22", "333", "4444" };
            const string elementToRemove = "55555";
            IEqualityComparer<string> stringLengthEqualityComparer = new StringLengthEqualityComparer<string>();

            stringNumbers = stringNumbers.Without(stringLengthEqualityComparer, elementToRemove);

            stringNumbers.Should().HaveCount(4);
        }
开发者ID:razormad,项目名称:ExtraLINQ,代码行数:10,代码来源:WithoutTests.cs

示例15: RemoveBackwardsWhere_RemoveElementsProperly

 public void RemoveBackwardsWhere_RemoveElementsProperly()
 {
     var array = new[] { 1, 2, 3, 4, 5 }.ToList();
     array.RemoveBackwardsWhere((i, item) => item % 2 == 0);
     array.Should().BeEquivalentTo(1, 3, 5);
 }
开发者ID:ApocalypticOctopus,项目名称:Apocalyptic.Utilities.Net,代码行数:6,代码来源:EnumerableExtensionsTests.cs


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