本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List类的典型用法代码示例。如果您正苦于以下问题:C# List类的具体用法?C# List怎么用?C# List使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
List类属于Microsoft.VisualStudio.TestTools.UnitTesting命名空间,在下文中一共展示了List类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:nemesek,项目名称:ProjectEuler,代码行数:28,代码来源:Problem10Tests.cs
示例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);
}
开发者ID:harumburum,项目名称:todolist-mvc5,代码行数:26,代码来源:TodoRepositoryTests.cs
示例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);
}
开发者ID:mjenny,项目名称:ECNF,代码行数:35,代码来源:Lab5Test.cs
示例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);
}
开发者ID:dvysotskiy,项目名称:Healthcare,代码行数:26,代码来源:SubsidyCalculatorTest.cs
示例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);
}
}
开发者ID:joefeser,项目名称:XPathParser,代码行数:31,代码来源:LocationPaths_Test_Expected_Return_Values.cs
示例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);
}
开发者ID:guusvanw,项目名称:Guus.Xrm,代码行数:29,代码来源:GenericXrmServiceTest.cs
示例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);
}
开发者ID:PetarPenev,项目名称:Telerik,代码行数:7,代码来源:UnitTestingQuickSort.cs
示例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);
}
开发者ID:embix,项目名称:TIS100,代码行数:7,代码来源:AddTest.cs
示例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);
}
开发者ID:andyvans,项目名称:BinarySerializer,代码行数:31,代码来源:UntilItemTests.cs
示例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;
}
}
开发者ID:eslahi,项目名称:prism,代码行数:28,代码来源:CompilerHelper.Desktop.cs
示例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);
}
开发者ID:MMetodiew,项目名称:hotdocs-open-sdk,代码行数:25,代码来源:AnswerTest.cs
示例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);
}
开发者ID:lance22me,项目名称:BiggResponsive,代码行数:7,代码来源:EnumerableExtensionTests.cs
示例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();
}
开发者ID:ebergstedt,项目名称:CruDapper,代码行数:32,代码来源:TestPut.cs
示例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);
}
开发者ID:embix,项目名称:TIS100,代码行数:7,代码来源:AddTest.cs
示例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);
}
开发者ID:modulexcite,项目名称:Tx,代码行数:25,代码来源:EtwTest.cs
示例16: CreateEventsFor_Test
public void CreateEventsFor_Test()
{
// Arrange
_eventRepo.Setup(x => x.GetEventsOn(It.IsAny<DateTime>())).Returns(new List<Event>());
var start = new DateTime(2014, 2, 16);
// start.DayOfWeek = Sunday
var end = start.AddDays(6);
var basketball = new Activity
{
DayOfWeek = "Saturday",
Name = "Basketball"
};
var frisbee = new Activity
{
DayOfWeek = "Sunday",
Name = "Frisbee"
};
var activities = new List<Activity> {
basketball, frisbee
};
var count = 0;
_eventRepo.Setup(x => x.Insert(It.IsAny<Event>())).Callback((Event ev) => { count++; });
_activtyRepo.Setup(x => x.GetAll()).Returns(activities);
// Act
_sut.CreateEventsFor(start, end);
// Assert
Assert.AreEqual(2, count);
}
开发者ID:EventHub,项目名称:GenericEventHub,代码行数:34,代码来源:EventGeneratorTests.cs
示例17: QueryEntries
/// <summary>
/// Specifically use to query single entry or multi entries(query with $expand)
/// </summary>
/// <param name="requestUri"></param>
/// <param name="mimeType"></param>
/// <returns></returns>
public List<ODataEntry> QueryEntries(string requestUri, string mimeType)
{
List<ODataEntry> entries = new List<ODataEntry>();
ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings() { BaseUri = baseUri };
var requestMessage = new HttpWebRequestMessage(new Uri(baseUri.AbsoluteUri + requestUri, UriKind.Absolute));
requestMessage.SetHeader("Accept", mimeType);
var responseMessage = requestMessage.GetResponse();
Assert.AreEqual(200, responseMessage.StatusCode);
if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata))
{
using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, model))
{
var reader = messageReader.CreateODataEntryReader();
while (reader.Read())
{
if (reader.State == ODataReaderState.EntryEnd)
{
entries.Add(reader.Item as ODataEntry);
}
}
Assert.AreEqual(ODataReaderState.Completed, reader.State);
}
}
return entries;
}
开发者ID:rossjempson,项目名称:odata.net,代码行数:34,代码来源:QueryOptionTestsHelper.cs
示例18: ListContainsTest
public void ListContainsTest()
{
var list = new List<char>();
list.Add('o');
Assert.IsTrue(list.Contains('o'));
Assert.IsFalse(list.Contains('l'));
}
开发者ID:Kirill-Andreev,项目名称:University,代码行数:7,代码来源:GenericsTest.cs
示例19: TestRedirectFileGeneration
//[TestMethod]
public void TestRedirectFileGeneration()
{
var originalFile = @"E:\Index\mscorlib\A.html";
var lines = File.ReadAllLines(originalFile);
var list = new List<KeyValuePair<string, string>>();
var map = new Dictionary<string, string>();
foreach (var line in lines)
{
if (line.Length > 25 && line[0] == 'm')
{
if (line[22] == '"')
{
var id = line.Substring(3, 16);
var file = line.Substring(23, line.Length - 25);
list.Add(new KeyValuePair<string, string>(id, file));
map[id] = file;
}
else if (line[22] == 'm')
{
var id = line.Substring(3, 16);
var other = line.Substring(25, 16);
list.Add(new KeyValuePair<string, string>(id, map[other]));
}
}
}
Microsoft.SourceBrowser.HtmlGenerator.ProjectGenerator.GenerateRedirectFile(
@"E:\Solution",
@"E:\Solution\Project",
list.ToDictionary(kvp => kvp.Key, kvp => (IEnumerable<string>)new List<string> { kvp.Value }));
}
开发者ID:rgmills,项目名称:SourceBrowser,代码行数:34,代码来源:RedirectFileTests.cs
示例20: GetFirstUnsentAddress_ShouldReturnNull_IfNoUserWithNotSentStatusExistsInDatabase
public void GetFirstUnsentAddress_ShouldReturnNull_IfNoUserWithNotSentStatusExistsInDatabase()
{
// Arrange
var stubContext = new Mock<Context>();
var stubRecipients = new List<Recipient>
{
new Recipient("[email protected]"),
new Recipient("[email protected]"),
new Recipient("[email protected]"),
}.AsQueryable();
stubRecipients.ElementAt(0).MarkAsSent(DateTime.Now);
stubRecipients.ElementAt(1).MarkAsSent(DateTime.Now);
stubRecipients.ElementAt(2).MarkAsFailed("sending failed", DateTime.Now);
var stubDbSet = new Mock<DbSet<Recipient>>();
stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.Provider).Returns(stubRecipients.Provider);
stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.Expression).Returns(stubRecipients.Expression);
stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.ElementType).Returns(stubRecipients.ElementType);
stubDbSet.As<IQueryable<Recipient>>().Setup(m => m.GetEnumerator()).Returns(stubRecipients.GetEnumerator());
stubContext.Setup(c => c.Recipients).Returns(stubDbSet.Object);
// Act
var repository = new Repository(stubContext.Object);
var recipient = repository.GetFirstUnsentAddress();
// Assert
Assert.IsNull(recipient);
}
开发者ID:bpashkovskyi,项目名称:BulkMailSender,代码行数:30,代码来源:RepositoryTests.cs
注:本文中的Microsoft.VisualStudio.TestTools.UnitTesting.List类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论