public void EqualityTest() { // ReSharper disable SuspiciousTypeConversion.Global var time0 = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); var time1 = new DateTime(2015, 12, 31, 0, 0, 0, DateTimeKind.Utc); var range0 = new DateTimeRange(time0, time1); var range1 = new DateTimeRange(time0, time1); var range2 = new DateTimeRange(new DateTime(1999, 12, 31, 0, 0, 0, DateTimeKind.Utc), time1); var range3 = new DateTimeRange(time0, new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc)); // Equals(DateTimeRange) Assert.IsTrue(range0.Equals(range0)); Assert.IsTrue(range0.Equals(range1)); Assert.IsFalse(range0.Equals(range2)); Assert.IsFalse(range0.Equals(range3)); // Equals(object) Assert.IsTrue(range0.Equals((object)range0)); Assert.IsTrue(range0.Equals((object)range1)); Assert.IsFalse(range0.Equals((object)range2)); Assert.IsFalse(range0.Equals((object)range3)); Assert.IsFalse(range0.Equals(null)); Assert.IsFalse(range0.Equals(range0.ToString())); // == operator Assert.IsTrue(range0 == range1); Assert.IsFalse(range0 == range2); Assert.IsFalse(range0 == range3); // != operator Assert.IsFalse(range0 != range1); Assert.IsTrue(range0 != range2); Assert.IsTrue(range0 != range3); // ReSharper restore SuspiciousTypeConversion.Global }
public void Should_BeEqual() { var d1 = new DateTimeRange(Now, Now.AddDays(1)); var d2 = new DateTimeRange(Now, Now.AddDays(1)); var d3 = new DateTimeRange(Now, Now.AddDays(2)); d1.Equals(d2).Should().BeTrue(); d1.Equals(d3).Should().BeFalse(); }
public void EqualityComparer_ShouldReturnValidResult() { // Arrange. var start = new DateTime(2001, 1, 1, 1, 0, 0, 0, DateTimeKind.Local); var tomorrow = start.AddDays(1); var nextWeek = start.AddDays(7); var targetOne = new DateTimeRange(start, tomorrow); var targetTwo = new DateTimeRange(start, tomorrow); var targetThree = new DateTimeRange(start, nextWeek); // Act. var resultOne = targetOne.Equals(targetTwo); var resultTwo = targetTwo.Equals(targetThree); var resultThree = targetTwo == targetOne; var resultFour = targetThree == targetOne; var resultFive = targetOne != targetThree; var resultSix = targetTwo != targetOne; // Assert. resultOne.Should().BeTrue(); resultTwo.Should().BeFalse(); resultThree.Should().BeTrue(); resultFour.Should().BeFalse(); resultFive.Should().BeTrue(); resultSix.Should().BeFalse(); }
public void Equals_SameValueIsEqual() { //Act var target = new DateTimeRange(new DateTime(2011, 10, 26, 1, 2, 3), new DateTime(2011, 10, 26, 10, 11, 12)); var actual = target.Equals(target); //Assert actual.Should().BeTrue(); }
public void Equals_DifferentRangesAreDifferent() { //Act var target1 = new DateTimeRange(new DateTime(2011, 10, 26, 1, 2, 3), new DateTime(2011, 10, 26, 10, 11, 12)); var target2 = new DateTimeRange(new DateTime(2011, 10, 25, 2, 3, 4), new DateTime(2011, 10, 25, 11, 12, 13)); var actual = target1.Equals(target2); //Assert actual.Should().BeFalse(); }
public void EqualsWrongTypeReturnsFalseInsteadOfException(int startDayOffset, int endDayOffset) { // arrange var range = new DateTimeRange(DateTime.Now.AddDays(startDayOffset), DateTime.Now.AddDays(endDayOffset)); // act var isEqual = range.Equals(34); // assert isEqual.Should().BeFalse(); }
public void DateTimeRange_Is_Equal() { // Arrange DateTimeRange timeRange1 = new DateTimeRange(new DateTime(2018, 6, 16), new DateTime(2018, 6, 18)); DateTimeRange timeRange2 = new DateTimeRange(new DateTime(2018, 6, 16), new DateTime(2018, 6, 18)); // Act bool result = timeRange1.Equals(timeRange2); // Assert Assert.True(result); }
public void DateTimeRange_One_Instance_Is_Null() { // Arrange DateTimeRange timeRange1 = new DateTimeRange(new DateTime(2018, 6, 16), new DateTime(2018, 6, 18)); DateTimeRange timeRange2 = null; // Act bool result = timeRange1.Equals(timeRange2); // Assert Assert.False(result); }
public void EqualsUnequalBoxedTypeReturnsFalse(int startDayOffset, int endDayOffset) { // arrange var range = new DateTimeRange(DateTime.Now.AddDays(startDayOffset), DateTime.Now.AddDays(endDayOffset)); object range2 = new DateTimeRange(DateTime.MinValue, DateTime.MaxValue); // act var isEqual = range.Equals(range2); // assert isEqual.Should().BeFalse(); }
public void SameRangeReturnsTrue() { // arrange var range1 = new DateTimeRange(DateTime.Now.AddDays(-30), DateTime.Now.AddDays(30)); var range2 = new DateTimeRange(DateTime.Now.AddDays(-30), DateTime.Now.AddDays(30)); // act var isEqual = range1.Equals(range2); // assert isEqual.Should().BeTrue(); }
public void Equals_IdenticalRangesAreEqual() { var start = new DateTime(2011, 10, 26, 1, 2, 3); var end = new DateTime(2011, 10, 26, 10, 11, 12); //Act var target1 = new DateTimeRange(start, end); var target2 = new DateTimeRange(start, end); var actual = target1.Equals(target2); //Assert actual.Should().BeTrue(); }
/// <summary> /// Returns a list of Exchange users, provides free busy times and /// appointments if available within the date range. /// </summary> /// <param name="ldapAttribute">Parameter to search upon</param> /// <param name="utcRange">DateRange for search</param> /// <param name="searchTerms">Search terms to search exchange for</param> /// <returns></returns> public ExchangeUserDict Search( string ldapAttribute, DateTimeRange utcRange, params string[] searchTerms) { if (utcRange.Equals(DateTimeRange.Full)) { throw new Exception("Must specify a time range"); } /* Create the network credentials and WebDav resources needed for user */ ExchangeUserDict activeDirectoryResults = QueryActiveDirectoryByAttribute(ldapAttribute, searchTerms); /* Assign user free busy times if any users were returned */ if (activeDirectoryResults != null && activeDirectoryResults.Count > 0) { GetCalendarInfoForUsers(activeDirectoryResults, utcRange); } return(activeDirectoryResults); }