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


C# List.Should方法代码示例

本文整理汇总了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);
        }
开发者ID:thomaslevesque,项目名称:WeakEvent,代码行数:33,代码来源:WeakEventSourceTests.cs

示例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);
        }
开发者ID:bsatrom,项目名称:Faceplant,代码行数:34,代码来源:Should.cs

示例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();
        }
开发者ID:Microsoft,项目名称:RTVS,代码行数:35,代码来源:PackageInstallTest.cs

示例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());
        }
开发者ID:uffekhansen,项目名称:FoosballGameManager,代码行数:11,代码来源:EnumerableExtensions.cs

示例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);
        }
开发者ID:Microsoft,项目名称:RTVS,代码行数:52,代码来源:RClientTest.cs

示例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);
        }
开发者ID:JordanZaerr,项目名称:GameOf99Network,代码行数:27,代码来源:DeckTests.cs

示例7: FunctionDefinition01

        public void FunctionDefinition01() {
            var completionSets = new List<CompletionSet>();
            RCompletionTestUtilities.GetCompletions(_editorShell, "x <- function()", 14, completionSets);

            completionSets.Should().ContainSingle()
                .Which.Completions.Should().BeEmpty();
        }
开发者ID:Microsoft,项目名称:RTVS,代码行数:7,代码来源:RCompletionSourceTest.cs

示例8: BeforeComment

        public void BeforeComment() {
            var completionSets = new List<CompletionSet>();
            RCompletionTestUtilities.GetCompletions(_editorShell, "#No", 0, completionSets);

            completionSets.Should().ContainSingle()
                .Which.Completions.Should().NotBeEmpty();
        }
开发者ID:Microsoft,项目名称:RTVS,代码行数:7,代码来源:RCompletionSourceTest.cs

示例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});

        }
开发者ID:ericstj,项目名称:cli,代码行数:29,代码来源:GivenACompositeCommandResolver.cs

示例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();
		}
开发者ID:niemyjski,项目名称:elasticsearch-net,代码行数:28,代码来源:Responses.doc.cs

示例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);
            }
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:27,代码来源:JsonReaderTests.cs

示例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);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:32,代码来源:ValidationRuleSetTests.cs

示例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();
        }
开发者ID:Microsoft,项目名称:RTVS,代码行数:7,代码来源:RCompletionSourceTest.cs

示例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});

        }
开发者ID:ericstj,项目名称:cli,代码行数:29,代码来源:GivenACompositeCommandResolver.cs

示例15: RCompletionSource_CommentsTest01

        public void RCompletionSource_CommentsTest01() {
            List<CompletionSet> completionSets = new List<CompletionSet>();
            GetCompletions("#No", 3, completionSets);

            completionSets.Should().ContainSingle()
                .Which.Completions.Should().BeEmpty();
        }
开发者ID:AlexanderSher,项目名称:RTVS-Old,代码行数:7,代码来源:RCompletionSourceTest.cs


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