本文整理汇总了C#中NUnit.Framework.List.SelectMany方法的典型用法代码示例。如果您正苦于以下问题:C# List.SelectMany方法的具体用法?C# List.SelectMany怎么用?C# List.SelectMany使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NUnit.Framework.List
的用法示例。
在下文中一共展示了List.SelectMany方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SimpleFlatten
public void SimpleFlatten()
{
List<string> Test = new List<string>();
Test.Add("Howdy");
Test.Add("Pal");
var result = Test.SelectMany(x => x.ToCharArray());
result.AssertSequenceEqual('H', 'o', 'w', 'd', 'y', 'P', 'a', 'l' );
}
示例2: SelectManyQueryReuse
public void SelectManyQueryReuse()
{
List<List<int>> data = new List<List<int>> { new List<int> { 1, 2 }, new List<int> { 3, 4 } };
IEnumerable<int> enumerable = data.SelectMany(x => x);
enumerable.AssertEqual(1, 2, 3, 4);
data.Add(new List<int> { 5, 6 });
enumerable.AssertEqual(1, 2, 3, 4, 5, 6);
}
示例3: Should_Generate_One_Request_Object_Per_Not_Get_Methods
public void Should_Generate_One_Request_Object_Per_Not_Get_Methods()
{
var generatorMethods = new Collection<ClientGeneratorMethod>();
generatorMethods.Add(new ClientGeneratorMethod
{
Name = "m1",
Verb = "get",
ReturnType = "t1",
UriParameters = new List<GeneratorParameter>()
});
generatorMethods.Add(new ClientGeneratorMethod
{
Name = "m2",
Verb = "post",
ReturnType = "t2",
UriParameters = new List<GeneratorParameter>()
});
generatorMethods.Add(new ClientGeneratorMethod
{
Name = "m3",
Verb = "put",
ReturnType = "t3",
UriParameters = new List<GeneratorParameter>()
});
var classes = new List<ClassObject>();
classes.Add(new ClassObject
{
Name = "c1",
Methods = generatorMethods
});
var generator = new ApiRequestObjectsGenerator();
var apiObjects = generator.Generate(classes);
Assert.AreEqual(2, apiObjects.Count());
Assert.AreEqual("ApiRequest", classes.SelectMany(c => c.Methods).First(m => m.Name == "m1").RequestType);
Assert.IsFalse(string.IsNullOrWhiteSpace(classes.SelectMany(c => c.Methods).First(m => m.Name == "m2").RequestType));
Assert.IsFalse(string.IsNullOrWhiteSpace(classes.SelectMany(c => c.Methods).First(m => m.Name == "m3").RequestType));
}
示例4: Test
public void Test()
{
string word = "blue hades";
var problemnum = 2;
int unitIndex = 2;
int seedIndex = 5;
var problem = ProblemsSet.GetProblem(problemnum);
var originalUnit = problem.units[unitIndex];
var prefix = new List<MoveType>();
var spawnedUnit = Game.SpawnUnit(originalUnit, problem).Move(MoveType.SE).Move(MoveType.SW);
var unit = spawnedUnit;
var units = new List<Unit> { unit };
foreach (var c in word)
{
var moveType = MoveTypeExt.Convert(c);
unit = unit.Move(moveType.Value);
units.Add(unit);
}
var minX = units.SelectMany(x => x.members).Min(t => t.x);
while (minX < 0)
{
prefix.Add(MoveType.E);
minX++;
}
while (minX > 0)
{
prefix.Add(MoveType.W);
minX--;
}
prefix.Add(MoveType.SE);
prefix.Add(MoveType.SW);
var game = new SolverGame(problem, problem.sourceSeeds[seedIndex], new string[0]);
game.Step();
var danananananananananananananan = "danananananananananananananan";
game.ApplyUnitSolution(danananananananananananananan);
if (game.state != GameBase.State.End && game.state != GameBase.State.WaitUnit)
throw new InvalidOperationException(string.Format("Invalid game state: {0}", game.state));
game.Step();
Assert.That(game.spawnedUnitIndex, Is.EqualTo(unitIndex));
var staticPowerPhraseBuilder = new StaticPowerPhraseBuilder();
var solution = staticPowerPhraseBuilder.Build(prefix) + word;
Console.Out.WriteLine(danananananananananananananan + solution);
game.ApplyUnitSolution(solution);
var output = new Output
{
problemId = problemnum,
seed = problem.sourceSeeds[seedIndex],
solution = danananananananananananananan + solution
};
}
示例5: ShouldScheduleFixturesForAllTeams
public void ShouldScheduleFixturesForAllTeams()
{
KnockoutStageSeason season = A.KnockoutStageSeason.WithPairCount(4).Scheduled().Activated().Build();
var fixtures = new List<Fixture>();
season.ScheduleFixtures(f => fixtures.Add(f));
var fixtureTeams = fixtures.SelectMany(f => new Team[] { f.Team1, f.Team2 }).ToArray();
Assert.That(fixtureTeams, Is.EquivalentTo(season.Teams));
}
示例6: Flatten
public void Flatten()
{
var listA = new List<int> { 1, 2, 3, 4, 5 };
var listB = new List<int> { 6, 7, 8, 9, 10 };
var listC = new List<int> { 11, 12, 13, 14, 15 };
var lists = new List<List<int>> { listA, listB, listC };
var theList = lists.SelectMany(x => x);
theList.Print();
}
示例7: LotsOfConcurrentMapRedRequestsShouldWork
public void LotsOfConcurrentMapRedRequestsShouldWork()
{
var keys = new List<string>();
for (var i = 1; i < 11; i++)
{
var key = "key" + i;
var doc = new RiakObject(MapReduceBucket, key, new { value = i });
keys.Add(key);
var result = Client.Put(doc, new RiakPutOptions { ReturnBody = true });
result.IsSuccess.ShouldBeTrue();
}
var input = new RiakBucketKeyInput();
keys.ForEach(k => input.Add(new RiakObjectId(MapReduceBucket, k)));
var query = new RiakMapReduceQuery()
.Inputs(input)
.MapJs(m => m.Source(@"function(o){return[1];}"))
.ReduceJs(r => r.Name(@"Riak.reduceSum").Keep(true));
query.Compile();
var results = new List<RiakResult<RiakMapReduceResult>>[ThreadCount];
Parallel.For(0, ThreadCount, i =>
{
results[i] = DoMapRed(query);
});
var failures = 0;
foreach (var r in results.SelectMany(l => l))
{
if (r.IsSuccess)
{
var resultValue = JsonConvert.DeserializeObject<int[]>(r.Value.PhaseResults.ElementAt(1).Values.First().FromRiakString())[0];
resultValue.ShouldEqual(10);
//r.Value.PhaseResults.ElementAt(1).GetObject<int[]>()[0].ShouldEqual(10);
}
else
{
// the only acceptable result is that it ran out of retries when
// talking to the cluster (trying to get a connection)
r.ResultCode.ShouldEqual(ResultCode.NoRetries);
++failures;
}
}
Console.WriteLine("Total of {0} out of {1} failed to execute due to connection contention", failures, ThreadCount * ActionCount);
}
示例8: WillOuterJoinTwoSets
public void WillOuterJoinTwoSets()
{
//arrange
var data1 = new List<int>() {3, 13, 7};
var data2 = new List<int>() {8, 7, 13, 24};
//act
//var join = data1.Join(data2, x => x, y => y, (x, y) => x);
var join = data1.GroupJoin(data2, x => x, y => y, (x, y) => new {Foo = x, Bars = y});
//.SelectMany(x => x.Bars.DefaultIfEmpty());
var j1 = data1.SelectMany(x => data2.Where(y => y == x).DefaultIfEmpty(), (x, y) => y);
//data1.LeftOuterJoin()
//assert
j1.Count().ShouldEqual(5);
}
示例9: ShouldWork
public void ShouldWork()
{
var ready = false;
var bytes = new List<byte[]>();
var obs = new ObservableFromFile(@"samples\example_1.txt");
obs.Subscribe(bytes.Add, e => { }, () => { ready = true; });
while (!ready)
{
Thread.Sleep(10);
}
var array = bytes.SelectMany(b => b)
.Skip(3) // ignore the first 3bytes
.ToArray();
var result = Encoding.UTF8.GetString(array).Replace("\n", " ").Replace("\r\n", " ");
var expected = String.Join(" ", Enumerable.Range(1, 9));
result.Should().Be.EqualTo(expected);
}
示例10: Original
public void Original()
{
var allCsvs = new List<Csv>
{
new Csv
{
CommaSepList = "1,2,3,4,,5"
},
new Csv
{
CommaSepList = "4,5,7,,5,,"
},
};
int[] intArray = allCsvs
.SelectMany(c => c.CommaSepList.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
.Select(int.Parse)
.ToArray();
}
示例11: RequestCustomValidatorErrorCode_When_all_have_unique_value_Then_test_passed
public void RequestCustomValidatorErrorCode_When_all_have_unique_value_Then_test_passed()
{
RequestValidatorErrorMessagesDictionary.Register<ProductRequestCustomValidatorErrorCode>();
RequestValidatorErrorMessagesDictionary.Register<PartnerRequestCustomValidatorErrorCode>();
RequestValidatorErrorMessagesDictionary.Register<RequestValidatorErrorCode>();
RequestValidatorErrorMessagesDictionary.Register<CommonErrorCode>();
var types = new List<Type>();
types.Add(typeof(ProductRequestCustomValidatorErrorCode));
types.Add(typeof(PartnerRequestCustomValidatorErrorCode));
types.Add(typeof(RequestValidatorErrorCode));
types.Add(typeof (CommonErrorCode));
var codeConsts =
types.SelectMany(t => t.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
.Where(f => f.IsLiteral && f.FieldType == typeof(int) && f.DeclaringType == t)).ToList();
Assert.AreEqual(codeConsts.Count, codeConsts.Select(s => (int)s.GetValue(null)).Distinct().Count(), "Error codes are not unique");
Assert.AreEqual(codeConsts.Count, RequestValidatorErrorMessagesDictionary.Instance.Count, "Fetched error codes count is not correct");
Assert.Pass(codeConsts.Count+" unique error codes");
}
示例12: Given_IsSensitive_is_true_then_PersonalRiskAssessment_not_returned
public void Given_IsSensitive_is_true_then_PersonalRiskAssessment_not_returned()
{
//GIVEN
var pras = new List<PersonalRiskAssessment>();
var pra = PersonalRiskAssessment.Create("title", "reference", _companyId, new UserForAuditing() { Id = Guid.NewGuid() });
pra.Sensitive = true;
pra.RiskAssessmentSite = new Site();
pras.Add(pra);
var target = GetTarget();
target.Setup(x => x.PersonalRiskAssessments())
.Returns(pras.AsQueryable);
target.Setup(x => x.RiskAssessmentReviews())
.Returns(pras.SelectMany(x => x.Reviews).AsQueryable);
var result = target.Object.Search(null, _companyId, null, null, null, null, null, _user.Id, false, false, 1, 10, RiskAssessmentOrderByColumn.Title, OrderByDirection.Ascending);
//THEN
Assert.That(result.Count(), Is.EqualTo(0));
}
示例13: RequestCustomValidatorErrorCode_When_all_have_stringValueAttribute_Then_test_passed
public void RequestCustomValidatorErrorCode_When_all_have_stringValueAttribute_Then_test_passed()
{
RequestValidatorErrorMessagesDictionary.Register<ProductRequestCustomValidatorErrorCode>();
RequestValidatorErrorMessagesDictionary.Register<PartnerRequestCustomValidatorErrorCode>();
RequestValidatorErrorMessagesDictionary.Register<RequestValidatorErrorCode>();
RequestValidatorErrorMessagesDictionary.Register<CommonErrorCode>();
var types = new List<Type>();
types.Add(typeof(ProductRequestCustomValidatorErrorCode));
types.Add(typeof(PartnerRequestCustomValidatorErrorCode));
types.Add(typeof(RequestValidatorErrorCode));
types.Add(typeof(CommonErrorCode));
var codeConsts =
types.SelectMany(t => t.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
.Where(f => f.IsLiteral && f.FieldType == typeof(int) && f.DeclaringType == t)).ToList();
foreach (var codeConst in codeConsts)
{
Assert.IsTrue(codeConst.CustomAttributes
.SingleOrDefault(s => s.AttributeType == typeof(StringValueAttribute)) != null);
}
}
示例14: SeedStackOverflowData
private void SeedStackOverflowData(IDbConnectionFactory dbConnectionFactory)
{
var client = new JsonServiceClient();
int numberOfPages = 80;
int pageSize = 100;
var dbQuestions = new List<Question>();
var dbAnswers = new List<Answer>();
try
{
for (int i = 1; i < numberOfPages + 1; i++)
{
//Throttle queries
Thread.Sleep(100);
var questionsResponse =
client.Get("https://api.stackexchange.com/2.2/questions?page={0}&pagesize={1}&site={2}&tagged=servicestack"
.Fmt(i, pageSize, "stackoverflow"));
QuestionsResponse qResponse;
using (new ConfigScope())
{
var json = questionsResponse.ReadToEnd();
qResponse = json.FromJson<QuestionsResponse>();
dbQuestions.AddRange(qResponse.Items.Select(q => q.ConvertTo<Question>()));
}
var acceptedAnswers =
qResponse.Items
.Where(x => x.AcceptedAnswerId != null)
.Select(x => x.AcceptedAnswerId).ToList();
var answersResponse = client.Get("https://api.stackexchange.com/2.2/answers/{0}?sort=activity&site=stackoverflow"
.Fmt(acceptedAnswers.Join(";")));
using (new ConfigScope())
{
var json = answersResponse.ReadToEnd();
var aResponse = JsonSerializer.DeserializeFromString<AnswersResponse>(json);
dbAnswers.AddRange(aResponse.Items.Select(a => a.ConvertTo<Answer>()));
}
}
}
catch (Exception ex)
{
//ignore
}
//Filter duplicates
dbQuestions = dbQuestions.GroupBy(q => q.QuestionId).Select(q => q.First()).ToList();
dbAnswers = dbAnswers.GroupBy(a => a.AnswerId).Select(a => a.First()).ToList();
var questionTags = dbQuestions.SelectMany(q =>
q.Tags.Select(t => new QuestionTag { QuestionId = q.QuestionId, Tag = t }));
using (var db = dbConnectionFactory.OpenDbConnection())
{
db.InsertAll(dbQuestions);
db.InsertAll(dbAnswers);
db.InsertAll(questionTags);
}
}
示例15: _SetupLargeDataset
private void _SetupLargeDataset()
{
_largeDataset = new List<string>();
HashSet<SearchResult> searchResults = new HashSet<SearchResult>();
StreamReader reader = new StreamReader(@"results.csv");
reader.ReadLine(); //do not process header
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
string[] entries = line.Split(new [] {','}, System.StringSplitOptions.None);
SearchResult sr = new SearchResult(entries[0]);
searchResults.Add(sr);
}
_largeDataset.AddRange(searchResults.Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name));
List<string> intermediateDataSet = new List<string>();
intermediateDataSet.AddRange(_largeDataset.SelectMany(x => x.Split(new[] {' '})));
_sortedDataSet = new SortedList(
intermediateDataSet.Where(x => !string.IsNullOrWhiteSpace(x)).
Select(x => x.ToLower().Trim()).
Distinct().
ToDictionary(str => str));
}