本文整理汇总了C#中NUnit.Framework.List.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# List.ToList方法的具体用法?C# List.ToList怎么用?C# List.ToList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NUnit.Framework.List
的用法示例。
在下文中一共展示了List.ToList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestInit
public void TestInit()
{
#region User members
_members = new List<User>
{
new User
{
UserId = 1,
UserName = "lorem"
},
new User
{
UserId = 2,
UserName = "ipsum"
},
new User
{
UserId = 3,
UserName = "dolor"
}
};
#endregion
#region Communities
_communities = new List<Community>
{
new Community
{
Id = 1,
LeaderUserId = 1,
Leader = _members.FirstOrDefault(a => a.UserId == 1),
Members = _members.ToList()
},
new Community
{
Id = 2,
LeaderUserId = 2,
Leader = _members.FirstOrDefault(a => a.UserId == 2),
Members = _members.ToList()
},
new Community
{
Id = 3,
LeaderUserId = 3,
Leader = _members.FirstOrDefault(a => a.UserId == 3),
Members = _members.ToList()
},
};
#endregion
}
示例2: TryValidateObjectRecursive_returns_errors_when_grandchild_class_has_invalid_properties
public void TryValidateObjectRecursive_returns_errors_when_grandchild_class_has_invalid_properties()
{
var parent = new Parent { PropertyA = 1, PropertyB = 1 };
parent.Child = new Child { PropertyA = 1, PropertyB = 1 };
parent.Child.GrandChildren = new [] {new GrandChild{PropertyA = 11, PropertyB = 11}};
var validationResults = new List<ValidationResult>();
var result = _validator.TryValidateObjectRecursive(parent, validationResults);
Assert.IsFalse(result);
Assert.AreEqual(2, validationResults.Count);
Assert.AreEqual(1, validationResults.ToList().Count(x => x.ErrorMessage == "GrandChild PropertyA not within range"));
Assert.AreEqual(1, validationResults.ToList().Count(x => x.ErrorMessage == "GrandChild PropertyB not within range"));
}
示例3: ToListReturnsNewInstance
public void ToListReturnsNewInstance()
{
List<int> integers = new List<int>() { 1, 2, 3 };
List<int> result = integers.ToList();
Assert.That(result, Is.Not.SameAs(integers));
}
示例4: PrintSingleTest
public static void PrintSingleTest()
{
var directories = GetBuildDirectories();
var tests = new List<TestResult>();
foreach (var dir in directories)
{
var files = Directory.GetFiles(dir, "junitResult.xml");
if (files.Any())
{
var fileName = files[0];
var iterator = GetTestCasesWithErrors("UserAcceptanceTests.Features.ProductFeature","RefreshOnProductAfterAddingCommentShouldNOTResultInErrorBugFix",fileName);
while (iterator.MoveNext())
{
var failingTest = GetFailingTestName(iterator);
var testResult = new TestResult {BuildName = GetBuildName(dir),TestName = failingTest};
tests.Add(testResult);
}
}
}
foreach (var failingTest in tests.ToList().OrderBy(x=>x.BuildName).Reverse())
{
Console.WriteLine(failingTest);
}
}
示例5: ResultIsIndependentOfSource
public void ResultIsIndependentOfSource()
{
List<string> source = new List<string> { "xyz", "abc" };
List<string> result = source.ToList();
result.AssertSequenceEqual("xyz", "abc");
Assert.AreNotSame(source, result);
source.Add("extra element");
// The extra element hasn't been added to the result
Assert.AreNotEqual(source.Count, result.Count);
}
示例6: Setup
public void Setup()
{
var reviews = new List<Review>();
var review = new Review();
review.Id = 1;
review.Title = "Testing";
review.Content = "Testng Reviews";
review.UserId = "d9274a62-8a8c-46bf-aedc-d1cb3e8626c0";
review.Username = "admin";
reviews.Add(review);
this.Reviews = reviews.ToList();
}
示例7: CombinesDataBlocks
public void CombinesDataBlocks(
[Values(100, 500, 1000, 5000)] double blockMilliseconds,
[Values(5000, 10000)] double sampleRateHz,
[Values(1, 4)] int numStim
)
{
var parameters = new Dictionary<string, object>();
var sampleRate = new Measurement((decimal)sampleRateHz, "Hz");
var data = new List<IOutputData>();
var stimuli = new List<IStimulus>();
for (int i = 0; i < numStim; i++)
{
IOutputData d = new OutputData(Enumerable.Range(0, (int)TimeSpan.FromSeconds(3).Samples(new Measurement((decimal)sampleRateHz, "Hz")))
.Select(j => new Measurement(j, "units")).ToList(),
sampleRate,
false);
data.Add(d);
stimuli.Add(new RenderedStimulus((string)"RenderedStimulus" + i, (IDictionary<string, object>)parameters, d));
}
var combined = new CombinedStimulus("CombinedStimulus", new Dictionary<string, object>(), stimuli, CombinedStimulus.Add);
var blockSpan = TimeSpan.FromMilliseconds(blockMilliseconds);
IEnumerator<IOutputData> iter = combined.DataBlocks(blockSpan).GetEnumerator();
while (iter.MoveNext())
{
IOutputData expectedData = null;
foreach (var d in data.ToList())
{
var cons = d.SplitData(blockSpan);
data[data.IndexOf(d)] = cons.Rest;
expectedData = expectedData == null
? cons.Head
: expectedData.Zip(cons.Head, (m1, m2) => new Measurement(m1.QuantityInBaseUnits + m2.QuantityInBaseUnits, 0, m1.BaseUnits));
}
Assert.That(iter.Current.Duration, Is.EqualTo(expectedData.Duration));
Assert.That(iter.Current.Data, Is.EqualTo(expectedData.Data));
}
}
示例8: DeterminePlaceholderIndicesNormalTets
public void DeterminePlaceholderIndicesNormalTets()
{
//(?,?2,?,?2,?1)
var placeholders = new List<AstPlaceholder>
{
_createPlaceholder(),
_createPlaceholder(1),
_createPlaceholder(),
_createPlaceholder(1),
_createPlaceholder(0)
};
var copy = placeholders.ToList();
Assert.AreNotSame(copy, placeholders);
AstPlaceholder.DeterminePlaceholderIndices(placeholders);
//First assert that the list itself has not been altered
Assert.AreEqual(placeholders.Count, copy.Count);
for (var i = 0; i < placeholders.Count; i++)
Assert.AreSame(copy[i], placeholders[i], "List itself must not be altered.");
//Expexted mapping (0-based):
// ?2, ?1, ?3, ?1, ?0
foreach (var placeholder in placeholders)
Assert.IsTrue(placeholder.Index.HasValue,
"All placeholders should be assigned afterwards.");
// ReSharper disable PossibleInvalidOperationException
Assert.AreEqual(2, placeholders[0].Index.Value,
"Placeholder at source position 0 is not mapped correctly");
Assert.AreEqual(1, placeholders[1].Index.Value,
"Placeholder at source position 1 is not mapped correctly");
Assert.AreEqual(3, placeholders[2].Index.Value,
"Placeholder at source position 2 is not mapped correctly");
Assert.AreEqual(1, placeholders[3].Index.Value,
"Placeholder at source position 3 is not mapped correctly");
Assert.AreEqual(0, placeholders[4].Index.Value,
"Placeholder at source position 4 is not mapped correctly");
// ReSharper restore PossibleInvalidOperationException
}
示例9: Index_Returns_Category_List
public async void Index_Returns_Category_List()
{
// Arrange
IEnumerable<Category> fakeCategories = new List<Category>
{
new Category {Id = 1, Name = "Test1", Description = "Test1Desc"},
new Category {Id = 2, Name = "Test2", Description = "Test2Desc"},
new Category {Id = 3, Name = "Test3", Description = "Test3Desc"}
}.AsEnumerable();
_firstDbContextUoW.Setup(x => x.CategoryRepository.GetAllAsync()).ReturnsAsync(fakeCategories.ToList());
var controller = new CategoryController(_categoryService);
// Act
Mapper.CreateMap<Category, CategoryModel>();
var result = (ViewResult) await controller.Index();
// Assert
Assert.IsNotNull(result, "View Result is null");
Assert.IsInstanceOf(typeof(IEnumerable<CategoryModel>),
result.ViewData.Model, "Wrong View Model");
var categories = result.ViewData.Model as IEnumerable<CategoryModel>;
if (categories != null) Assert.AreEqual(3, categories.Count(), "Got wrong number of Categories");
}
示例10: Index_Returns_Department_List
public async void Index_Returns_Department_List()
{
// Arrange
IEnumerable<Department> fakeDepartments = new List<Department>
{
new Department {Id = 1, Name = "Test1"},
new Department {Id = 2, Name = "Test2"},
new Department {Id = 3, Name = "Test3"}
}.AsEnumerable();
_secondDbContextUoW.Setup(x => x.DepartmentRepository.GetAllAsync()).ReturnsAsync(fakeDepartments.ToList());
var controller = new DepartmentController(_departmentService);
// Act
Mapper.CreateMap<Department, DepartmentModel>();
var result = (ViewResult) await controller.Index();
// Assert
Assert.IsNotNull(result, "View Result is null");
Assert.IsInstanceOf(typeof(IEnumerable<DepartmentModel>),
result.ViewData.Model, "Wrong View Model");
var departments = result.ViewData.Model as IEnumerable<DepartmentModel>;
if (departments != null) Assert.AreEqual(3, departments.Count(), "Got wrong number of Departments");
}
示例11: FillInGuestPhonesCallsDaoOnce
public void FillInGuestPhonesCallsDaoOnce()
{
var guestPhoneDao = new Mock<IGuestPhoneDao>();
BookingDao bookingDao = new BookingDao
{
GuestPhoneDao = guestPhoneDao.Object
};
IEnumerable<Booking> bookings = new List<Booking>()
{
new Booking
{
GuestId = 1,
Guest = new Guest() { GuestId = 1 }
},
new Booking
{
GuestId = 2,
Guest = new Guest() { GuestId = 1 }
}
};
guestPhoneDao.Setup(gp => gp.GetAllByGuestIdList(It.IsAny<IEnumerable<int>>()))
.Returns(new List<GuestPhone>()
{
new GuestPhone {GuestId = 1},
new GuestPhone {GuestId = 2}
});
bookingDao.FillInGuestPhones(bookings);
Assert.IsTrue(bookings.ToList().TrueForAll(b => b.Guest.GuestPhones != null),
"Not all booking got phone numbers correctly");
guestPhoneDao.Verify(gp => gp.GetAllByGuestIdList(It.IsAny<IEnumerable<int>>()), Times.Once);
}
示例12: Given_a_FRA_when_copy_then_attached_documents_are_cloned
public void Given_a_FRA_when_copy_then_attached_documents_are_cloned()
{
var currentUser = new UserForAuditing { Id = Guid.NewGuid() };
IEnumerable<RiskAssessmentDocument> documents = new List<RiskAssessmentDocument>()
{
new RiskAssessmentDocument()
{
Id = 1, CreatedBy = new UserForAuditing { Id = Guid.NewGuid() }, CreatedOn = DateTime.Now.AddDays(-1234),Description = "doc description",DocumentLibraryId = 123
},
new RiskAssessmentDocument()
{
Id = 2, CreatedBy = new UserForAuditing { Id = Guid.NewGuid() }, CreatedOn = DateTime.Now.AddDays(-1234)
}
,
new RiskAssessmentDocument()
{
Id = 3, CreatedBy = new UserForAuditing { Id = Guid.NewGuid() }, CreatedOn = DateTime.Now.AddDays(-1234)
}
};
var fraToCopy = FireRiskAssessment.Create("this is the title", "the ref", 1312, null, new UserForAuditing { Id = Guid.NewGuid() });
fraToCopy.Documents = documents.ToList();
//when
var copiedFra = fraToCopy.Copy(currentUser);
//then
Assert.AreEqual(fraToCopy.Documents.Count(), copiedFra.Documents.Count);
Assert.IsTrue(copiedFra.Documents.All(x => x.Id == 0));
Assert.IsTrue(copiedFra.Documents.All(x => x.CreatedBy.Id == currentUser.Id)); //ensure that all cloned are new entities
Assert.IsTrue(copiedFra.Documents.All(x => x.CreatedOn.Value.Date == DateTime.Now.Date)); //ensure that all cloned are new entities
Assert.IsTrue(copiedFra.Documents.Any(x => x.Description == documents.First().Description));
Assert.AreEqual(fraToCopy, copiedFra.Documents.First().RiskAssessment);
}
示例13: Print
public string Print(List<Token> tokens)
{
IntrospectedTokens = tokens.ToList();
return "The result of this outputter is found in the field 'IntrospectedTokens'";
}
示例14: testBuildPatientObject
public void testBuildPatientObject()
{
DemographicSet patientDemogs = new DemographicSet();
Address addr = new Address() { City = "Hooville", State = "MI", County = "Eggs and Ham", Street1 = "123 Elm St.", Street2 = "Apt 4", Zipcode = "90210" };
PhoneNum phone = new PhoneNum() { Description = "Cell phone", AreaCode = "555", Exchange = "867", Number = "5309" };
EmailAddress email = new EmailAddress() { Address = "[email protected]" };
IList<Address> addresses = new List<Address>() { addr };
IList<PhoneNum> telephones = new List<PhoneNum>() { phone };
IList<EmailAddress> emails = new List<EmailAddress>() { email };
patientDemogs.EmailAddresses = emails.ToList<EmailAddress>();
patientDemogs.PhoneNumbers = telephones.ToList<PhoneNum>();
patientDemogs.StreetAddresses = addresses.ToList<Address>();
CCRHelper helper = new CCRHelper();
ActorType patient = helper.buildPatientObject("1234567890", "987654321", "USER", "ONE", "O", "0000/12/25", "2011", "M", patientDemogs);
Assert.IsNotNull(patient);
Assert.IsTrue(patient.Item is ActorTypePerson);
Assert.AreEqual(patient.Address.Count, 1);
Assert.AreEqual(patient.EMail.Count, 1);
Assert.AreEqual(patient.Telephone.Count, 1);
Assert.AreEqual(patient.IDs.Count, 2);
Assert.IsTrue(String.Equals(patient.IDs[0].ID, "1234567890"));
Assert.IsTrue(String.Equals(patient.IDs[0].Type.Text, "ID"));
Assert.IsTrue(String.Equals(patient.IDs[1].ID, "987654321"));
Assert.IsTrue(String.Equals(patient.IDs[1].Type.Text, "SSN"));
Assert.IsTrue(String.Equals(patient.Address[0].City, "Hooville"));
Assert.IsTrue(String.Equals(patient.Address[0].County, "Eggs and Ham"));
Assert.IsTrue(String.Equals(patient.Address[0].Line1, "123 Elm St."));
Assert.IsTrue(String.Equals(patient.Address[0].Line2, "Apt 4"));
Assert.IsTrue(String.Equals(patient.Address[0].PostalCode, "90210"));
Assert.IsTrue(String.Equals(patient.Address[0].State, "MI"));
Assert.IsTrue(String.Equals(patient.EMail[0].Value, "[email protected]"));
Assert.IsTrue(String.Equals(patient.Telephone[0].Value, "5558675309"));
ActorTypePerson person = (ActorTypePerson)patient.Item;
Assert.IsTrue(String.Equals(person.DateOfBirth.ExactDateTime, "0000/12/25"));
Assert.IsTrue(String.Equals(person.DateOfBirth.Age.Value, "2011"));
Assert.IsTrue(String.Equals(person.Gender.Text, "M"));
Assert.IsTrue(String.Equals(person.Name.CurrentName.Family.First(), "ONE"));
Assert.IsTrue(String.Equals(person.Name.CurrentName.Given.First(), "USER"));
Assert.IsTrue(String.Equals(person.Name.CurrentName.Middle.First(), "O"));
}
示例15: Should_clear_all_cache_strategies
public void Should_clear_all_cache_strategies()
{
var controllerName = NameHelper.Controller<AdminController>();
var policyContainers = new List<PolicyContainer>
{
TestDataFactory.CreateValidPolicyContainer(controllerName, "Index"),
TestDataFactory.CreateValidPolicyContainer(controllerName, "ListPosts"),
TestDataFactory.CreateValidPolicyContainer(controllerName, "AddPost")
};
var conventionPolicyContainer = new ConventionPolicyContainer(policyContainers.Cast<IPolicyContainerConfiguration>().ToList());
conventionPolicyContainer.Cache<RequireAnyRolePolicy>(Cache.PerHttpRequest);
// Act
conventionPolicyContainer.ClearCacheStrategies();
// Assert
var containers = policyContainers.ToList();
Assert.That(containers[0].CacheStrategies.Any(), Is.False);
Assert.That(containers[1].CacheStrategies.Any(), Is.False);
Assert.That(containers[2].CacheStrategies.Any(), Is.False);
}