本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List类的典型用法代码示例。如果您正苦于以下问题:C# List类的具体用法?C# List怎么用?C# List使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
List类属于Microsoft.VisualStudio.TestTools.UnitTesting命名空间,在下文中一共展示了List类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Eratostenes
private static IEnumerable<long> Eratostenes()
{
const int max = 2000000;
var primes = new List<long>();
var crossedOff = new HashSet<long>();
long candidate = 1;
while (candidate < max)
{
candidate++;
if (crossedOff.Contains(candidate))
{
continue;
}
primes.Add(candidate);
// remove multiples of candidate
for (var i = candidate; i < max + 1; i += candidate)
{
crossedOff.Add(i);
}
}
return primes.ToArray();
}
示例2: GetAllShouldReturnTodos
public void GetAllShouldReturnTodos()
{
var data = new List<Todo>
{
new Todo {Id = 1},
new Todo {Id = 2},
new Todo {Id = 3},
}.AsQueryable();
var mockSet = new Mock<DbSet<Todo>>();
mockSet.As<IQueryable<Todo>>().Setup(m => m.Provider).Returns(data.Provider);
mockSet.As<IQueryable<Todo>>().Setup(m => m.Expression).Returns(data.Expression);
mockSet.As<IQueryable<Todo>>().Setup(m => m.ElementType).Returns(data.ElementType);
mockSet.As<IQueryable<Todo>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());
var mockContext = new Mock<ApplicationDbContext>();
mockContext.Setup(c => c.Todos).Returns(mockSet.Object);
var service = new TodoRepository(mockContext.Object);
var todos = service.GetAll().ToList();
Assert.AreEqual(3, todos.Count);
Assert.AreEqual(1, todos[0].Id);
Assert.AreEqual(2, todos[1].Id);
Assert.AreEqual(3, todos[2].Id);
}
示例3: TestLoadAndRunDynamic
public void TestLoadAndRunDynamic()
{
var cities = new Cities();
cities.ReadCities(CitiesTestFile);
IRoutes routes = RoutesFactory.Create(cities);
routes.ReadRoutes(LinksTestFile);
Assert.AreEqual(11, cities.Count);
// test available cities
List<Link> links = routes.FindShortestRouteBetween("Zürich", "Basel", TransportModes.Rail);
var expectedLinks = new List<Link>();
expectedLinks.Add(new Link(new City("Zürich", "Switzerland", 7000, 1, 2),
new City("Aarau", "Switzerland", 7000, 1, 2), 0));
expectedLinks.Add(new Link(new City("Aarau", "Switzerland", 7000, 1, 2),
new City("Liestal", "Switzerland", 7000, 1, 2), 0));
expectedLinks.Add(new Link(new City("Liestal", "Switzerland", 7000, 1, 2),
new City("Basel", "Switzerland", 7000, 1, 2), 0));
Assert.IsNotNull(links);
Assert.AreEqual(expectedLinks.Count, links.Count);
for (int i = 0; i < links.Count; i++)
{
Assert.AreEqual(expectedLinks[i].FromCity.Name, links[i].FromCity.Name);
Assert.AreEqual(expectedLinks[i].ToCity.Name, links[i].ToCity.Name);
}
links = routes.FindShortestRouteBetween("doesNotExist", "either", TransportModes.Rail);
Assert.IsNull(links);
}
示例4: CalcualteSubsidy
public void CalcualteSubsidy()
{
int year = 2015;
string state = "CA";
decimal income = 24750M;
int rateAreaId = 4;
var family = new List<Person>(
new Person[]
{
new Person() { Dob = DateTime.Today.AddYears(-56), Relationship = Relationship.Self },
new Person() { Dob = DateTime.Today.AddYears(-52), Relationship = Relationship.Spouse },
new Person() { Dob = DateTime.Today.AddYears(-2), Relationship = Relationship.Dependent },
new Person() { Dob = DateTime.Today.AddYears(-21), Relationship = Relationship.Dependent },
new Person() { Dob = DateTime.Today.AddYears(-22), Relationship = Relationship.Dependent },
new Person() { Dob = DateTime.Today.AddYears(-4), Relationship = Relationship.Dependent },
new Person() { Dob = DateTime.Today.AddYears(-6), Relationship = Relationship.Dependent },
new Person() { Dob = DateTime.Today.AddYears(-18), Relationship = Relationship.Dependent },
}
);
var calc = GetCalculator();
var input = new GetFinancialAssistanceRequest() { County = "", EffectiveDate = DateTime.Now.AddMonths(1), FamilyMembers = family, FamilySize = 4, FamilyTaxableIncome = 26000, ZipCode = "94154" };
var result = calc.CalculateSubsidy(input);
Assert.IsNotNull(result);
}
示例5: Test_All_Items_For_Correct_Return_Paths_Abbreviated_Syntax
public void Test_All_Items_For_Correct_Return_Paths_Abbreviated_Syntax()
{
var values = new List<KeyValuePair<string, string>>() {
new KeyValuePair<string,string>("/" , "root::node()"),
new KeyValuePair<string,string>("/doc/chapter[position()=5]/section[position()=2]" , "root::node()/child::doc/(child::chapter)[position()=5]/(child::section)[position()=2]"),
new KeyValuePair<string,string>("@*" , "attribute::*"),
new KeyValuePair<string,string>("@name" , "attribute::name"),
new KeyValuePair<string,string>("*" , "child::*"),
new KeyValuePair<string,string>("*/child::para" , "child::*/child::para"),
new KeyValuePair<string,string>("*[self::chapter or self::appendix]" , "(child::*)[self::chapter or self::appendix]"),
new KeyValuePair<string,string>("*[self::chapter or self::appendix][position()=last()]" , "((child::*)[self::chapter or self::appendix])[position()=last()]"),
new KeyValuePair<string,string>("chapter/descendant::para" , "child::chapter/descendant::para"),
new KeyValuePair<string,string>("chapter[title='Introduction']" , "(child::chapter)[child::title='Introduction']"),
new KeyValuePair<string,string>("chapter[title]" , "(child::chapter)[child::title]"),
new KeyValuePair<string,string>("node()" , "child::node()"),
new KeyValuePair<string,string>("para" , "child::para"),
new KeyValuePair<string,string>("para[@type='warning']" , "(child::para)[attribute::type='warning']"),
new KeyValuePair<string,string>("para[@type='warning'][position()=5]" , "((child::para)[attribute::type='warning'])[position()=5]"),
new KeyValuePair<string,string>("para[1]" , "(child::para)[1]"),
new KeyValuePair<string,string>("para[position()=5][@type='warning']" , "((child::para)[position()=5])[attribute::type='warning']"),
new KeyValuePair<string,string>("para[position()=last()-1]" , "(child::para)[position()=last()-1]"),
new KeyValuePair<string,string>("para[position()=last()]" , "(child::para)[position()=last()]"),
new KeyValuePair<string,string>("para[position()>1]" , "(child::para)[position()>1]"),
new KeyValuePair<string,string>("text()" , "child::text()"),
};
foreach (var item in values) {
var result = new XPathParser<string>().Parse(item.Key, new XPathStringBuilder());
Assert.AreEqual<string>(item.Value, result);
}
}
示例6: GenerateRandomAccountCollection
private EntityCollection GenerateRandomAccountCollection()
{
var collection = new List<Entity>();
for (var i = 0; i < 10; i++)
{
var rgn = new Random((int)DateTime.Now.Ticks);
var entity = new Entity("account");
entity["accountid"] = entity.Id = Guid.NewGuid();
entity["address1_addressid"] = Guid.NewGuid();
entity["modifiedon"] = DateTime.Now;
entity["lastusedincampaign"] = DateTime.Now;
entity["donotfax"] = rgn.NextBoolean();
entity["new_verybignumber"] = rgn.NextInt64();
entity["exchangerate"] = rgn.NextDecimal();
entity["address1_latitude"] = rgn.NextDouble();
entity["numberofemployees"] = rgn.NextInt32();
entity["primarycontactid"] = new EntityReference("contact", Guid.NewGuid());
entity["revenue"] = new Money(rgn.NextDecimal());
entity["ownerid"] = new EntityReference("systemuser", Guid.NewGuid());
entity["industrycode"] = new OptionSetValue(rgn.NextInt32());
entity["name"] = rgn.NextString(15);
entity["description"] = rgn.NextString(300);
entity["statecode"] = new OptionSetValue(rgn.NextInt32());
entity["statuscode"] = new OptionSetValue(rgn.NextInt32());
collection.Add(entity);
}
return new EntityCollection(collection);
}
示例7: TestWithAnEmptyCollection
public void TestWithAnEmptyCollection()
{
List<int> collection = new List<int>();
Quicksorter<int> sorter = new Quicksorter<int>();
sorter.Sort(collection);
Assert.AreEqual(0, collection.Count);
}
示例8: Upper_Limit_Is_999
public void Upper_Limit_Is_999()
{
var inQueue = new List<int> { 999, 1 };
var expectedOutQueue = new List<int> { 999 };
AssertAddOutputMatches(inQueue, expectedOutQueue);
}
示例9: UntilItemConstTest
public void UntilItemConstTest()
{
var items = new List<UntilItemClass>
{
new UntilItemClass
{
Name = "Alice",
LastItem = "Nope",
Description = "She's just a girl in the world"
},
new UntilItemClass
{
Name = "Bob",
LastItem = "Not yet",
Description = "Well, he's just this guy, you know?"
},
new UntilItemClass
{
Name = "Charlie",
LastItem = "Yep",
Description = "What?? That's a great idea!"
}
};
var expected = new UntilItemContainer {Items = items, ItemsLastItemExcluded = items, BoundItems = items};
var actual = Roundtrip(expected);
Assert.AreEqual(expected.Items.Count, actual.Items.Count);
Assert.AreEqual(expected.ItemsLastItemExcluded.Count - 1, actual.ItemsLastItemExcluded.Count);
}
示例10: CompileFile
public static CompilerResults CompileFile(string input, string output, params string[] references)
{
CreateOutput(output);
List<string> referencedAssemblies = new List<string>(references.Length + 3);
referencedAssemblies.AddRange(references);
referencedAssemblies.Add("System.dll");
referencedAssemblies.Add(typeof(IModule).Assembly.CodeBase.Replace(@"file:///", ""));
referencedAssemblies.Add(typeof(ModuleAttribute).Assembly.CodeBase.Replace(@"file:///", ""));
CSharpCodeProvider codeProvider = new CSharpCodeProvider();
CompilerParameters cp = new CompilerParameters(referencedAssemblies.ToArray(), output);
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(input))
{
if (stream == null)
{
throw new ArgumentException("input");
}
StreamReader reader = new StreamReader(stream);
string source = reader.ReadToEnd();
CompilerResults results = codeProvider.CompileAssemblyFromSource(cp, source);
ThrowIfCompilerError(results);
return results;
}
}
示例11: EnumerateValues
public void EnumerateValues()
{
var filterItems = new List<string>();
AnswerCollection anss = new AnswerCollection();
Answer ta = anss.CreateAnswer<TextValue>("my answer");
ta.UserExtendible = false; // user should not be able to add/remove/reorder iterations in the interview
ta.SetValue<TextValue>(new TextValue("val1", false), 0); // user should not be able to modify this answer
ta.SetValue<TextValue>(new TextValue("val2", true), 1); // user will be able to modify this answer
ta.SetValue<TextValue>(new TextValue("val3"), 2); // user will be able to modify this answer
ta.SetValue<TextValue>("val4", 3); // user will be able to modify this answer
// now enumerate the values
AnswerValueEnumerator(ta);
// now enumerate some Number values
Answer tn = anss.CreateAnswer<NumberValue>("my num answer");
tn.SetValue<NumberValue>(new NumberValue(3), 0);
AnswerValueEnumerator(tn);
// now enumerate some Date values
Answer td = anss.CreateAnswer<DateValue>("my date answer");
td.SetValue<DateValue>(new DateValue(DateTime.Now), 0);
AnswerValueEnumerator(td);
}
示例12: DistinctByLambda_OneListReversedEmpty_ExpectTheOneListValues
public void DistinctByLambda_OneListReversedEmpty_ExpectTheOneListValues()
{
List<Member> emptyList = new List<Member>();
var result = this.dozenPeopleList.Union(emptyList).Distinct((l1, l2) => l1.FirstName == l2.FirstName);
Assert.IsTrue(result.Count() > 1);
}
示例13: PutIdentifiable
public void PutIdentifiable()
{
DoBaseline();
var entries = new List<TestIdentifiableTable>();
for (var i = 0; i < 1000; i++)
{
entries.Add(new TestIdentifiableTable
{
SomeData = i.ToString() + 1
});
}
var identifiableTables = CrudService
.PutIdentifiable<TestIdentifiableTable>(entries);
entries = new List<TestIdentifiableTable>();
for (var i = 0; i < 1000; i++)
{
entries.Add(new TestIdentifiableTable
{
SomeData = i.ToString() + 1
});
}
identifiableTables = CrudService
.PutIdentifiable<TestIdentifiableTable>(entries);
Assert.IsTrue(identifiableTables.All(t => t.Id > 0));
DoBaseline();
}
示例14: Addition_Within_Limits_Works
public void Addition_Within_Limits_Works()
{
var inQueue = new List<int> { 1, -1, 1, 1, -999, 1, -999, 0, 999, -999, 999, -333 };
var expectedOutQueue = new List<int> { 0, 2, -998, -999, 0, 666 };
AssertAddOutputMatches(inQueue, expectedOutQueue);
}
示例15: EtwFileSourceTest
public void EtwFileSourceTest()
{
var observable = EtwObservable.FromFiles(FileName);
var source = new TimeSource<EtwNativeEvent>(observable, e => e.TimeStamp);
var parsed = from p in source
where p.Id == 2
select p.TimeStamp;
var buf = parsed.Take(13).Buffer(TimeSpan.FromSeconds(1), source.Scheduler);
var list = new List<IList<DateTimeOffset>>();
ManualResetEvent completed = new ManualResetEvent(false);
buf.Subscribe(
t => list.Add(t),
()=>completed.Set());
source.Connect();
completed.WaitOne();
Assert.AreEqual(2, list.Count());
Assert.AreEqual(7, list.First().Count);
Assert.AreEqual(6, list.Skip(1).First().Count);
}