本文整理汇总了C#中NUnit.Framework.List.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# List.CopyTo方法的具体用法?C# List.CopyTo怎么用?C# List.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NUnit.Framework.List
的用法示例。
在下文中一共展示了List.CopyTo方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetUp
public void SetUp()
{
_scheduler = new ManualTaskScheduler();
_entries = new List<LogLine>();
_logFile = new Mock<ILogFile>();
_logFile.Setup(x => x.GetSection(It.IsAny<LogFileSection>(), It.IsAny<LogLine[]>()))
.Callback(
(LogFileSection section, LogLine[] entries) =>
_entries.CopyTo((int)section.Index, entries, 0, section.Count));
_logFile.Setup(x => x.AddListener(It.IsAny<ILogFileListener>(), It.IsAny<TimeSpan>(), It.IsAny<int>()))
.Callback((ILogFileListener listener, TimeSpan unused, int max) =>
{
for (int i = 0; i < _entries.Count/max+1; ++i)
{
int from = i*max;
int to = Math.Min((i + 1)*max, _entries.Count);
listener.OnLogFileModified(_logFile.Object, new LogFileSection(from, to - from));
}
});
_logFile.Setup(x => x.GetLine(It.IsAny<int>())).Returns((int index) => _entries[index]);
_logFile.Setup(x => x.Count).Returns(() => _entries.Count);
_logFile.Setup(x => x.EndOfSourceReached).Returns(true);
_matches = new List<LogMatch>();
_listener = new Mock<ILogFileSearchListener>();
_listener.Setup(x => x.OnSearchModified(It.IsAny<ILogFileSearch>(), It.IsAny<List<LogMatch>>()))
.Callback((ILogFileSearch sender, IEnumerable<LogMatch> matches) =>
{
_matches.Clear();
_matches.AddRange(matches);
});
}
示例2: SetUp
public void SetUp()
{
_control = new LogEntryListView
{
Width = 1024,
Height = 768
};
var availableSize = new Size(1024, 768);
_control.Measure(availableSize);
_control.Arrange(new Rect(new Point(), availableSize));
DispatcherExtensions.ExecuteAllEvents();
_lines = new List<LogLine>();
_listeners = new List<ILogFileListener>();
_logFile = new Mock<ILogFile>();
_logFile.Setup(x => x.Count).Returns(() => _lines.Count);
_logFile.Setup(x => x.GetSection(It.IsAny<LogFileSection>(), It.IsAny<LogLine[]>()))
.Callback((LogFileSection section, LogLine[] dest) =>
_lines.CopyTo((int) section.Index, dest, 0, section.Count));
_logFile.Setup(x => x.GetLine(It.IsAny<int>())).Returns((int index) =>
_lines[index]);
_logFile.Setup(x => x.AddListener(It.IsAny<ILogFileListener>(), It.IsAny<TimeSpan>(), It.IsAny<int>()))
.Callback((ILogFileListener listener, TimeSpan maximumTimeout, int maximumLines) =>
{
_listeners.Add(listener);
listener.OnLogFileModified(_logFile.Object,
new LogFileSection(0, _lines.Count));
});
}
示例3: CopyTo_CopiesToNewObject
public void CopyTo_CopiesToNewObject()
{
List<int> original = new List<int> { 1 };
original.CopyTo<List<int>>()
.ShouldNotReferTo(original)
.And.ShouldMatch(new[] { 1 });
}
示例4: ShouldGetLastFiveReleases
public void ShouldGetLastFiveReleases()
{
//given
var releaseRepository = new ReleaseRepository();
var expectedReleaseDetailsModels = new List<Release>
{
new ReleaseBuilder().WithReleaseNumber("REL05").WithReleaseDate(DateTime.Today.AddDays(-1)).Build(),
new ReleaseBuilder().WithReleaseNumber("REL04").WithReleaseDate(DateTime.Today.AddMonths(-1)).Build(),
new ReleaseBuilder().WithReleaseNumber("REL03").WithReleaseDate(DateTime.Today.AddMonths(-1)).Build(),
new ReleaseBuilder().WithReleaseNumber("REL02").WithReleaseDate(DateTime.Today.AddMonths(-2).AddDays(2)).Build(),
new ReleaseBuilder().WithReleaseNumber("REL01").WithReleaseDate(DateTime.Today.AddMonths(-2)).Build()
};
var lastfiveReleases = new Release[expectedReleaseDetailsModels.Count];
expectedReleaseDetailsModels.CopyTo(lastfiveReleases);
expectedReleaseDetailsModels.Add(new ReleaseBuilder().WithReleaseNumber("REL06").WithReleaseDate(DateTime.Today.AddMonths(-3).AddDays(-1)).Build());
//when
foreach (Release expectedReleaseDetailsModel in expectedReleaseDetailsModels)
{
releaseRepository.SaveReleaseDetails(expectedReleaseDetailsModel);
}
// then
IEnumerable<Release> releaseDetailsModels = releaseRepository.GetLastFiveReleases();
IEnumerable<Release> expectedReleases = lastfiveReleases.ToList();
Assert.That(releaseDetailsModels, Is.EqualTo(expectedReleases));
}
示例5: MainTest
public void MainTest()
{
string curDir = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(TestUtility.TempDir);
if (Directory.Exists(TestUtility.TempDir + @"NewDir"))
Directory.Delete(TestUtility.TempDir + @"NewDir", true);
List<string> al = new List<string>();
al.Add(@"-bf:TestTool.xml");
al.Add(@"-bc:JavaApp;TestLibrary");
al.Add(@"-prop:OutputDir=C:\Temp\NewDir");
al.Add(@"-log:xml");
string[] args = new string[al.Count];
al.CopyTo(args, 0);
Program.Main(args);
Assert.IsTrue(Directory.Exists(TestUtility.TempDir + @"NewDir"));
Assert.IsTrue(File.Exists(TestUtility.TempDir + @"NewDir\JavaApp.class"));
Assert.IsTrue(File.Exists(TestUtility.TempDir + @"NewDir\TestLibrary.dll"));
Assert.IsTrue(File.Exists(TestUtility.TempDir + @"TestTool.log.xml"));
DateTime dateModTestLibrary = File.GetLastWriteTime(TestUtility.TempDir + @"NewDir\TestLibrary.dll");
DateTime dateModJavaApp = File.GetLastWriteTime(TestUtility.TempDir + @"NewDir\JavaApp.class");
al.Add(@"-rebuild:JavaApp");
args = new string[al.Count];
al.CopyTo(args, 0);
Program.Main(args);
Assert.AreEqual(dateModTestLibrary, File.GetLastWriteTime(TestUtility.TempDir + @"NewDir\TestLibrary.dll"));
Assert.AreNotEqual(dateModJavaApp, File.GetLastWriteTime(TestUtility.TempDir + @"NewDir\JavaApp.class"));
// cleanup
if (Directory.Exists(TestUtility.TempDir + @"NewDir"))
Directory.Delete(TestUtility.TempDir + @"NewDir", true);
File.Delete(TestUtility.TempDir + @"TestTool.log.xml");
Directory.SetCurrentDirectory(curDir);
}
示例6: Setup
public void Setup()
{
_entries = new List<LogLine>();
_logFile = new Mock<ILogFile>();
_listeners = new LogFileListenerCollection(_logFile.Object);
_logFile.Setup(x => x.EndOfSourceReached).Returns(true);
_logFile.Setup(x => x.GetSection(It.IsAny<LogFileSection>(), It.IsAny<LogLine[]>()))
.Callback(
(LogFileSection section, LogLine[] entries) =>
_entries.CopyTo((int)section.Index, entries, 0, section.Count));
_logFile.Setup(x => x.AddListener(It.IsAny<ILogFileListener>(), It.IsAny<TimeSpan>(), It.IsAny<int>()))
.Callback((ILogFileListener listener, TimeSpan maximumWaitTime, int maximumLineCount) => _listeners.AddListener(listener, maximumWaitTime, maximumLineCount));
_logFile.Setup(x => x.RemoveListener(It.IsAny<ILogFileListener>()))
.Callback((ILogFileListener listener) => _listeners.RemoveListener(listener));
_logFile.Setup(x => x.GetLine(It.IsAny<int>())).Returns((int index) => _entries[index]);
_logFile.Setup(x => x.Count).Returns(() => _entries.Count);
}
示例7: SetUp
public void SetUp()
{
_taskScheduler = new ManualTaskScheduler();
_entries = new List<LogLine>();
_logFile = new Mock<ILogFile>();
_logFile.Setup(x => x.GetSection(It.IsAny<LogFileSection>(), It.IsAny<LogLine[]>()))
.Callback(
(LogFileSection section, LogLine[] entries) =>
_entries.CopyTo((int) section.Index, entries, 0, section.Count));
_logFile.Setup(x => x.GetLine(It.IsAny<int>())).Returns((int index) => _entries[index]);
_logFile.Setup(x => x.Count).Returns(() => _entries.Count);
_logFile.Setup(x => x.EndOfSourceReached).Returns(true);
_sections = new List<LogFileSection>();
_listener = new Mock<ILogFileListener>();
_listener.Setup(x => x.OnLogFileModified(It.IsAny<ILogFile>(), It.IsAny<LogFileSection>()))
.Callback((ILogFile l, LogFileSection s) => _sections.Add(s));
}
示例8: CreateLogFile
private static Mock<ILogFile> CreateLogFile(List<LogLine> lines)
{
var source = new Mock<ILogFile>();
source.Setup(x => x.GetLine(It.IsAny<int>()))
.Returns((int index) => lines[index]);
source.Setup(x => x.GetSection(It.IsAny<LogFileSection>(), It.IsAny<LogLine[]>()))
.Callback((LogFileSection section, LogLine[] data) => lines.CopyTo((int) section.Index, data, 0, section.Count));
source.Setup(x => x.EndOfSourceReached).Returns(true);
return source;
}
示例9: TestCopyTo
public void TestCopyTo()
{
using (var map = new MemoryMapStream())
{
var list = new List<int>(map);
for (var i = 0; i < 10; i++)
{
list.Add(i);
}
var array = new int[20];
list.CopyTo(array, 0);
for (var i = 0; i < 10; i++)
{
Assert.AreEqual(i, array[i]);
}
list.CopyTo(array, 10);
for (var i = 10; i < 20; i++)
{
Assert.AreEqual(i - 10, array[i]);
}
}
}
示例10: Parallel_ForEach_Can_Be_Used_To_Put_And_Get_Objects
public void Parallel_ForEach_Can_Be_Used_To_Put_And_Get_Objects()
{
/* NB: this example assumes a 4-node devrel available
* with localhost PB ports at 10017, 10027, 10037 and 10047 */
const int numNodes = 4;
const int poolSize = 8;
const int totalConnectionCount = poolSize * numNodes;
const ushort portInterval = 10;
const ushort startingPort = 10017;
const ushort endingPort = startingPort + ((numNodes - 1) * portInterval);
const int totalObjects = 65536;
byte[] data = new byte[65536];
Random.NextBytes(data);
int batchSize = totalConnectionCount;
int totalBatches = totalObjects / batchSize;
Assert.AreEqual(0, totalObjects % batchSize);
Debug.WriteLine("batchSize: {0}, totalBatches: {1}", batchSize, totalBatches);
string riakHost = Environment.GetEnvironmentVariable("RIAK_HOST");
if (String.IsNullOrWhiteSpace(riakHost))
{
riakHost = "riak-test";
}
Debug.WriteLine("Riak host: {0}", riakHost);
Assert.AreEqual(10047, endingPort);
var objs = new List<RiakObject>();
for (int i = 0; i < totalObjects; i++)
{
var key = String.Format("{0}_{1}", TestKey, i);
var id = new RiakObjectId(TestBucket, key);
var obj = new RiakObject(id, data, RiakConstants.ContentTypes.ApplicationOctetStream, null);
objs.Add(obj);
}
IRiakClusterConfiguration clusterConfig = new RiakClusterConfiguration();
for (ushort port = startingPort; port <= endingPort; port += portInterval)
{
IRiakNodeConfiguration nc = new RiakNodeConfiguration();
nc.PoolSize = poolSize;
nc.HostAddress = riakHost;
nc.PbcPort = port;
nc.Name = String.Format("dev_{0}", port);
clusterConfig.AddNode(nc);
}
var batchObjs = new RiakObject[batchSize];
var p = new int[] { 1, batchSize };
foreach (int parallelism in p)
{
var parallelOptions = new ParallelOptions();
parallelOptions.MaxDegreeOfParallelism = parallelism;
using (var cluster = new RiakCluster(clusterConfig))
{
var client = cluster.CreateClient();
var sw = new Stopwatch();
sw.Start();
for (int i = 0; i < totalObjects; i += batchSize)
{
objs.CopyTo(i, batchObjs, 0, batchSize);
Parallel.ForEach(batchObjs, parallelOptions, (obj) =>
{
try
{
client.Put(obj);
}
catch (Exception e)
{
Debug.WriteLine("[ERROR] put exception: {0}", e.ToString());
}
});
}
sw.Stop();
Debug.WriteLine("parallelism: {0} - put {1} objects in {2}", parallelism, totalObjects, sw.Elapsed);
sw.Reset();
sw.Start();
for (int i = 0; i < totalObjects; i += batchSize)
{
objs.CopyTo(i, batchObjs, 0, batchSize);
Parallel.ForEach(batchObjs, parallelOptions, (obj) =>
{
try
{
var id = new RiakObjectId(obj.Bucket, obj.Key);
client.Get(id);
}
catch (Exception e)
{
//.........这里部分代码省略.........
示例11: HandleEmailProperties
private static void HandleEmailProperties(string messageSubject, string messageBody, string formattedMessageBody, string emailClient, Request request)
{
List<CustomProperty> propList = new List<CustomProperty>();
propList.Add(new CustomProperty(SMTPPropertyTags.Subject, messageSubject));
propList.Add(new CustomProperty(SMTPPropertyTags.Body, messageBody));
propList.Add(new CustomProperty(SMTPPropertyTags.FormattedBody, formattedMessageBody));
propList.Add(new CustomProperty(SMTPPropertyTags.FileHeader, string.Empty));
propList.Add(new CustomProperty(SMTPRoutingPropertyTags.RequestChannel, emailClient));
propList.Add(new CustomProperty(SMTPPropertyTags.xPriority, "2"));
request.Properties = new CustomProperty[propList.Count];
propList.CopyTo(request.Properties);
}
示例12: HandleEmailSender
private static void HandleEmailSender(Request request, string sender)
{
List<CustomProperty> propList = new List<CustomProperty>();
propList.Add(new CustomProperty(SMTPRoutingPropertyTags.DisplayName, sender));
propList.Add(new CustomProperty(SMTPRoutingItemPropertyKeys.AddressType, AddressType.From));
propList.Add(new CustomProperty(SMTPRoutingItemPropertyKeys.Internal, bool.TrueString));
RoutingItem senderItem = new RoutingItem();
senderItem.Content = sender;
senderItem.Properties = new CustomProperty[propList.Count];
propList.CopyTo(senderItem.Properties);
request.Source.Items = new RoutingItem[] { senderItem };
}
示例13: ShiftAlpha
private List<char> ShiftAlpha(string cipher)
{
var alpha = new List<char>(new char[26].Select((a, b) => (char)(b + 97)).ToArray());
var startIndex = alpha.IndexOf(Convert.ToChar(cipher));
var alphaNew = new char[alpha.Count];
alpha.CopyTo(alphaNew);
alpha.InsertRange(alpha.Count, alphaNew.Take(startIndex));
return alpha.Skip(startIndex).ToList();
}