public void DateTimePropertyAcccess_GetProperty_Adjusts_For_TimeZone(string propertyName, string timeZoneId) { //Arrange var dtPropertyAccess = new DateTimePropertyAccess(); var userTimeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId); var timeZoneProfileProperty = new ProfilePropertyDefinition(Constants.PORTAL_Zero) { PropertyName = "PreferredTimeZone", PropertyValue = timeZoneId }; var userProfile = new UserProfile(); userProfile.ProfileProperties.Add(timeZoneProfileProperty); var accessingUser = new UserInfo { Profile = userProfile }; var culture = CultureInfo.InvariantCulture; string expected = String.Empty; switch (propertyName) { case "current": expected = TimeZoneInfo.ConvertTime(DateTime.Now, userTimeZone).ToString("D", culture); break; case "now": expected = TimeZoneInfo.ConvertTime(DateTime.Now, userTimeZone).ToString("g", culture); break; case "system": expected = DateTime.Now.ToString("g", culture); break; case "utc": expected = DateTime.Now.ToUniversalTime().ToString("g", culture); break; } //Act bool propertyNotFound = false; string propertyValue = dtPropertyAccess.GetProperty(propertyName, "", culture, accessingUser, Scope.DefaultSettings, ref propertyNotFound); //Assert Assert.AreEqual(expected, propertyValue); }
public void DateTimePropertyAcccess_GetProperty_Sets_PropertyNotFound(string propertyName, bool expected) { // Arrange var dtPropertyAccess = new DateTimePropertyAccess(); var accessingUser = new UserInfo { Profile = new UserProfile { PreferredTimeZone = TimeZoneInfo.Local } }; // Act bool propertyNotFound = false; string propertyValue = dtPropertyAccess.GetProperty(propertyName, string.Empty, CultureInfo.InvariantCulture, accessingUser, Scope.DefaultSettings, ref propertyNotFound); // Assert Assert.AreEqual(expected, propertyNotFound); }
public void DateTimePropertyAcccess_GetProperty_Returns_Correct_String_Given_Format_And_Culture(string propertyName, string cultureName, string format) { //Arrange var dtPropertyAccess = new DateTimePropertyAccess(); var accessingUser = new UserInfo { Profile = new UserProfile { PreferredTimeZone = TimeZoneInfo.Local } }; var culture = new CultureInfo(cultureName); string expected = String.Empty; switch (propertyName) { case "current": expected = DateTime.Now.ToString(format, culture); break; case "now": expected = DateTime.Now.ToString(format, culture); break; case "system": expected = DateTime.Now.ToString(format, culture); break; case "utc": expected = DateTime.Now.ToUniversalTime().ToString(format, culture); break; } //Act bool propertyNotFound = false; string propertyValue = dtPropertyAccess.GetProperty(propertyName, format, culture, accessingUser, Scope.DefaultSettings, ref propertyNotFound); //Assert Assert.AreEqual(expected, propertyValue); }