本文整理汇总了C#中Time.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# Time.Execute方法的具体用法?C# Time.Execute怎么用?C# Time.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Time
的用法示例。
在下文中一共展示了Time.Execute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormattedTime
public void FormattedTime()
{
Time task = new Time();
task.BuildEngine = new MockBuild();
// test without the optional Format property
Assert.IsNull(task.Format, @"Format not null");
Assert.IsNull(task.FormattedTime, @"Formatted time not null");
Assert.IsTrue(task.Execute(), @"Time task without Format failed");
Assert.IsNull(task.Format, @"Format not null after executing task");
DateTime time = task.DateTimeValue;
Assert.IsNotNull(task.FormattedTime, @"Formatted time null after executing task");
task.Log.LogMessage(MessageImportance.Low, "Time without format: \"{0}\" (local)", task.FormattedTime);
Assert.AreEqual(time.ToString(DateTimeFormatInfo.InvariantInfo), task.FormattedTime,
@"Wrong default local time");
// the .Now property has a limited resolution
// according to ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref2/html/P_System_DateTime_Now.htm
// therefore wait some time to ensure we get a different value
// when executing a second time
Thread.Sleep(1000);
// second execute must yield another time stamp
Assert.IsTrue(task.Execute(), @"Time task without Format failed in second execution");
task.Log.LogMessage(MessageImportance.Low, "Time without format: \"{0}\" (local)", task.FormattedTime);
Assert.AreNotEqual(time, task.DateTimeValue, @"Time doesn't change with second execution");
// specify the format
task.Format = @"yyyyMMddHHmmss";
task.Kind = System.DateTimeKind.Utc.ToString();
Assert.IsTrue(task.Execute(), @"Time task with Format failed");
task.Log.LogMessage(MessageImportance.Low, "Time with format: \"{0}\" (UTC)", task.FormattedTime);
Assert.AreEqual(task.Format.Length, task.FormattedTime.Length, @"Wrong time length");
}
示例2: TimeExecute
public void TimeExecute()
{
Time task = new Time();
task.BuildEngine = new MockBuild();
Assert.IsTrue(task.Execute(), "Execute Failed!");
}