本文整理汇总了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();
}
示例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 }.");
}
示例3: PropertiesToRouteValueDictionary_NotNull_ReturnsCorrectList
public void PropertiesToRouteValueDictionary_NotNull_ReturnsCorrectList ()
{
var result = new { a = "b" }.PropertiesToRouteValueDictionary ();
result.Should ().Equal (new Dictionary<string, object>
{
{ "a", "b" }
});
}
示例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.");
}
示例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*");
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
}
}
示例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);
}
示例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);
}