本文整理汇总了C#中Generator.Take方法的典型用法代码示例。如果您正苦于以下问题:C# Generator.Take方法的具体用法?C# Generator.Take怎么用?C# Generator.Take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Generator
的用法示例。
在下文中一共展示了Generator.Take方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddAnyAmountOfNumbersReturnsCorrectResult
public void AddAnyAmountOfNumbersReturnsCorrectResult(Calculator sut, int count, Generator<int> generator)
{
var integers = generator.Take(count+2).ToArray();
var numbers = string.Join(",", integers);
var actual = sut.Add(numbers);
var expected = integers.Sum();
Assert.Equal(expected, actual);
}
示例2: SetNumbersDividedOnThreeReturnsCorrectResult
public void SetNumbersDividedOnThreeReturnsCorrectResult(FizzBuzz sut, int count, Generator<int> generator)
{
var numbers = generator.Take(count).Where(x => x % 3 == 0 && x % 5 != 0).ToArray();
var actual = numbers.Select(n => sut.Get(n)).ToList();
actual.ForEach(result => Assert.Equal("Fizz", result));
}
示例3: SetNumbersNotDividedOnFiveAndThreeReturnsCorrectResult
public void SetNumbersNotDividedOnFiveAndThreeReturnsCorrectResult(FizzBuzz sut, int count, Generator<int> generator)
{
var numbers = generator.Take(count).Where(x => x % 5 != 0 && x % 3 != 0).ToArray();
var actual = numbers.Select(n => sut.Get(n)).ToList();
var expected = numbers.Select(n => Convert.ToString(n));
Assert.Equal(expected, actual);
}
示例4: AddLineWithCustomDelimiterStringREturnsCorrectResult
public void AddLineWithCustomDelimiterStringREturnsCorrectResult(Calculator sut,
string delimiter,
int count,
Generator<int> intGenerator)
{
var integers = intGenerator.Take(count).ToArray();
var numbers = string.Format("//[{0}]\n{1}",
delimiter,
string.Join(delimiter, integers));
var expected = integers.Sum();
var actual = sut.Add(numbers);
Assert.Equal(expected, actual);
}
示例5: AddLineWithCustomDelimiterReturnsCorrrectResult
public void AddLineWithCustomDelimiterReturnsCorrrectResult(Calculator sut,
Generator<char> charGenerator,
Generator<int> intGenerator,
int count)
{
int dummy;
var delimiter = charGenerator.Where(c => !int.TryParse(c.ToString(), out dummy) &&
c != '-').First();
var integers = intGenerator.Take(count).ToArray();
var numbers = string.Format("//{0}\n{1}", delimiter, string.Join(delimiter.ToString(), integers));
var actual = sut.Add(numbers);
var expected = integers.Sum();
Assert.Equal(expected, actual);
}
示例6: SutSeemsToBeThreadSafe
public void SutSeemsToBeThreadSafe(
AtomEventsInMemory sut,
Generator<AtomFeedBuilder<DataContractTestEventX>> g,
Mock<ITypeResolver> resolverStub)
{
resolverStub
.Setup(r => r.Resolve("test-event-x", "http://grean.rocks/dc"))
.Returns(typeof(DataContractTestEventX));
var feeds = g.Take(500).Select(b => b.Build()).ToArray();
var tasks = feeds
.AsParallel()
.Select(f => Task.Factory.StartNew(() =>
{
using (var w = sut.CreateFeedWriterFor(f))
f.WriteTo(
w,
new DataContractContentSerializer(
resolverStub.Object));
}))
.ToArray();
var readFeeds = feeds
.AsParallel()
.Select(f => f.Locate())
.Select(uri =>
{
using (var r = sut.CreateFeedReaderFor(uri))
return AtomFeed.ReadFrom(
r,
new DataContractContentSerializer(
resolverStub.Object));
})
.ToArray();
Task.WaitAll(tasks);
Assert.Equal(feeds.Length, readFeeds.Length);
}
示例7: WriteToXmlWriterWritesCorrectXml
public void WriteToXmlWriterWritesCorrectXml(
AtomEntry entry,
Generator<AtomLink> linkGenerator,
DataContractTestEventX tex,
DataContractContentSerializer serializer)
{
// Fixture setup
var sb = new StringBuilder();
using (var w = XmlWriter.Create(sb))
{
var links = linkGenerator.Take(2).ToList();
var sut = entry
.WithContent(new XmlAtomContent(tex))
.WithLinks(links);
// Exercise system
sut.WriteTo(w, serializer);
// Verify outcome
w.Flush();
var expected = XDocument.Parse(
"<entry xmlns=\"http://www.w3.org/2005/Atom\">" +
" <id>" + sut.Id.ToString() + "</id>" +
" <title type=\"text\">" + sut.Title + "</title>" +
" <published>" + sut.Published.ToString("o") + "</published>" +
" <updated>" + sut.Updated.ToString("o") + "</updated>" +
" <author>" +
" <name>" + sut.Author.Name + "</name>" +
" </author>" +
" <link href=\"" + links[0].Href.ToString() + "\" rel=\"" + links[0].Rel + "\" />" +
" <link href=\"" + links[1].Href.ToString() + "\" rel=\"" + links[1].Rel + "\" />" +
" <content type=\"application/xml\">" +
" <test-event-x xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://grean.rocks/dc\">" +
" <number>" + tex.Number + "</number>" +
" <text>" + tex.Text + "</text>" +
" </test-event-x>" +
" </content>" +
"</entry>");
var actual = XDocument.Parse(sb.ToString());
Assert.Equal(expected, actual, new XNodeEqualityComparer());
// Teardown
}
}