本文整理汇总了C#中List.Should方法的典型用法代码示例。如果您正苦于以下问题:C# List.Should方法的具体用法?C# List.Should怎么用?C# List.Should使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.Should方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handlers_Can_Be_Unsubscribed
public void Handlers_Can_Be_Unsubscribed()
{
var pub = new Publisher();
var calledSubscribers = new List<int>();
var sub1 = new InstanceSubscriber(1, pub, calledSubscribers.Add);
var sub2 = new InstanceSubscriber(2, pub, calledSubscribers.Add);
StaticSubscriber.FooWasRaised = false;
StaticSubscriber.Subscribe(pub);
// Make sure they really were subscribed
pub.Raise();
calledSubscribers.Should().Equal(1, 2);
StaticSubscriber.FooWasRaised.Should().BeTrue();
calledSubscribers.Clear();
sub1.Unsubscribe(pub);
pub.Raise();
calledSubscribers.Should().Equal(2);
StaticSubscriber.FooWasRaised = false;
StaticSubscriber.Unsubscribe(pub);
pub.Raise();
StaticSubscriber.FooWasRaised.Should().BeFalse();
calledSubscribers.Clear();
sub2.Unsubscribe(pub);
pub.Raise();
calledSubscribers.Should().BeEmpty();
// Make sure subscribers are not collected before the end of the test
GC.KeepAlive(sub1);
GC.KeepAlive(sub2);
}
示例2: Should_fluent_assertions
public void Should_fluent_assertions()
{
object obj = null;
obj.Should().Be.Null();
obj = new object();
obj.Should().Be.OfType(typeof(object));
obj.Should().Equal(obj);
obj.Should().Not.Be.Null();
obj.Should().Not.Be.SameAs(new object());
obj.Should().Not.Be.OfType<string>();
obj.Should().Not.Equal("foo");
obj = "x";
obj.Should().Not.Be.InRange("y", "z");
obj.Should().Be.InRange("a", "z");
obj.Should().Be.SameAs("x");
"This String".Should().Contain("This");
"This String".Should().Not.Be.Empty();
"This String".Should().Not.Contain("foobar");
false.Should().Be.False();
true.Should().Be.True();
var list = new List<object>();
list.Should().Count.Zero();
list.Should().Not.Contain.Item(new object());
var item = new object();
list.Add(item);
list.Should().Not.Be.Empty();
list.Should().Contain.Item(item);
}
示例3: InstallPackageTest
public async Task InstallPackageTest() {
await Workflow.RSession.EnsureHostStartedAsync(new RHostStartupInfo {Name = nameof(InstallPackageTest)}, null, 50000);
var completionSets = new List<CompletionSet>();
for (int i = 0; i < 2; i++) {
try {
await Workflow.Packages.UninstallPackageAsync("abc", null);
//await Workflow.RSession.ExecuteAsync("remove.packages('abc')", REvaluationKind.Mutating);
} catch (RException) { }
await PackageIndex.BuildIndexAsync();
completionSets.Clear();
RCompletionTestUtilities.GetCompletions(EditorShell, "abc::", 5, completionSets);
completionSets.Should().ContainSingle();
// Try again one more time
if (completionSets[0].Completions.Count == 0) {
break;
}
}
completionSets[0].Completions.Should().BeEmpty();
try {
await Workflow.RSession.ExecuteAsync("install.packages('abc')", REvaluationKind.Mutating);
} catch (RException) { }
await PackageIndex.BuildIndexAsync();
completionSets.Clear();
RCompletionTestUtilities.GetCompletions(EditorShell, "abc::", 5, completionSets);
completionSets.Should().ContainSingle();
completionSets[0].Completions.Should().NotBeEmpty();
}
示例4: Given_Action_And_Strings_When_Calling_Each_Then_Action_Is_Invoked_For_Each_Element
public void Given_Action_And_Strings_When_Calling_Each_Then_Action_Is_Invoked_For_Each_Element()
{
IEnumerable<int> items = new List<int> { 1, 2, 3 };
var visited = new List<int>();
Action<int> action = visited.Add;
items.Each(action);
visited.Should().ContainInOrder(items);
visited.Should().HaveCount(items.Count());
}
示例5: InstallTelemetry
public void InstallTelemetry() {
var telemetryEvents = new List<string>();
var telemetry = Substitute.For<ITelemetryService>();
telemetry.When(x => x.ReportEvent(Arg.Any<TelemetryArea>(), Arg.Any<string>(), Arg.Any<object>()))
.Do(x => telemetryEvents.Add(x.Args()[1] as string));
var coreShell = Substitute.For<ICoreShell>();
var services = Substitute.For<ICoreServices>();
services.Telemetry.Returns(telemetry);
var ps = Substitute.For<IProcessServices>();
ps.When(x => x.Start(Arg.Any<string>())).Do(c => {
c.Args()[0].Should().NotBeNull();
});
services.ProcessServices.Returns(ps);
coreShell.Services.Returns(services);
coreShell.ShowMessage(Arg.Any<string>(), Arg.Any<MessageButtons>()).Returns(MessageButtons.Yes);
var downloader = Substitute.For<IFileDownloader>();
downloader.Download(null, null, CancellationToken.None).ReturnsForAnyArgs((string)null);
var inst = new MicrosoftRClientInstaller();
inst.LaunchRClientSetup(coreShell, downloader);
telemetryEvents.Should().HaveCount(1);
telemetryEvents[0].Should().Be(RtvsTelemetry.ConfigurationEvents.RClientInstallYes);
downloader.Download(null, null, CancellationToken.None).ReturnsForAnyArgs("Failed");
telemetryEvents.Clear();
inst.LaunchRClientSetup(coreShell, downloader);
telemetryEvents.Should().HaveCount(2);
telemetryEvents[0].Should().Be(RtvsTelemetry.ConfigurationEvents.RClientInstallYes);
telemetryEvents[1].Should().Be(RtvsTelemetry.ConfigurationEvents.RClientDownloadFailed);
downloader.Download(null, null, CancellationToken.None).ReturnsForAnyArgs((string)null);
ps = Substitute.For<IProcessServices>();
ps.When(x => x.Start(Arg.Any<string>())).Do(c => {
throw new Win32Exception((unchecked((int)0x800704C7)));
});
services.ProcessServices.Returns(ps);
telemetryEvents.Clear();
inst.LaunchRClientSetup(coreShell, downloader);
telemetryEvents.Should().HaveCount(2);
telemetryEvents[0].Should().Be(RtvsTelemetry.ConfigurationEvents.RClientInstallYes);
telemetryEvents[1].Should().Be(RtvsTelemetry.ConfigurationEvents.RClientInstallCancel);
}
示例6: ReshufflesDiscards
public void ReshufflesDiscards()
{
var cards = new List<int>();
for (int i = 0; i < 95; i++)
{
var card = _deck.DrawCard();
if (card%9 == 0)
{
cards.Add(card);
_deck.DiscardCard(card);
}
}
var shuffledDiscards = new List<int>();
for (int i = 0; i < cards.Count + 4; i++)
{
if (i > 3)
{
var card = _deck.DrawCard();
card.Satisfy(x => x%9 == 0);
shuffledDiscards.Add(card);
}
else
_deck.DrawCard();
}
cards.Should().Not.Have.SameSequenceAs(shuffledDiscards);
}
示例7: FunctionDefinition01
public void FunctionDefinition01() {
var completionSets = new List<CompletionSet>();
RCompletionTestUtilities.GetCompletions(_editorShell, "x <- function()", 14, completionSets);
completionSets.Should().ContainSingle()
.Which.Completions.Should().BeEmpty();
}
示例8: BeforeComment
public void BeforeComment() {
var completionSets = new List<CompletionSet>();
RCompletionTestUtilities.GetCompletions(_editorShell, "#No", 0, completionSets);
completionSets.Should().ContainSingle()
.Which.Completions.Should().NotBeEmpty();
}
示例9: It_iterates_through_all_added_resolvers_in_order_when_they_return_null
public void It_iterates_through_all_added_resolvers_in_order_when_they_return_null()
{
var compositeCommandResolver = new CompositeCommandResolver();
var resolverCalls = new List<int>();
var mockResolver1 = new Mock<ICommandResolver>();
mockResolver1.Setup(r => r
.Resolve(It.IsAny<CommandResolverArguments>()))
.Returns(default(CommandSpec))
.Callback(() => resolverCalls.Add(1));
var mockResolver2 = new Mock<ICommandResolver>();
mockResolver2.Setup(r => r
.Resolve(It.IsAny<CommandResolverArguments>()))
.Returns(default(CommandSpec))
.Callback(() => resolverCalls.Add(2));
compositeCommandResolver.AddCommandResolver(mockResolver1.Object);
compositeCommandResolver.AddCommandResolver(mockResolver2.Object);
compositeCommandResolver.Resolve(default(CommandResolverArguments));
resolverCalls.Should()
.HaveCount(2)
.And
.ContainInOrder(new [] {1, 2});
}
示例10: ResponsePropertyCollectionsShouldBeReadOnly
public void ResponsePropertyCollectionsShouldBeReadOnly()
{
var exceptions = new HashSet<PropertyInfo>
{
typeof(ITypeMapping).GetProperty(nameof(ITypeMapping.DynamicDateFormats)),
typeof(ITypeMapping).GetProperty(nameof(ITypeMapping.Meta)),
typeof(TypeMapping).GetProperty(nameof(TypeMapping.DynamicDateFormats)),
typeof(TypeMapping).GetProperty(nameof(TypeMapping.Meta)),
#pragma warning disable 618
typeof(IMultiPercolateResponse).GetProperty(nameof(IMultiPercolateResponse.Responses)),
#pragma warning restore 618
typeof(IBulkResponse).GetProperty(nameof(IBulkResponse.ItemsWithErrors)),
typeof(IMultiSearchResponse).GetProperty(nameof(IMultiSearchResponse.AllResponses)),
};
var responseInterfaceTypes = from t in typeof(IResponse).Assembly().Types()
where t.IsInterface() && typeof(IResponse).IsAssignableFrom(t)
select t;
var ruleBreakers = new List<string>();
var seenTypes = new HashSet<Type>();
foreach (var responseType in responseInterfaceTypes)
{
FindPropertiesBreakingRule(responseType, exceptions, seenTypes, ruleBreakers);
}
ruleBreakers.Should().BeEmpty();
}
示例11: JsonReader_should_support_reading_multiple_documents
public void JsonReader_should_support_reading_multiple_documents(
[Range(0, 3)]
int numberOfDocuments)
{
var document = new BsonDocument("x", 1);
var json = document.ToJson();
var input = Enumerable.Repeat(json, numberOfDocuments).Aggregate("", (a, j) => a + j);
var expectedResult = Enumerable.Repeat(document, numberOfDocuments);
using (var jsonReader = new JsonReader(input))
{
var result = new List<BsonDocument>();
while (!jsonReader.IsAtEndOfFile())
{
jsonReader.ReadStartDocument();
var name = jsonReader.ReadName();
var value = jsonReader.ReadInt32();
jsonReader.ReadEndDocument();
var resultDocument = new BsonDocument(name, value);
result.Add(resultDocument);
}
result.Should().Equal(expectedResult);
}
}
示例12: NewValidationRulesShouldBeInTheRuleSetExceptBaselinedExceptionRules
public void NewValidationRulesShouldBeInTheRuleSetExceptBaselinedExceptionRules()
{
var validationRules = new Dictionary<object, string>();
var items = typeof(ValidationRules).GetFields().Select(f=> new KeyValuePair<object, string>(f.GetValue(null), f.Name));
foreach (var item in items)
{
validationRules.Add(item.Key, item.Value);
}
var unFoundValidationRules = new List<object>();
foreach(var ruleSet in ValidationRuleSet.GetEdmModelRuleSet(new Version(4, 0)))
{
if (validationRules.ContainsKey(ruleSet))
{
validationRules.Remove(ruleSet);
}
else
{
unFoundValidationRules.Add(validationRules);
}
}
unFoundValidationRules.Should().HaveCount(0);
// The 4 remaining rules are deprecated:
// ComplexTypeMustContainProperties
// OnlyEntityTypesCanBeOpen
// ComplexTypeInvalidPolymorphicComplexType
// ComplexTypeInvalidAbstractComplexType
validationRules.ToList().Should().HaveCount(4);
}
示例13: SuppressedCompletion
public void SuppressedCompletion(string content, int position) {
var completionSets = new List<CompletionSet>();
RCompletionTestUtilities.GetCompletions(_editorShell, content, position, completionSets);
completionSets.Should().ContainSingle()
.Which.Completions.Should().BeEmpty();
}
示例14: It_stops_iterating_through_added_resolvers_when_one_returns_nonnull
public void It_stops_iterating_through_added_resolvers_when_one_returns_nonnull()
{
var compositeCommandResolver = new CompositeCommandResolver();
var resolverCalls = new List<int>();
var mockResolver1 = new Mock<ICommandResolver>();
mockResolver1.Setup(r => r
.Resolve(It.IsAny<CommandResolverArguments>()))
.Returns(new CommandSpec(null, null, default(CommandResolutionStrategy)))
.Callback(() => resolverCalls.Add(1));
var mockResolver2 = new Mock<ICommandResolver>();
mockResolver2.Setup(r => r
.Resolve(It.IsAny<CommandResolverArguments>()))
.Returns(default(CommandSpec))
.Callback(() => resolverCalls.Add(2));
compositeCommandResolver.AddCommandResolver(mockResolver1.Object);
compositeCommandResolver.AddCommandResolver(mockResolver2.Object);
compositeCommandResolver.Resolve(default(CommandResolverArguments));
resolverCalls.Should()
.HaveCount(1)
.And
.ContainInOrder(new [] {1});
}
示例15: RCompletionSource_CommentsTest01
public void RCompletionSource_CommentsTest01() {
List<CompletionSet> completionSets = new List<CompletionSet>();
GetCompletions("#No", 3, completionSets);
completionSets.Should().ContainSingle()
.Which.Completions.Should().BeEmpty();
}