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


C# List.Join方法代码示例

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


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

示例1: JoinTest

 public void JoinTest()
 {
     var data = new List<String>() { "A", "B", "C", "D", "E" };
       var expected = "A, B, C, D, E";
       var actual = data.Join(", ");
       Assert.AreEqual(expected, actual);
 }
开发者ID:ctimmons,项目名称:cs_utilities,代码行数:7,代码来源:IEnumerable.cs

示例2: Join

        public void Join()
        {
            var emptyList = new List<string>();
            var oneItemList = new List<string> { "One" };
            var twoItemList = new List<string> { "One", "Two" };

            Assert.That(emptyList.Join(","), Is.EqualTo(String.Empty));
            Assert.That(oneItemList.Join(","), Is.EqualTo("One"));
            Assert.That(twoItemList.Join(","), Is.EqualTo("One,Two"));
        }
开发者ID:shawnewallace,项目名称:GiveCamp2011,代码行数:10,代码来源:EnumerableExtensionTests.cs

示例3: join

 public void join()
 {
     var list = new List<string>(new[] {"a", "b", "c"});
     list.Join(", ").ShouldEqual("a, b, c");
 }
开发者ID:bobpace,项目名称:fubucore,代码行数:5,代码来源:GenericEnumerableExtensionsTester.cs

示例4: Join_IgnoresNullElements

 public void Join_IgnoresNullElements()
 {
     var listWithNull = new List<string> { "One", null, "Two" };
     Assert.That(listWithNull.Join(","), Is.EqualTo("One,Two"));
 }
开发者ID:shawnewallace,项目名称:GiveCamp2011,代码行数:5,代码来源:EnumerableExtensionTests.cs

示例5: LIVE_STRESS_TEST_multiple_producers_multiple_queues_one_consumer_per_queue

 public void LIVE_STRESS_TEST_multiple_producers_multiple_queues_one_consumer_per_queue()
 {
     var messagesPerProducer = 100;
     var producerCount = 1;
     var client = CreateLiveClient();
     var queues = new List<string>();
     foreach(var x in new[] { "a", "b", "c", "d" }) {
         var queue = "test-" + x + "-" + StringUtil.CreateAlphaNumericKey(4);
         client.CreateQueue(queue, new Result<AwsSqsResponse>()).Wait();
         queues.Add(queue);
     }
     try {
         var producers = new List<Result<List<string>>>();
         for(var i = 0; i < producerCount; i++) {
             var producer = i;
             producers.Add(Async.Fork(() => {
                 _log.DebugFormat("producer {0} started", producer);
                 var c = CreateLiveClient();
                 var msgs = new List<string>();
                 for(var j = 0; j < messagesPerProducer; j++) {
                     var msg = StringUtil.CreateAlphaNumericKey(1024);
                     foreach(var queue in queues) {
                         c.Send(queue, AwsSqsMessage.FromBody(msg), new Result<AwsSqsSendResponse>()).Wait();
                     }
                     msgs.Add(msg);
                     if(msgs.Count % 10 == 0) {
                         _log.DebugFormat("producer {0} sent {1}/{2} msgs", producer, msgs.Count, messagesPerProducer);
                     }
                 }
                 _log.DebugFormat("producer {0} finished", producer);
                 return msgs;
             }, new Result<List<string>>()));
         }
         var consumers = queues.ToDictionary(queue => queue, queue => Async.Fork(() => {
             _log.DebugFormat("consumer {0} started", queue);
             var c = CreateLiveClient();
             var msgs = new List<string>();
             var expected = messagesPerProducer * producerCount;
             var lastReport = 0;
             while(msgs.Count < expected) {
                 var received = c.ReceiveMax(queue, new Result<IEnumerable<AwsSqsMessage>>()).Wait();
                 var count = 0;
                 foreach(var msg in received) {
                     count++;
                     msgs.Add(msg.Body);
                     c.Delete(msg, new Result<AwsSqsResponse>()).Wait();
                 }
                 if(count > 0 && msgs.Count > lastReport + 10) {
                     _log.DebugFormat("consumer '{0}' received: {1}/{2}", queue, msgs.Count, expected);
                     lastReport = msgs.Count;
                 }
             }
             return msgs;
         }, new Result<List<string>>()));
         producers.Join(new Result()).Wait();
         consumers.Values.Join(new Result()).Wait();
         var allMessages = producers.SelectMany(x => x.Value).OrderBy(x => x).ToArray();
         foreach(var consumed in consumers) {
             var queue = consumed.Key;
             var messages = consumed.Value.Value.OrderBy(x => x).ToArray();
             Assert.AreEqual(allMessages, messages, string.Format("message list for queue '{0}' is wrong", queue));
         }
     } finally {
         foreach(var queue in queues) {
             _log.DebugFormat("cleaning up queue '{0}'", queue);
             client.DeleteQueue(queue, new Result<AwsSqsResponse>()).Wait();
         }
     }
 }
开发者ID:danice,项目名称:DReAM,代码行数:69,代码来源:AwsSqsClientTests.cs

示例6: Produce

 public Result<Production> Produce(int messages)
 {
     var production = new Production();
     var final = new Result<Production>();
     Async.Fork(() => {
         try {
             _log.DebugFormat("{0}: Producing {1} messages", production.Id, messages);
             var responses = new List<Result<string>>();
             var client = new AwsSqsClient(_clientConfig);
             for(var i = 0; i < messages; i++) {
                 var result = new Result<string>();
                 responses.Add(result);
                 var msg = production.Id + ":" + messages;
                 client.Send(_queue, AwsSqsMessage.FromBody(msg), new Result<AwsSqsSendResponse>()).WhenDone(r => {
                     if(r.HasException) {
                         result.Throw(r.Exception);
                         return;
                     }
                     result.Return(msg);
                 });
             }
             responses.Join(new Result()).WhenDone(r => {
                 if(r.HasException) {
                     final.Throw(r.Exception);
                     return;
                 }
                 production.Stopwatch.Stop();
                 production.Sent.AddRange(responses.Select(x => x.Value));
                 _log.DebugFormat("{0}: Sent {1} messages in {2:0.00}s @ {3:0.00}msg/sec",
                     production.Id,
                     production.Sent.Count,
                     production.Stopwatch.Elapsed.TotalSeconds,
                     production.Sent.Count / production.Stopwatch.Elapsed.TotalSeconds
                 );
                 final.Return(production);
             });
         } catch(Exception e) {
             final.Throw(e);
         }
     });
     return final;
 }
开发者ID:danice,项目名称:DReAM,代码行数:42,代码来源:AwsSqsClientTests.cs

示例7: LIVE_STRESSTEST_Produce_Consume

 public void LIVE_STRESSTEST_Produce_Consume()
 {
     var client = CreateLiveClient();
     var queue = "test-" + StringUtil.CreateAlphaNumericKey(8);
     client.CreateQueue(queue, new Result<AwsSqsResponse>()).Wait();
     try {
         var n = 100;
         var productions = new List<Result<Production>>();
         var producer = new Producer(queue, GetConfig());
         for(var i = 0; i < 4; i++) {
             productions.Add(producer.Produce(n));
         }
         productions.Join(new Result()).Wait();
         var totalMessages = productions.Count * n;
         var consumers = new List<Consumer>();
         for(var i = 0; i < 10; i++) {
             var consumer = new Consumer(queue, CreateLiveClient());
             consumer.Consume();
             consumers.Add(consumer);
         }
         Assert.IsTrue(
             Wait.For(() => consumers.Sum(x => x.Received) == totalMessages, (totalMessages * 0.2).Seconds()),
             string.Format("got {0} instead of the expected {1} messages", consumers.Sum(x => x.Received), totalMessages)
         );
     } finally {
         _log.DebugFormat("cleaning up queue '{0}'", queue);
         client.DeleteQueue(queue, new Result<AwsSqsResponse>()).Wait();
     }
 }
开发者ID:danice,项目名称:DReAM,代码行数:29,代码来源:AwsSqsClientTests.cs

示例8: WaitForEmailsToBeSent

 public void WaitForEmailsToBeSent(List<string> recipients, int waitFor = 5)
 {
     WaitForEmailsWithCondition(waitFor,
                                messages => recipients.Join(messages, x => x, y => y.To.First().Address, (x, y) => x)
                                .Count() == recipients.Count());
 }
开发者ID:mamluka,项目名称:SpeedyMailer,代码行数:6,代码来源:IntegrationEmailHelpers.cs

示例9: CodegenAllServicesTest

        private void CodegenAllServicesTest(string language)
        {
            // Discover discovery.
            IService discovery = DiscoverDiscovery();

            // Generate discovery.
            Assembly discoveryAssembly = CodegenDiscovery(discovery);

            // Call the .List method.
            API[] apis = DiscoveryListServices(discoveryAssembly);

            // Run the generator.
            List<Exception> exceptions = new List<Exception>();
            List<string> failedAPIs = new List<string>();
            foreach (API api in apis)
            {
                try
                {
                    Assert.NotNull(TestService(language, api));
                }
                catch (Exception e)
                {
                    // Catch all exceptions, and throw them together.
                    failedAPIs.Add(api.Name);
                    exceptions.Add(e);
                }
            }

            // Create the error message.
            if (exceptions.Count > 0)
            {
                var message = new StringBuilder();
                message.AppendLine(
                    string.Format("Failed to generate {0} out of {1} APIs:", failedAPIs.Count, apis.Length));
                message.AppendLine(String.Join(", ", failedAPIs.ToArray()));
                message.AppendLine();

                int i = 0;
                int j = 0;
                var msgs = failedAPIs.Join(
                    exceptions, str => i++, ex => j++, (str, ex) => new { API = str, Exception = ex });
                foreach (var entries in msgs)
                {
                    message.AppendLine(string.Format("API '{0}' failed with:", entries.API));
                    message.AppendLine(string.Format("   {0}", entries.Exception));
                }

                Assert.Fail(message.ToString());
            }
        }
开发者ID:jithuin,项目名称:infogeezer,代码行数:50,代码来源:SystemTest.cs

示例10: JoinWithComparerQueryReuse

        public void JoinWithComparerQueryReuse()
        {
            List<int> first = new List<int> { 1, 2 };
            List<int> second = new List<int> { 4, 5 };
            IEnumerable<string> enumerable = first.Join(second, x => x % 2 == 0, x => x % 2 == 0, (x, y) => String.Format("{0}:{1}", x, y), EqualityComparer<bool>.Default);

            enumerable.AssertEqual("1:5", "2:4");

            first.Add(3);
            second.Add(6);
            enumerable.AssertEqual("1:5", "2:4", "2:6", "3:5");
        }
开发者ID:barisertekin,项目名称:LINQlone,代码行数:12,代码来源:JoinTests.cs

示例11: Join

 public void Join()
 {
     var list = new List<string>() { "first", "second", "third" };
     var joined = list.Join(",");
     Assert.That(joined, Has.Length.EqualTo(18), "Incorrect length.");
 }
开发者ID:tbashore,项目名称:TLib.NET,代码行数:6,代码来源:ListTests.cs


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