本文整理汇总了C#中System.DateTime.Should方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.Should方法的具体用法?C# DateTime.Should怎么用?C# DateTime.Should使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTime
的用法示例。
在下文中一共展示了DateTime.Should方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DateTimeExtensionsTestToSaml2Date
public void DateTimeExtensionsTestToSaml2Date()
{
var subject = new DateTime(2014, 03, 02, 22, 42, 54, DateTimeKind.Utc)
.ToLocalTime().ToSaml2DateTimeString();
subject.Should().Be("2014-03-02T22:42:54Z");
}
示例2: DateTimeExtensionsTests_ToSaml2DateStripsSecondFractions
public void DateTimeExtensionsTests_ToSaml2DateStripsSecondFractions()
{
var subject = new DateTime(2014, 07, 14, 16, 23, 47, 153, DateTimeKind.Utc)
.ToSaml2DateTimeString();
subject.Should().Be("2014-07-14T16:23:47Z");
}
示例3: VerifyBothNowValuesMatch
public void VerifyBothNowValuesMatch()
{
var custom = TimeObservations.PrimaryDateTime;
var customValue = new DateTime(custom.Year, custom.Month, custom.Day, custom.Hour, custom.Minute, custom.Second);
var system = TimeObservations.SecondaryDateTime;
var systemValue = new DateTime(system.Year, system.Month, system.Day, system.Hour, system.Minute, system.Second);
customValue.Should().Be(systemValue);
}
示例4: Should_Handle_Negative_Numbers
public void Should_Handle_Negative_Numbers()
{
var task = new Mock<ITask>();
var schedule = new Schedule(task.Object);
schedule.ToRunEvery(2).Months().On(-1);
var input = new DateTime(2000, 1, 1, 1, 23, 25);
var scheduledTime = schedule.CalculateNextRun(input);
var expectedTime = new DateTime(2000, 2, 28);
expectedTime.Should().Equal(scheduledTime.Date);
}
示例5: Should_Override_Existing_Minutes_And_Seconds_If_At_Method_Is_Called
public void Should_Override_Existing_Minutes_And_Seconds_If_At_Method_Is_Called()
{
var task = new Mock<ITask>();
var schedule = new Schedule(task.Object);
schedule.ToRunEvery(2).Months().On(1).At(3, 15);
var input = new DateTime(2000, 1, 1, 5, 23, 25);
var scheduledTime = schedule.CalculateNextRun(input);
var expectedTime = new DateTime(2000, 3, 1);
expectedTime.Should().Equal(scheduledTime.Date);
scheduledTime.Hour.Should().Equal(3);
scheduledTime.Minute.Should().Equal(15);
scheduledTime.Second.Should().Equal(0);
}
示例6: Should_succeed_when_asserting_nullable_datetime_value_with_a_value_to_have_a_value
public void Should_succeed_when_asserting_nullable_datetime_value_with_a_value_to_have_a_value()
{
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
DateTime? nullableDateTime = new DateTime(2016, 06, 04);
//-----------------------------------------------------------------------------------------------------------
// Act
//-----------------------------------------------------------------------------------------------------------
Action action = () => nullableDateTime.Should().HaveValue();
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
action.ShouldNotThrow();
}
示例7: When_nullable_datetimeoffset_value_with_a_value_to_have_a_value_it_should_succeed
public void When_nullable_datetimeoffset_value_with_a_value_to_have_a_value_it_should_succeed()
{
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
DateTimeOffset? nullableDateTime = new DateTime(2016, 06, 04);
//-----------------------------------------------------------------------------------------------------------
// Act
//-----------------------------------------------------------------------------------------------------------
Action action = () => nullableDateTime.Should().HaveValue();
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
action.ShouldNotThrow();
}
示例8: Should_fail_when_asserting_datetime_value_is_equal_to_the_different_value
public void Should_fail_when_asserting_datetime_value_is_equal_to_the_different_value()
{
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
var dateTime = new DateTime(2012, 03, 10);
var otherDateTime = new DateTime(2012, 03, 11);
//-----------------------------------------------------------------------------------------------------------
// Act
//-----------------------------------------------------------------------------------------------------------
Action act = () => dateTime.Should().Be(otherDateTime, "because we want to test the failure {0}", "message");
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.ShouldThrow<AssertFailedException>()
.WithMessage(
"Expected date and time to be <2012-03-11>*failure message, but found <2012-03-10>.", ComparisonMode.Wildcard);
}
示例9: DateTime
public void When_a_date_time_is_expected_to_have_a_date_part_that_is_the_same_as_a_fully_specified_date_time_but_it_doesnt_it_should_fail_with_the_correct_message()
{
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
var subject = new DateTime(2015, 1, 7, 12, 22, 13);
//-----------------------------------------------------------------------------------------------------------
// Act
//-----------------------------------------------------------------------------------------------------------
Action act = () => subject.Should().BeSameDateAs(new DateTime(2015, 2, 7, 12, 22, 13), "because we want to test the failure {0}", "message");
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.ShouldThrow<AssertFailedException>().WithMessage(
"Expected a date and time with date <2015-02-07> because we want to test the failure message, but found <2015-01-07 12:22:13>.");
}
示例10: When_a_date_time_is_expected_to_have_a_specified_date_part_but_it_doesnt_it_should_throw
public void When_a_date_time_is_expected_to_have_a_specified_date_part_but_it_doesnt_it_should_throw()
{
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
var subject = new DateTime(2009, 12, 31);
//-----------------------------------------------------------------------------------------------------------
// Act
//-----------------------------------------------------------------------------------------------------------
Action act = () => subject.Should().BeSameDateAs(new DateTime(2009, 12, 30));
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.ShouldThrow<AssertFailedException>().WithMessage(
"Expected a date and time with date <2009-12-30>, but found <2009-12-31>.");
}
示例11: When_asserting_subject_datetime_is_after_later_expected_datetime_should_throw
public void When_asserting_subject_datetime_is_after_later_expected_datetime_should_throw()
{
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
DateTime subject = new DateTime(2016, 06, 04);
DateTime expectation = new DateTime(2016, 06, 05);
//-----------------------------------------------------------------------------------------------------------
// Act
//-----------------------------------------------------------------------------------------------------------
Action act = () => subject.Should().BeAfter(expectation);
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.ShouldThrow<AssertFailedException>().WithMessage("Expected a date and time after <2016-06-05>, but found <2016-06-04>.");
}
示例12: When_asserting_subject_datetime_is_not_close_to_an_ealier_datetime_by_35ms_it_should_throw
public void When_asserting_subject_datetime_is_not_close_to_an_ealier_datetime_by_35ms_it_should_throw()
{
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
DateTime time = new DateTime(2016, 06, 04).At(12, 15, 31, 035);
DateTime nearbyTime = new DateTime(2016, 06, 04).At(12, 15, 31);
//-----------------------------------------------------------------------------------------------------------
// Act
//-----------------------------------------------------------------------------------------------------------
Action act = () => time.Should().NotBeCloseTo(nearbyTime, 35);
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.ShouldThrow<AssertFailedException>().WithMessage("Expected date and time to not be within 35 ms from <2016-06-04 12:15:31>, but found <2016-06-04 12:15:31.035>.");
}
示例13: When_asserting_subject_datetime_is_before_the_same_datetime_it_should_throw
public void When_asserting_subject_datetime_is_before_the_same_datetime_it_should_throw()
{
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
DateTime expected = new DateTime(2016, 06, 04);
DateTime subject = new DateTime(2016, 06, 04);
//-----------------------------------------------------------------------------------------------------------
// Act
//-----------------------------------------------------------------------------------------------------------
Action act = () => subject.Should().BeBefore(expected);
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.ShouldThrow<AssertFailedException>().WithMessage("Expected a date and time before <2016-06-04>, but found <2016-06-04>.");
}
示例14: When_two_date_times_are_equal_but_the_kinds_differ_it_should_still_succeed
public void When_two_date_times_are_equal_but_the_kinds_differ_it_should_still_succeed()
{
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
DateTime dateTimeA = new DateTime(2014, 4, 20, 9, 11, 0, DateTimeKind.Unspecified);
DateTime dateTimeB = new DateTime(2014, 4, 20, 9, 11, 0, DateTimeKind.Utc);
//-----------------------------------------------------------------------------------------------------------
// Act
//-----------------------------------------------------------------------------------------------------------
Action action = () =>
dateTimeA.Should().Be(dateTimeB);
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
action.ShouldNotThrow();
}
示例15: Should_support_chaining_constraints_with_and
public void Should_support_chaining_constraints_with_and()
{
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
DateTimeOffset yesterday = new DateTime(2016, 06, 04).AddDays(-1);
DateTimeOffset? nullableDateTime = new DateTime(2016, 06, 04);
//-----------------------------------------------------------------------------------------------------------
// Act
//-----------------------------------------------------------------------------------------------------------
Action action = () =>
nullableDateTime.Should()
.HaveValue()
.And
.BeAfter(yesterday);
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
action.ShouldNotThrow();
}