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


C# List.Count方法代码示例

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


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

示例1: LocateNeighbours

        public void LocateNeighbours()
        {
            var db = new LocalityQueryProximityDatabase<object>(Vector3.Zero, new Vector3(10, 10, 10), new Vector3(2, 2, 2));

            Dictionary<object, Vector3> positionLookup = new Dictionary<object, Vector3>();

            var xyz000 = CreateToken(db, new Vector3(0, 0, 0), positionLookup);
            var xyz100 = CreateToken(db, new Vector3(1, 0, 0), positionLookup);
            CreateToken(db, new Vector3(3, 0, 0), positionLookup);

            var list = new List<object>();
            xyz000.FindNeighbors(Vector3.Zero, 2, list);

            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(1, list.Count(a => positionLookup[a] == new Vector3(0, 0, 0)));
            Assert.AreEqual(1, list.Count(a => positionLookup[a] == new Vector3(1, 0, 0)));

            //Check tokens handle being disposed twice
            xyz000.Dispose();
            xyz000.Dispose();

            list.Clear();
            xyz100.FindNeighbors(Vector3.Zero, 1.5f, list);

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(new Vector3(1, 0, 0), positionLookup[list[0]]);
        }
开发者ID:cupsster,项目名称:SharpSteer2,代码行数:27,代码来源:LocalityQueryProximityDatabaseTest.cs

示例2: TestMaxItemCount

        public async Task TestMaxItemCount()
        {
            var nextItem = 0;
            var pool = new PipelinedPool<int>(() => TaskPort.FromResult(++nextItem), null, new PipelinedPoolOptions
            {
                MaxRequestsPerItem = 10,
                TargetItemCount = 2,
            });

            var items = new List<IPooledItem<int>>();
            for (int i = 0; i < 20; ++i)
            {
                var task = pool.Borrow();
                Assert.AreEqual(true, task.IsCompleted);
                var item = await task;
                items.Add(item);
            }
            Assert.AreEqual(20, items.Count);
            Assert.AreEqual(10, items.Count(v => v.Item == 1));
            Assert.AreEqual(10, items.Count(v => v.Item == 2));

            var waiter = pool.Borrow();
            Assert.AreEqual(false, waiter.IsCompleted);

            items.First().Dispose();
            Assert.AreEqual(true, waiter.IsCompleted);
            foreach (var item in items.Skip(1))
            {
                item.Dispose();
            }
            waiter.Result.Dispose();
        }
开发者ID:JeffreySu,项目名称:MemcachedSharp,代码行数:32,代码来源:PipelinedPoolTest.cs

示例3: GetRandomGenderTest

 public void GetRandomGenderTest() 
 {
     var maxTests = 1000000;
     var genders = new List<string>();
     for (var i = 0; i < maxTests; i++) {
         genders.Add(RandomInfoGenerator.GetRandomGender(i));
     }
     var malesCount = genders.Count(s=> s == "Male");
     Assert.IsTrue(malesCount < genders.Count());
 }
开发者ID:wgoodq,项目名称:DataTable.Demos,代码行数:10,代码来源:ServicesTests.cs

示例4: ForEachTest

 public void ForEachTest()
 {
     int N = 10;
     List<A> items = new List<A>(N);
     for (int i = 0; i < N; ++i)
         items.Add(new A());
     Assert.AreEqual(0, items.Count(a => a.Visited));
     items.ForEach(a => a.Visit());
     Assert.AreEqual(N, items.Count(a => a.Visited));
 }
开发者ID:wtain,项目名称:FinCalc,代码行数:10,代码来源:IEnumerableExtensionsTests.cs

示例5: TestLogEntries

        private void TestLogEntries(List<LogEntry> expectedLogEntries, List<LogEntry> actualLogEntries)
        {
            Assert.AreEqual(expectedLogEntries.Count(), actualLogEntries.Count(), "Log counts not equal");

            for (int i = 0; i < expectedLogEntries.Count(); i++)
            {
                Assert.AreEqual(expectedLogEntries.ElementAt(i).Message, actualLogEntries.ElementAt(i).Message);
                Assert.AreEqual(expectedLogEntries.ElementAt(i).LoggerName, actualLogEntries.ElementAt(i).LoggerName);
                Assert.AreEqual(expectedLogEntries.ElementAt(i).Level, actualLogEntries.ElementAt(i).Level);
            }
        }
开发者ID:jltrem,项目名称:jsnlog,代码行数:11,代码来源:LoggerProcessorTests.Http.Infrastructure.cs

示例6: ViewModel_Observed

        public void ViewModel_Observed()
        {
            var propertyNames = new List<string>();
            var vm = new MyViewModel();
            vm.PropertyChanged += (sender, args) => propertyNames.Add(args.PropertyName);
            vm.ViewModelProperty = new MyViewModel { StringProperty = "inner vm" };

            Assert.AreEqual(1, propertyNames.Count(s => s == "ViewModelProperty"));
            Assert.AreEqual(0, propertyNames.Count(s => s == "StringProperty"));

            vm.ViewModelProperty.StringProperty = "new value";
            Assert.AreEqual(2, propertyNames.Count(s => s == "ViewModelProperty"));
            Assert.AreEqual(0, propertyNames.Count(s => s == "StringProperty"));
        }
开发者ID:heinersuter,项目名称:simple-ui-tests,代码行数:14,代码来源:ViewModelTest.cs

示例7: LoadAdaptersNameTooLongAsyncTest

        public async Task LoadAdaptersNameTooLongAsyncTest()
        {
            //Arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "am-LoadAdaptersNameTooLongAsyncTest" };
            Database.SetInitializer(new CreateFreshDbInitializer());

            var logEntries = new List<LogEntry>();
            var log = new StubIFeedback<LogEntry>
            {
                ReportAsyncT0CancellationToken = (e, c) =>
                {
                    Console.WriteLine(e.ToString());
                    logEntries.Add(e);
                    return Task.FromResult(0);
                }
            };

            var longNameAdapter = new StubZvsAdapter
            {
                AdapterGuidGet = () => Guid.Parse("a0f912a6-b8bb-406a-360f-1eb13f50aae4"),
                NameGet = () => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque magna diam, pellentesque et orci eget, pellentesque iaculis odio. Ut ultrices est sapien, ac pellentesque odio malesuada a. Etiam in neque ullamcorper massa gravida ullamcorper vel a posuere.",
                DescriptionGet = () => "",
                OnSettingsCreatingAdapterSettingBuilder = (s) => Task.FromResult(0),
                OnDeviceTypesCreatingDeviceTypeBuilder = (s) => Task.FromResult(0)
            };

            var adapterManager = new AdapterManager(new List<ZvsAdapter>() { longNameAdapter }, dbConnection, log);
            //act
            await adapterManager.StartAsync(CancellationToken.None);

            //assert 
            Assert.IsTrue(logEntries.Count(o => o.Level == LogEntryLevel.Error) == 1, "Expected 1 error");
        }
开发者ID:m19brandon,项目名称:zVirtualScenes,代码行数:33,代码来源:AdapterManagerTests.cs

示例8: ReturnOnlyLocationsWithGravityLessThan105PercentOfStandard

        public void ReturnOnlyLocationsWithGravityLessThan105PercentOfStandard()
        {
            var mocks = new Rhino.Mocks.MockRepository();
            var db = (null as ILocationRepository).Create(mocks);

            int locationCount = 100.GetRandom(50);
            var allLocations = new List<Location>();
            for (int i = 0; i < locationCount; i++)
                allLocations.Add((null as Location).Create());

            TestContext.WriteLine("{0} locations in data store", allLocations.Count());

            Rhino.Mocks
                .Expect.Call(db.GetLocations())
                .Repeat.Any()
                .Return(allLocations);

            mocks.ReplayAll();

            var target = new Engine(db);
            var actual = target.Scout();
            TestContext.WriteLine("{0} locations returned from target", actual.Count());

            foreach (var location in actual)
                Assert.IsTrue(location.Gravity < 1.05);

            mocks.VerifyAll();
        }
开发者ID:bsstahl,项目名称:OneOffTestDemos,代码行数:28,代码来源:Engine_Scout_Should.cs

示例9: REPORT_FAILURE

 public void REPORT_FAILURE(string greekName, Average.Type averageType,
     double runningAccumulator, int pastFixings,
     List<Date> fixingDates, StrikedTypePayoff payoff,
     Exercise exercise, double s, double q, double r,
     Date today, double v, double expected,
     double calculated, double tolerance)
 {
     Assert.Fail(exercise + " "
     + exercise
     + " Asian option with "
     + averageType + " and "
     + payoff + " payoff:\n"
     + "    running variable: "
     + runningAccumulator + "\n"
     + "    past fixings:     "
     + pastFixings + "\n"
     + "    future fixings:   " + fixingDates.Count() + "\n"
     + "    underlying value: " + s + "\n"
     + "    strike:           " + payoff.strike() + "\n"
     + "    dividend yield:   " + q + "\n"
     + "    risk-free rate:   " + r + "\n"
     + "    reference date:   " + today + "\n"
     + "    maturity:         " + exercise.lastDate() + "\n"
     + "    volatility:       " + v + "\n\n"
     + "    expected   " + greekName + ": " + expected + "\n"
     + "    calculated " + greekName + ": " + calculated + "\n"
     + "    error:            " + Math.Abs(expected - calculated)
     + "\n"
     + "    tolerance:        " + tolerance);
 }
开发者ID:StreetConnect,项目名称:QLNet,代码行数:30,代码来源:T_AsianOptions.cs

示例10: hasSameNumberOfStations

 public void hasSameNumberOfStations()
 {
     ciudades = new List<string>();
     ciudades.Add(final[3]);
     for (int i = 3; i < final.Length;i++)
     {
         bool exists = false;
         if ((i + 8) < final.Length)
         {
             i = i + 7;
         }
         else
         {
             continue;
         }
         for (int j = 0; j < ciudades.Count(); j++)
             {
                 if (final[i].Equals(ciudades.ElementAt(j)))
                 {
                     exists = true;
                 }
         }
         if (!exists)
         {
             ciudades.Add(final[i]);
         }
         i--;
     }
     Assert.AreEqual(13,ciudades.Count);
 }
开发者ID:javmonisu,项目名称:PoliCyL,代码行数:30,代码来源:BackgroundActivityTest.cs

示例11: Should_get_types_except_for_stop_point

 public void Should_get_types_except_for_stop_point()
 {
     var typeNames = new List<string>();
     var visitor = GetRelayVisiterForTypes(typeNames);
     visitor.GoUntil(typeof(ObservableCollection<>), () => typeNames.Count == 5);
     Assert.AreEqual(5, typeNames.Count());
 }
开发者ID:GeniusCode,项目名称:GeniusCode.Components.RelayVisitor,代码行数:7,代码来源:RecursiveWalkerTest.cs

示例12: All_Text_Is_Removed_And_Readded_When_Replace_Option_Selected

        public async Task All_Text_Is_Removed_And_Readded_When_Replace_Option_Selected()
        {
            // Assort
            var store = new List<ForwardTextCandidate>(from x in InputTextItems.Take(2) select new ForwardTextCandidate { Text = x });
            var repository = CreateFakeRepository(store);

            var svc = new Mock<CsvFileTextService<ForwardTextCandidate>>();
            svc.Setup(x => x.Import(It.IsAny<string>(), MergeWithExistingRecordsPolicy.Replace, repository.Object, NullEntityCreator, NullEntityLocator, NullEntityUpdater))
                .Callback<string, MergeWithExistingRecordsPolicy, IBaseRepository<ForwardTextCandidate>, Func<string, ForwardTextCandidate>, Func<ForwardTextCandidate, string, bool>, Action<ForwardTextCandidate, string>>
                ((path, opc, rep, creator, locator, updater) =>
                {
                    rep.Get().ToList().ForEach(x => rep.Delete(x));
                    InputTextItems.ToList().ForEach(x => rep.Save(new ForwardTextCandidate { Text = x }));
                })
                .Returns(Task.FromResult<ImportTextResult>(new ImportTextResult { Success = true, InsertedRecords = InputTextItems.Length }));

            // Act
            var result = await svc.Object.Import(string.Empty, MergeWithExistingRecordsPolicy.Replace, repository.Object, NullEntityCreator, NullEntityLocator, NullEntityUpdater);

            // Assert
            Assert.IsTrue(result.Success);
            Assert.AreEqual(InputTextItems.Length, store.Count());

            var index = 0;
            store.ForEach(x => Assert.AreEqual(x.Text, InputTextItems[index++]));

            repository.Verify(x => x.Create(It.IsAny<ForwardTextCandidate>()), Times.Exactly(3));
        }
开发者ID:c0d3m0nky,项目名称:mty,代码行数:28,代码来源:CsvFileTextServiceTests.cs

示例13: All_Provided_Text_Is_Added_When_The_Append_Option_Is_Selected

        public async Task All_Provided_Text_Is_Added_When_The_Append_Option_Is_Selected()
        {
            // Assort
            var store = new List<ForwardTextCandidate>();
            var repository = new MockRepository(MockBehavior.Default).Create<Repository<ForwardTextCandidate>>(new Mock<ISession>().Object);
            repository.Setup(x => x.Get()).Returns(store.AsQueryable());
            repository.Setup(x => x.Save(It.IsAny<IQueryable<ForwardTextCandidate>>())).Callback<IQueryable<ForwardTextCandidate>>(items => store.AddRange(items));

            var svc = new Mock<CsvFileTextService<ForwardTextCandidate>>();
            svc.Setup(x => x.Import(It.IsAny<string>(), MergeWithExistingRecordsPolicy.Append, repository.Object, NullEntityCreator, NullEntityLocator, NullEntityUpdater))
                .Callback<string, MergeWithExistingRecordsPolicy, IBaseRepository<ForwardTextCandidate>,  Func<string, ForwardTextCandidate>, Func<ForwardTextCandidate, string, bool>, Action<ForwardTextCandidate, string>>
                ((path, opc, rep, creator, locator, updater) =>
                {
                    var itemsToAdd = new List<ForwardTextCandidate>();
                    InputTextItems.ToList().ForEach(x => itemsToAdd.Add(new ForwardTextCandidate { Text = x }));
                    rep.Save(itemsToAdd.AsQueryable());
                })
                .Returns(Task.FromResult<ImportTextResult>(new ImportTextResult { Success = true, InsertedRecords = InputTextItems.Length }));
            
            // Act
            var result = await svc.Object.Import(string.Empty, MergeWithExistingRecordsPolicy.Append, repository.Object, NullEntityCreator, NullEntityLocator, NullEntityUpdater);

            // Assert
            Assert.IsTrue(result.Success);
            Assert.AreEqual(InputTextItems.Length, store.Count());

            var index = 0;
            store.ForEach(x => Assert.AreEqual(x.Text, InputTextItems[index++]));
        }
开发者ID:c0d3m0nky,项目名称:mty,代码行数:29,代码来源:CsvFileTextServiceTests.cs

示例14: RuleSetOnlyNotifiesWhenStrictlyNeccessary

        public void RuleSetOnlyNotifiesWhenStrictlyNeccessary()
        {
            var changedprops = new List<string>();
            var persister = new XmlPersister( new RuleSetXmlSerializer(), new StreamFactory( "data.xml" ), 2000 );
            var rs = persister.RecreateRuleSet();
            rs.PropertyChanged += ( s, e ) => changedprops.Add( e.PropertyName );

            var controller = new AlchemyController( rs );

            var rule = controller.RecommendNewRule();
            rule.Result = new[] { new Element( "alpha" ) };
            controller.ReportChangedRule( rule );

            Assert.AreEqual( 1, changedprops.Count( p => p.Equals( "FoundElements" ) ) );
            Assert.AreEqual( 1, changedprops.Count( p => p.Equals( "Rules" ) ) );
        }
开发者ID:Zazcallabah,项目名称:Alchemist,代码行数:16,代码来源:NotificationTests.cs

示例15: CanParseMultiTabledDeps2

        public void CanParseMultiTabledDeps2()
        {
            //arrange
            var query = "SELECT players.id,players.homeworld_id,orbital_objects.star_system_id,(SELECT foo from bar) FROM players,second" +
                        "\n,"+
                        "\nthird" +
                        "\n  , fourth ,fifth"+
                        "\nJOIN colonies ON colonies.orbital_object_id = players.homeworld_id AND colonies.player_id={0}" +
                        "\nJOIN orbital_objects ON orbital_objects.id = colonies.orbital_object_id" +
                        "\nWHERE homeworld_id NOT NULL";

            var expected = new List<string>(){
                "colonies",
                "players",
                "orbital_objects",
                "second",
                "third",
                "fourth",
                "fifth",
                "bar"
            };

            //act

            var result = SQLParser.ExtractTableDependencies(query);

            //assert
            Assert.IsTrue(!expected.Any(e => !result.Contains(e)));

            Assert.AreEqual(expected.Count(), result.Count());
        }
开发者ID:nugarin,项目名称:sotsos,代码行数:31,代码来源:SQLParserTests.cs


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