本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# List.ToList方法的具体用法?C# List.ToList怎么用?C# List.ToList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.ToList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestIndex
public void TestIndex()
{
// Arrange
var movies = new List<Movie> {
new Movie {Title="Star Wars", Director="Lucas"},
new Movie {Title="Star Wars II", Director="Lucas"},
new Movie {Title="Star Wars III", Director="Lucas"}
};
var mockMovieRepository = new Mock<IMovieRepository>();
mockMovieRepository.Setup(r => r.ListAllMovies()).Returns(movies);
var controller = new HomeController(mockMovieRepository.Object);
var vm = new List<IndexViewModel>();
movies.ToList().ForEach(m => vm.Add(new IndexViewModel {
Id = m.Id,
Title = m.Title,
Director = m.Director
}));
// Act
var result = (ViewResult)controller.Index();
var model = (List<IndexViewModel>)result.Model;
// Assert
Assert.AreEqual(vm[0].Title, model[0].Title);
}
示例2: BubbleSort
List<int> BubbleSort(List<int> l)
{
var result = l.ToList();
swapped = true;
while (swapped)
{
i = 0;
swapped = false;
while (i < result.Count - 1)
{
if (result[i] > result[i + 1])
{
t = result[i];
result[i] = result[i + 1];
result[i + 1] = t;
swapped = true;
}
i = i + 1;
}
}
return result;
}
示例3: TestComponentAbilityFiltering
public void TestComponentAbilityFiltering()
{
// targeted test data
var provoke = new TestBattleAbility("Provoke", true, false, false);
var fire = new TestBattleAbility("Fire", true, false, false);
// Buffs test data
var protect = new TestBattleAbility("Protect", true, true, true);
var shell = new TestBattleAbility("Shell", true, true, true);
// Enabled test data
var water = new TestBattleAbility("Water", false, false, false);
var testData = new List<TestBattleAbility>
{
provoke,
protect,
shell,
fire,
water
};
// Create the desired outcome with water removed since
// it won't be enabled.
var desiredOutcome = testData.ToList();
desiredOutcome.Remove(water);
var ordering = testData
.Where(x => x.Enabled)
.Where(x => x.IsBuff && x.HasEffectWore || !x.IsBuff);
Assert.IsTrue(ordering.SequenceEqual(desiredOutcome));
}
示例4: DeleteTheBest
public void DeleteTheBest()
{
Random r = new Random();
List<int> values = new List<int>();
for (int i = 0; i < 100; i++)
{
values.Add(r.Next(100) - r.Next(100));
}
foreach (int value in values)
{
heap.Insert(value);
}
int deleteCount = r.Next(values.Count);
List<int> sortedValues = values.ToList();
sortedValues.Sort(comparision);
sortedValues.Reverse();
int expectedTheBestValue = sortedValues.Skip(deleteCount).FirstOrDefault();
for (int i = 0; i < deleteCount; i++)
{
Assert.IsTrue(heap.DeleteTheBest());
}
Assert.AreEqual(values.Count - deleteCount, heap.Count);
Assert.AreEqual(expectedTheBestValue, heap.GetTheBest());
}
示例5: OrderByNameDescendingTest
public void OrderByNameDescendingTest()
{
var expextedResult = new List<Employee>() { employeeB, employeeA, employeeC }.AsQueryable();
var result = employeeList.AsQueryable().SortListBy(x => x.FirstName, ListSortDirection.Descending);
Assert.IsTrue(expextedResult.ToList().SequenceEqual(result.ToList(), new EmployeeListComparer()));
}
示例6: EmptySequenceList
public void EmptySequenceList()
{
IList<Bid> expected = new List<Bid>();
IList<BiddingSequence> biddingSequences = new List<BiddingSequence>();
var result = BiddingConverter.Convert(biddingSequences);
CollectionAssert.AreEqual(expected.ToList(), result.ToList());
}
示例7: AddFieldsForReturnsErrorWhenEmptyFieldDisplayIsAdded
public void AddFieldsForReturnsErrorWhenEmptyFieldDisplayIsAdded()
{
// Setup
const string Tenant = "tenant";
var mockTenant = new Mock<Tenant>();
var metadata = new UDFMetadata { Name = "name", Display = string.Empty };
var mockTenantStore = new Mock<ITenantStore>();
mockTenantStore.Setup(m => m.GetTenant(Tenant)).Returns(mockTenant.Object);
IEnumerable<UDFMetadataError> errors = new List<UDFMetadataError>();
var udfDictionary = new UDFDictionary(mockTenantStore.Object);
// Act
var result = udfDictionary.AddFieldFor<TestExtension>(Tenant, metadata, out errors);
// Assert
Assert.IsFalse(result);
Assert.IsTrue(errors.Count() > 0);
Assert.AreEqual(UDFMetadataField.Display, errors.ToList()[0].Field);
Assert.AreEqual("Cannot be empty", errors.ToList()[0].Message);
}
示例8: TiposItemController_AgregarTipoDeItemAProyecto
public void TiposItemController_AgregarTipoDeItemAProyecto()
{
HelperTestSistema.LimpiarArchivoBD();
HelperTestSistema.IniciarServidor();
//Creamos 1 proyecto1 directamente en la BD con dos tipos de item
var tiposDeItemProyecto1 = HelperInstanciacionItems.GetTiposDeItem( "Proyecto 1", 2 );
var proyecto = HelperInstanciacionProyectos.GetProyectos( 1 )[0];
proyecto.AgregarTipoDeItem( tiposDeItemProyecto1[0] );
proyecto.AgregarTipoDeItem( tiposDeItemProyecto1[1] );
//Guardamos los objetos en la BD
using ( IContextoProceso contexto = new ContextoProceso( HelperTestSistema.ObjectFactory ) )
{
contexto.ContenedorObjetos.Store( proyecto );
}
HelperTestSistema.ReiniciarConexion();
//Creamos un tipo de item y lo agregamos al proyecto a traves de la API
var controller = new TiposItemController( HelperTestSistema.ObjectFactory );
//Obtenemos el 2 ya que tenemos que simular un nuevo tipo de item
var nuevoTipoItem = HelperInstanciacionItems.GetTiposDeItem( "Proyecto 1" ,3 )[2];
controller.Post( "P1", nuevoTipoItem );
HelperTestSistema.ReiniciarConexion();
//Obtenemos los datos directamente de la base de datos para verificarlos
var proyectosBD = new List<Proyecto>();
using ( IContextoProceso contexto = new ContextoProceso(HelperTestSistema.ObjectFactory) )
{
proyectosBD = (from Proyecto p in contexto.ContenedorObjetos select p).ToList();
}
HelperTestSistema.ReiniciarConexion();
HelperTestSistema.FinalizarServidor();
//Asserts
Assert.Inconclusive( "Refactorizar y terminar este test" );
//Debe haber un solo proyecto en la base de datos
Assert.AreEqual( 1, proyectosBD.ToList().Count );
//El proyecto debe tener 3 tipos de item
Assert.AreEqual( 3, proyectosBD[0].TiposDeItem.Count() );
//El tercer tipo de item debe ser el que agregamos
Assert.AreEqual( "Proyecto 1-Tipo de item de prueba 3", proyectosBD[0].TiposDeItem.ToList()[2].Descripcion );
}
示例9: GetAllSuperheroes_WhenThereAreSuperheroes
public void GetAllSuperheroes_WhenThereAreSuperheroes()
{
var superherosList = new List<Superhero>()
.AsQueryable();
Mock.Arrange(() => this.mockSuperheroes.Entities)
.Returns(superherosList);
var service = new SuperheroesService(this.mockUnitOfWork, this.mockSuperheroes, this.mockPowers, this.mockCities);
var superheroes = service.GetAllSuperheroes()
.ToList();
CollectionAssert.AreEqual(superherosList.ToList(), superheroes);
}
示例10: DatamodelTests
static DatamodelTests()
{
var binary = new byte[16];
new Random().NextBytes(binary);
var quat = Quaternion.Normalize(new Quaternion(1, 2, 3, 4)); // dmxconvert will normalise this if I don't!
TestValues_V1 = new List<object>(new object[] { "hello_world", 1, 1.5f, true, binary, null, System.Drawing.Color.Blue,
new Vector2(1,2), new Vector3(1,2,3), new Vector4(1,2,3,4), quat, new Matrix4x4(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16) });
TestValues_V2 = TestValues_V1.ToList();
TestValues_V2[5] = TimeSpan.FromMinutes(5) + TimeSpan.FromTicks(TimeSpan.TicksPerMillisecond / 2);
TestValues_V3 = TestValues_V1.Concat(new object[] { (byte)0xFF, (UInt64)0xFFFFFFFF }).ToList();
}
示例11: AutoMapperTest
public void AutoMapperTest()
{
List<User> users = new List<User>
{
new User("1","1",null),
new User("2","2",null)
};
Mapper.CreateMap<User, UserDTO>();
Mapper.AssertConfigurationIsValid();
List<UserDTO> userDtos = Mapper.Map<List<User>, List<UserDTO>>(users.ToList());
Assert.IsTrue(userDtos.Count == 2);
}
示例12: Search_Empty_Query_Expected_View_Result_Returned
public void Search_Empty_Query_Expected_View_Result_Returned()
{
// Arrange
string query = string.Empty;
var stubResultsExpected = new List<SearchResultItem>();
_mockSearchService.Setup(x => x.Search(query)).Returns(stubResultsExpected.ToList());
// Act
var result = _controller.Search(string.Empty);
var model = result.Model as SearchResultViewModel;
// Assert
model.SearchQuery.Should().Be(query, " because that was the query we entered");
model.Results.ShouldAllBeEquivalentTo(stubResultsExpected, " we expect the method to return the result from ISearchService unchanged");
}
示例13: DeckInitialisedWithCorrectCardsFromCardList
public void DeckInitialisedWithCorrectCardsFromCardList()
{
List<Card> cards = new List<Card>();
cards.Add(new Card() { Name = "TestCard1" });
cards.Add(new Card() { Name = "TestCard2" });
cards.Add(new Card() { Name = "TestCard2" });
cards.Add(new Card() { Name = "TestCard3" });
Deck deck = Deck.CreateFromCardList(cards);
CollectionAssert.AreEquivalent(
deck.Cards.ToList(),
cards.ToList(),
"Deck contains correct list of cards.");
}
示例14: Reverse
List<int> Reverse(List<int> l)
{
var result = l.ToList();
i = 0;
s = result.Count;
while (i < s)
{
t = result[i];
result.RemoveAt(i);
result.Insert(0, t);
i = i + 1;
}
return result;
}
示例15: SeveralTheatres_ListTheatres_ShouldReturnListedTheatres
public void SeveralTheatres_ListTheatres_ShouldReturnListedTheatres()
{
//Arrange
var database = new PerformanceDatabase();
//Act
database.AddTheatre("Theatre Gosho");
database.AddTheatre("Theatre Petka");
database.AddTheatre("Ivana Theatre");
var listed = database.ListTheatres();
var expected = new List<IEnumerable> { "Ivana Theatre", "Theatre Gosho", "Theatre Petka" };
//Assert
CollectionAssert.AreEqual(expected.ToList(), listed.ToList());
}