本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.First方法的典型用法代码示例。如果您正苦于以下问题:C# List.First方法的具体用法?C# List.First怎么用?C# List.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.First方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckRecurringPayments_None_NewEntryForRecurring
public void CheckRecurringPayments_None_NewEntryForRecurring()
{
var repoSetup = new Mock<IPaymentRepository>();
var resultList = new List<Payment>();
var testList = new List<Payment>
{
new Payment
{
Id = 1,
Amount = 99,
ChargedAccountId = 2,
ChargedAccount = new Account {Id = 2},
Date = DateTime.Now.AddDays(-3),
RecurringPaymentId = 3,
RecurringPayment = new RecurringPayment
{
Id = 3,
Recurrence = (int) PaymentRecurrence.Daily,
ChargedAccountId = 2,
ChargedAccount = new Account {Id = 2},
Amount = 95
},
IsCleared = true,
IsRecurring = true
},
new Payment
{
Id = 2,
Amount = 105,
Date = DateTime.Now.AddDays(-3),
ChargedAccountId = 2,
ChargedAccount = new Account {Id = 2},
RecurringPaymentId = 4,
RecurringPayment = new RecurringPayment
{
Id = 4,
Recurrence = (int) PaymentRecurrence.Weekly,
ChargedAccountId = 2,
ChargedAccount = new Account {Id = 2},
Amount = 105
},
IsRecurring = true
}
};
repoSetup.Setup(x => x.Save(It.IsAny<Payment>()))
.Callback((Payment payment) => resultList.Add(payment));
repoSetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Payment>(testList));
repoSetup.Setup(x => x.LoadRecurringList(null)).Returns(testList);
new RecurringPaymentManager(repoSetup.Object).CheckRecurringPayments();
resultList.Any().ShouldBeTrue();
resultList.First().Amount.ShouldBe(95);
resultList.First().ChargedAccountId.ShouldBe(2);
resultList.First().RecurringPaymentId.ShouldBe(3);
}
示例2: ShouldFilterByGenre
public void ShouldFilterByGenre()
{
using (var session = _documentStore.OpenSession())
{
var repository = new Repository(session);
Enumerable.Range(1, 8).ToList().ForEach(i => repository.Create(new Book { Title = "Book " + i, Language = "Venda", Genre = "Poetry"}));
var book1 = new Book { Title = "Book 9", Language = "Zulu", AgeRange = "0-2", Genre = "Picture Books"};
repository.Create(book1);
var book2 = new Book { Title = "Book 10", Language = "Zulu", AgeRange = "3-5", Genre = "Fiction" };
repository.Create(book2);
session.SaveChanges();
Assert.AreEqual(10, repository.Count<Book>());
var expectedBooks = new List<Book> { book1 };
var booksController = new BooksController(repository);
var view = (ViewResult)booksController.Filter(new List<string>(), new List<string>(), new List<string> {"Picture Books"});
var filterInformation = (FilterInformation)view.Model;
var actualBooks = filterInformation.BookInformations.Select(bookInformation => bookInformation.Model).ToList();
Assert.AreEqual(1, actualBooks.Count());
Assert.AreEqual(expectedBooks.First().Language, actualBooks.First().Language);
Assert.AreEqual(expectedBooks.First().AgeRange, actualBooks.First().AgeRange);
Assert.AreEqual(expectedBooks.First().Genre, actualBooks.First().Genre);
Assert.AreEqual("Picture Books", filterInformation.Genres.First());
}
}
示例3: PropertiesTest
public void PropertiesTest()
{
var viewModel = Container.GetExportedValue<EmailListViewModel>();
List<Email> emails = new List<Email>();
emails.Add(new Email());
emails.Add(new Email());
Assert.IsNull(viewModel.Emails);
AssertHelper.PropertyChangedEvent(viewModel, x => x.Emails, () => viewModel.Emails = emails);
Assert.AreEqual(emails, viewModel.Emails);
Assert.IsNull(viewModel.SelectedEmail);
AssertHelper.PropertyChangedEvent(viewModel, x => x.SelectedEmail, () => viewModel.SelectedEmail = emails.First());
Assert.AreEqual(emails.First(), viewModel.SelectedEmail);
var emptyCommand = new DelegateCommand(() => { });
Assert.IsNull(viewModel.DeleteEmailCommand);
AssertHelper.PropertyChangedEvent(viewModel, x => x.DeleteEmailCommand, () => viewModel.DeleteEmailCommand = emptyCommand);
Assert.AreEqual(emptyCommand, viewModel.DeleteEmailCommand);
Assert.AreEqual("", viewModel.FilterText);
AssertHelper.PropertyChangedEvent(viewModel, x => x.FilterText, () => viewModel.FilterText = "abc");
Assert.AreEqual("abc", viewModel.FilterText);
}
示例4: PropertiesTest
public void PropertiesTest()
{
var viewModel = Container.GetExportedValue<ContactListViewModel>();
List<Contact> contacts = new List<Contact>()
{
new Contact(),
new Contact()
};
Assert.IsNull(viewModel.Contacts);
AssertHelper.PropertyChangedEvent(viewModel, x => x.Contacts, () => viewModel.Contacts = contacts);
Assert.AreEqual(contacts, viewModel.Contacts);
Assert.IsNull(viewModel.SelectedContact);
AssertHelper.PropertyChangedEvent(viewModel, x => x.SelectedContact, () => viewModel.SelectedContact = contacts.First());
Assert.AreEqual(contacts.First(), viewModel.SelectedContact);
var emptyCommand = new DelegateCommand(() => { });
Assert.IsNull(viewModel.DeleteContactCommand);
AssertHelper.PropertyChangedEvent(viewModel, x => x.DeleteContactCommand, () => viewModel.DeleteContactCommand = emptyCommand);
Assert.AreEqual(emptyCommand, viewModel.DeleteContactCommand);
Assert.AreEqual("", viewModel.FilterText);
AssertHelper.PropertyChangedEvent(viewModel, x => x.FilterText, () => viewModel.FilterText = "abc");
Assert.AreEqual("abc", viewModel.FilterText);
}
示例5: GenericComparerAsIComparer
public void GenericComparerAsIComparer()
{
List<int> ints = new List<int>(new[] { 10, 5, 2, 23, 7, 5, 3, 45, 23, 64, 25 });
ints.Sort(new GenericComparer<int>());
Assert.AreEqual(ints.Min(), ints.First());
Assert.AreEqual(ints.Max(), ints.Last());
ints.Sort(new GenericComparer<int>((i, i1) => Math.Sin(i) > Math.Sin(i1) ? -1 : Math.Sin(i) < Math.Sin(i1) ? 1 : 0));
Assert.AreEqual(64, ints.First());
Assert.AreEqual(5, ints.Last());
}
示例6: IndexShouldRenderInCorrectly
public void IndexShouldRenderInCorrectly()
{
var autoMapperConfig = new AutoMapperConfig();
autoMapperConfig.Execute(typeof(UserController).Assembly);
List<Platoon> Platoons = new List<Platoon>() { new Platoon() { Name = "Test", Id = 2, PlatoonCommander = new User() { FirstName = "Asd", LastName = "Asd", Id = "asd" } } };
var usersServiceMock = new Mock<IUsersService>();
usersServiceMock.Setup(x => x.GetById(It.IsAny<string>()))
.Returns(new User { FirstName = "Test", SquadId = 1 });
var squadsServiceMock = new Mock<ISquadsService>();
squadsServiceMock.Setup(x => x.GetById(It.IsAny<int>()))
.Returns(new Squad { Name = "Test" });
var platoonsServiceMock = new Mock<IPlatoonsService>();
platoonsServiceMock.Setup(x => x.GetAll())
.Returns(new List<Platoon>() { new Platoon() { Name = "Test", Id = 1, PlatoonCommander = new User() { FirstName = "Asd", LastName = "Asd", Id = "asd" } } }.AsQueryable());
var controller = new PlatoonAdministrationController(platoonsServiceMock.Object, squadsServiceMock.Object, usersServiceMock.Object);
controller.WithCallTo(x => x.Index())
.ShouldRenderView("Index")
.WithModel<PlatoonIndexModel>(
viewModel =>
{
Assert.AreNotEqual(Platoons.First().Id, viewModel.Platoons.First().Id);
}).AndNoModelErrors();
}
示例7: AddOrderEntryTest
public void AddOrderEntryTest()
{
List<Order> orders = new List<Order>();
List<BookType> bookTypeList = new List<BookType>();
NMock.Actions.InvokeAction saveOrUpdateAction = new NMock.Actions.InvokeAction(() => orders.Add(order));
orderManagementDaoMock.Expects.Any.MethodWith(x => x.SaveOrUpdate(order)).Will(saveOrUpdateAction);
bool isInList = false;
order.OrderEntries = new List<OrderEntry>();
oms.CreateNewOrder(order);
orderInformationDaoMock.Expects.Any.MethodWith(x => x.GetOrderById(order.Id)).WillReturn(orders.First(x => x.Id == order.Id));
getOrder = ois.GetOrderById(order.Id);
NMock.Actions.InvokeAction saveBookType = new NMock.Actions.InvokeAction(new Action(() => bookTypeList.Add(testBook)));
storehouseManagementDaoMock.Expects.Any.MethodWith(x => x.SaveBookType(testBook)).Will(saveBookType);
sms.SaveBookType(testBook);
booksInformationServiceMock.Expects.Any.MethodWith(x => x.GetBookTypeById(testBook.Id)).WillReturn(bookTypeList.FirstOrDefault(x => x.Id == testBook.Id));
oms.AddOrderEntry(order, testBook.Id, TEST_AMOUNT);
foreach (var item in order.OrderEntries)
{
if (item.Amount.Equals(TEST_AMOUNT) &&
item.BookType.Equals(testBook) &&
item.Price.Equals(testBook.Price)) isInList = true;
};
Assert.IsTrue(isInList);
}
示例8: Behaviour_should_also_work_with_method_calls
public void Behaviour_should_also_work_with_method_calls()
{
var SUT = new YakShayBus();
SUT.RegisterType<SomeTestClass>();
var resultingMessages = new List<Message>();
var msg = new
{
SomePartOfTheUID = "A",
AnotherPartOfTheUID = "B",
SomeFlag = true,
SomeString = "ABC"
};
SUT.Handle(
Message.FromAction(x => x.MethodToInvoke(SomePartOfTheUID: "A", AnotherPartOfTheUID: "B", SomeFlag: true, SomeString: "ABC"))
, x => resultingMessages.Add(x));
resultingMessages.Count.ShouldBe(1);
resultingMessages.First().ToFriendlyString().ShouldBe(new Message("OnMethodWasInvoked", new
{
SomePartOfTheUID = "A",
AnotherPartOfTheUID = "B",
SomeString = "ABC",
AnotherInt = 123
}).ToFriendlyString());
}
示例9: Service_Map_ExpenseReport_ExpenseReportModel_CalculateTotal
public void Service_Map_ExpenseReport_ExpenseReportModel_CalculateTotal()
{
// Arrange
int id = 1;
IMap<ExpenseReport> map = new Map<ExpenseReport>();
List<ExpenseReport> reports = new List<ExpenseReport>()
{
new ExpenseReport
{
Id = 1, Title = "Report One",
ExpenseItems = new List<ExpenseItem>()
{
new ExpenseItem { Id = 1, ExpenseAmount = 12.34m },
new ExpenseItem { Id = 1, ExpenseAmount = 12.34m }
}
}
};
decimal sum = reports.First().ExpenseItems.Sum(x => x.ExpenseAmount);
Mock<ExpenseContext> mockContext = new ExpenseContextBuilder()
.WithSet<ExpenseReport>(x => x.ExpenseReports, reports.AsQueryable())
.Build();
// Act
ExpenseReportQueryService service = new ExpenseReportQueryService(mockContext.Object, map);
var result = service.GetExpenseReportById(id);
// Assert
Assert.AreEqual(sum, result.ExpenseTotal);
}
示例10: TestMaxItemCount
public async Task TestMaxItemCount()
{
var nextItem = 0;
var pool = new PipelinedPool<int>(() => TaskPort.FromResult(++nextItem), null, new PipelinedPoolOptions
{
MaxRequestsPerItem = 10,
TargetItemCount = 2,
});
var items = new List<IPooledItem<int>>();
for (int i = 0; i < 20; ++i)
{
var task = pool.Borrow();
Assert.AreEqual(true, task.IsCompleted);
var item = await task;
items.Add(item);
}
Assert.AreEqual(20, items.Count);
Assert.AreEqual(10, items.Count(v => v.Item == 1));
Assert.AreEqual(10, items.Count(v => v.Item == 2));
var waiter = pool.Borrow();
Assert.AreEqual(false, waiter.IsCompleted);
items.First().Dispose();
Assert.AreEqual(true, waiter.IsCompleted);
foreach (var item in items.Skip(1))
{
item.Dispose();
}
waiter.Result.Dispose();
}
示例11: Can_Add_Order_Via_Controller
public void Can_Add_Order_Via_Controller()
{
//ARRANGE
List<Order> orders = new List<Order>();
Mock<IOrderRepository> mockOrder = new Mock<IOrderRepository>();
mockOrder.Setup(m => m.AddOrder(It.IsAny<Order>())).Returns((Order order) =>
{
if (orders.LastOrDefault() == null)
{
order.OrderID = 1;
}
else
{
order.OrderID = orders.Last().OrderID + 1;
}
orders.Add(order);
return true;
});
mockOrder.Setup(m => m.GetOrder(It.IsAny<int>())).Returns((int id) =>
{
return orders.Where(o => o.OrderID == id).FirstOrDefault();
});
OrderController target = new OrderController(mockOrder.Object);
//ACT
target.Index(new Order { Address = "lalala st.", Name = "lala", OrderDate = DateTime.Now });
target.Index(new Order { Address = "dadada st.", Name = "dada", OrderDate = DateTime.Now });
//ASSERT
Assert.IsNotNull(orders.Last());
Assert.AreEqual(orders.Last().Name, "dada");
Assert.AreEqual(orders.Last().OrderID, orders.First().OrderID + 1);
}
示例12: 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);
}
示例13: BookListViewModelBooksTest
public void BookListViewModelBooksTest()
{
List<Book> books = new List<Book>()
{
new Book() { Title = "The Fellowship of the Ring" },
new Book() { Title = "The Two Towers" }
};
MockBookListView bookListView = new MockBookListView();
IList<BookDataModel> bookDataModels = new SynchronizingCollection<BookDataModel, Book>(books, b => new BookDataModel(b, dummyCommand));
BookListViewModel bookListViewModel = new BookListViewModel(bookListView) { Books = bookDataModels };
Assert.AreEqual(bookDataModels, bookListViewModel.Books);
Assert.IsNull(bookListViewModel.SelectedBook);
Assert.IsFalse(bookListViewModel.SelectedBooks.Any());
// Select the first book
AssertHelper.PropertyChangedEvent(bookListViewModel, x => x.SelectedBook,
() => bookListViewModel.SelectedBook = bookDataModels.First());
Assert.AreEqual(books.First(), bookListViewModel.SelectedBook.Book);
bookListViewModel.AddSelectedBook(bookDataModels.First());
Assert.IsTrue(bookListViewModel.SelectedBooks.SequenceEqual(new[] { bookDataModels.First() }));
// Select both books
bookListViewModel.AddSelectedBook(bookDataModels.Last());
Assert.IsTrue(bookListViewModel.SelectedBooks.SequenceEqual(bookDataModels));
}
示例14: SeedMeals
private void SeedMeals(RestaurantsContext context, List<MealType> mealTypes)
{
var meals = new List<Meal>()
{
new Meal()
{
Name = "French salad",
Price = 5.40m,
Restaurant = new Restaurant()
{
Name = "Pri baba",
Owner = context.Users.FirstOrDefault(u => u.UserName == TestUserUsername),
Town = new Town() {Name = "Bracigovo"}
},
Type = mealTypes.First()
}
};
foreach (var meal in meals)
{
context.Meals.Add(meal);
}
context.SaveChanges();
}
示例15: ReaderWithHeaderTest
public void ReaderWithHeaderTest()
{
using (var reader = new CsvReader<StockValue>(
"csv-samples/IBM.csv",
containsHeader: true,
separator:',',
dateTimeFormat: "yyyyMMdd"))
{
var stockValues = new List<StockValue>();
StockValue value = null;
while ((value = reader.ReadObject()) != null)
{
if (value == null)
throw new NullReferenceException();
stockValues.Add(value);
}
Assert.AreEqual(473, stockValues.Count);
var firstValue = stockValues.First();
var lastValue = stockValues.Last();
Assert.AreEqual(new DateTime(2014, 1, 2), firstValue.DateTime);
Assert.AreEqual(185.529999M, firstValue.Close);
Assert.AreEqual(new DateTime(2015, 11, 16), lastValue.DateTime);
Assert.AreEqual(133.710007M, lastValue.Close);
}
}