本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Last方法的典型用法代码示例。如果您正苦于以下问题:C# List.Last方法的具体用法?C# List.Last怎么用?C# List.Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.Last方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Result_is_updated_after_Insert
public void Result_is_updated_after_Insert()
{
var subject = new ObservableCollection<int>(new [] { 10, 11, 12, 11, 12, 10, 12, 17 });
var result = subject.ToQueryable().Distinct().ToObservable();
var eventList = new List<NotifyCollectionChangedEventArgs>();
result.CollectionChanged += (s, e) => eventList.Add(e);
Assert.IsInstanceOfType(result, typeof(IQueryableObservableCollection<int>));
subject.Insert(2, 10);
EnumerableAssert.AreEqual(result, 10, 11, 12, 17);
Assert.AreEqual(0, eventList.Count);
subject.Insert(1, 11);
EnumerableAssert.AreEqual(result, 10, 11, 12, 17);
Assert.AreEqual(0, eventList.Count);
subject.Insert(1, 12);
EnumerableAssert.AreEqual(result, 10, 12, 11, 17);
Assert.AreEqual(1, eventList.Count);
Assert.AreEqual(NotifyCollectionChangedAction.Move, eventList.Last().Action);
subject.Insert(0, 17);
EnumerableAssert.AreEqual(result, 17, 10, 12, 11);
Assert.AreEqual(2, eventList.Count);
Assert.AreEqual(NotifyCollectionChangedAction.Move, eventList.Last().Action);
}
示例2: 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);
}
示例3: VerifyTerminalVelocityReached
public void VerifyTerminalVelocityReached()
{
List<double> velocities = new List<double> { 0 };
const int MAX_ITER = 10000;
while (velocities.Count < MAX_ITER)
velocities.Add(VelocitySimulation.CalculateNewVelocity(velocities.Last()));
Assert.IsTrue(Math.Abs(velocities.Skip(MAX_ITER - 100).Take(100).Average() - velocities.Last()) < 0.001);
}
示例4: 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());
}
示例5: PostNewsItemWithValidDataShouldSucceed
public void PostNewsItemWithValidDataShouldSucceed()
{
var news = new List<NewsItem>
{
new NewsItem
{
Title = "FirstNews",
Content = "FirstNewsContent",
PublishDate = DateTime.Now,
UserId = "2",
User = new ApplicationUser() {UserName = "Birko" }
},
new NewsItem
{
Title = "SecondNews",
Content = "SecondNewsContent",
PublishDate = DateTime.Now.AddDays(-3),
UserId = "2",
User = new ApplicationUser() { UserName = "Birko" }
},
new NewsItem
{
Title = "ThirdNews",
Content = "ThirdNewsContent",
PublishDate = DateTime.Now.AddDays(-10),
UserId = "2",
User = new ApplicationUser() {UserName = "Kapka"}
}
};
var dataMock = new Mock<INewsData>();
dataMock.Setup(r => r.News).Returns(this.GetMockedNewsItem(news));
var controller = new NewsController(dataMock.Object);
this.SetupController(controller, "NewsController");
var newNewsItem = new NewsItemOutputModel()
{
Title = "ThirdNews",
Content = "ThirdNewsContent",
PublishDate = DateTime.Now.AddDays(8)
};
var result = controller.Post(newNewsItem).ExecuteAsync(new CancellationToken()).Result;
Assert.AreEqual(HttpStatusCode.Created, result.StatusCode);
Assert.AreEqual(newNewsItem.Title, news.Last().Title);
Assert.AreEqual(newNewsItem.Content, news.Last().Content);
Assert.IsNotNull(news.Last().PublishDate);
}
示例6: 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);
}
}
示例7:
public void Progressでは_Reportが呼ばれるたびにProgressChangedイベントが起こる()
{
var progress = new IteratorTasks.Progress<int>();
var reportedItems = new List<int>();
progress.ProgressChanged += i =>
{
reportedItems.Add(i);
};
var t = Task.Run<int>(c => 進捗報告付きのコルーチン(c, progress));
var scheduler = Task.DefaultScheduler;
// RunOnce 仕様のために、最初の1回だけ特殊(Update より前に Report 呼ばれる)
// テスト仕様的には変だし何とかしたいけども
scheduler.Update();
for (int i = 1; i < 100; i++)
{
Assert.AreEqual(i, reportedItems.Count);
scheduler.Update();
Assert.AreEqual(i + 1, reportedItems.Count);
Assert.AreEqual(i, reportedItems.Last());
}
}
示例8: SupportVectorMachinePerformanceTest
public void SupportVectorMachinePerformanceTest() {
ex = null;
var cv = new CrossValidation();
cv.Algorithm = new SupportVectorRegression();
var rand = new HeuristicLab.Random.MersenneTwister();
double[,] data = GenerateData(1000, rand);
List<string> variables = new List<string>() { "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "y" };
Dataset ds = new Dataset(variables, data);
cv.Problem.ProblemDataParameter.ActualValue = new RegressionProblemData(ds, variables.Take(10), variables.Last());
cv.Folds.Value = 5;
cv.SamplesStart.Value = 0;
cv.SamplesEnd.Value = 999;
cv.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(cv_ExceptionOccurred);
cv.Stopped += new EventHandler(cv_Stopped);
cv.Prepare();
cv.Start();
trigger.WaitOne();
if (ex != null) throw ex;
TestContext.WriteLine("Runtime: {0}", cv.ExecutionTime.ToString());
}
示例9: LendToViewModelLendToTest
public void LendToViewModelLendToTest()
{
Book book = new Book() { Title = "The Fellowship of the Ring" };
List<Person> persons = new List<Person>()
{
new Person() { Firstname = "Harry" },
new Person() { Firstname = "Ron" }
};
MockLendToView lendToView = new MockLendToView();
AssertHelper.ExpectedException<ArgumentNullException>(() => new LendToViewModel(lendToView, null, null));
AssertHelper.ExpectedException<ArgumentNullException>(() => new LendToViewModel(lendToView, book, null));
LendToViewModel lendToViewModel = new LendToViewModel(lendToView, book, persons);
Assert.AreEqual(book, lendToViewModel.Book);
Assert.AreEqual(persons, lendToViewModel.Persons);
// Show the dialog
object owner = new object();
Action<MockLendToView> showDialogAction = (view) =>
{
Assert.AreEqual("", LendToViewModel.Title);
Assert.IsTrue(lendToView.IsVisible);
Assert.AreEqual(owner, lendToView.Owner);
// Check the default values
Assert.IsTrue(lendToViewModel.IsLendTo);
Assert.IsFalse(lendToViewModel.IsWasReturned);
Assert.AreEqual(persons.First(), lendToViewModel.SelectedPerson);
// Select the last person: Lend to Ron
AssertHelper.PropertyChangedEvent(lendToViewModel, x => x.SelectedPerson, () =>
lendToViewModel.SelectedPerson = persons.Last());
// Press Ok button
lendToViewModel.OkCommand.Execute(null);
};
lendToView.ShowDialogAction = showDialogAction;
Assert.IsTrue(lendToViewModel.ShowDialog(owner));
Assert.IsFalse(lendToView.IsVisible);
Assert.AreEqual(persons.Last(), lendToViewModel.SelectedPerson);
}
示例10: ShouldReturnRoleItems
public void ShouldReturnRoleItems()
{
var expected = new List<string>() { "ItemOne", "ItemTwo" };
var actual = _dashboardMappingsProvider.GetRoleItems("Admin");
Assert.AreEqual(expected.First(), actual.First());
Assert.AreEqual(expected.Last(), actual.Last());
}
示例11: HasChangesChangedAfterSave
public async Task HasChangesChangedAfterSave() {
var em1 = await TestFns.NewEm(_serviceName);
var eventArgsList = new List<EntityManagerHasChangesChangedEventArgs>();
em1.HasChangesChanged += (s, e) => {
eventArgsList.Add(e);
};
var emp = em1.CreateEntity<Employee>();
emp.FirstName = "Test Fn";
emp.LastName = "Test Ln";
Assert.IsTrue(eventArgsList.Count == 1);
Assert.IsTrue(eventArgsList.Last().HasChanges);
Assert.IsTrue(em1.HasChanges());
var sr1 = await em1.SaveChanges();
Assert.IsTrue(sr1.Entities.Count == 1);
Assert.IsTrue(eventArgsList.Count == 2);
Assert.IsTrue(!eventArgsList.Last().HasChanges);
Assert.IsTrue(!em1.HasChanges());
}
示例12: GetSequence
public int[] GetSequence(int length)
{
List<int> output = new List<int>();
output.Add(GetFirst());
while (output.Count < length)
{
output.Add(GetNext(output.Last()));
}
return output.ToArray();
}
示例13: HasChangesChangedAfterSave
public async Task HasChangesChangedAfterSave() {
var em1 = await TestFns.NewEm(_serviceName);
var hccArgs = new List<EntityManagerHasChangesChangedEventArgs>();
em1.HasChangesChanged += (s, e) => {
hccArgs.Add(e);
};
var emp = new Employee() { FirstName = "Test_Fn", LastName = "Test_Ln" };
em1.AddEntity(emp);
Assert.IsTrue(hccArgs.Count == 1);
Assert.IsTrue(hccArgs.Last().HasChanges == true);
Assert.IsTrue(em1.HasChanges());
var sr = await em1.SaveChanges();
Assert.IsTrue(sr.Entities.Count == 1);
Assert.IsTrue(hccArgs.Count == 2);
Assert.IsTrue(hccArgs.Last().HasChanges == false);
Assert.IsTrue(em1.HasChanges() == false);
}
示例14: MeasurementTracker_Track_Ends_Session
public void MeasurementTracker_Track_Ends_Session()
{
var actual = new List<Uri>();
var sessionManager = MeasurementTestHelpers.CreateSessionManager();
var tracker = new MeasurementTracker(MeasurementTestHelpers.Configuration, sessionManager, MeasurementTestHelpers.CreateEnvironment(), actual.Add);
tracker.Track(new ScreenViewActivity("Testing") { EndSession = true });
Assert.AreEqual(SessionStatus.Ending, sessionManager.SessionStatus);
StringAssert.Contains(actual.Last().OriginalString, "sc=end");
}
示例15: TestCircularRefs
public void TestCircularRefs()
{
var list = new List<TestMan>
{
new TestMan {Name = "Serg", Age = 34},
new TestMan {Name = "Julia", Age = 32}
};
list.First().Parent = list.Last();
list.Last().Parent = list.First();
_storage.Put("list", list);
var result = _storage.Get<List<TestMan>>("list");
Assert.IsNotNull(result);
Assert.AreEqual(2, result.Count);
Assert.AreEqual("Serg", result.First().Name);
Assert.AreEqual(34, result.First().Age);
Assert.AreEqual(result.First(), result.Last().Parent);
Assert.AreEqual(result.Last(), result.First().Parent);
}