public void Should_get_default_value_from_assets_field() { var field = new AssetsField(1, "1", Partitioning.Invariant, new AssetsFieldProperties()); Assert.Equal(new JArray(), DefaultValueFactory.CreateDefaultValue(field, Now)); }
public void Should_get_default_value_from_json_field() { var field = Fields.Json(1, "1", Partitioning.Invariant, new JsonFieldProperties()); Assert.Equal(new JObject(), DefaultValueFactory.CreateDefaultValue(field, Now)); }
public void Should_get_default_value_from_geolocation_field() { var field = new GeolocationField(1, "1", Partitioning.Invariant, new GeolocationFieldProperties()); Assert.Equal(JValue.CreateNull(), DefaultValueFactory.CreateDefaultValue(field, Now)); }
public void Should_get_default_value_from_tags_field() { var field = Fields.Tags(1, "1", Partitioning.Invariant, new TagsFieldProperties()); Assert.Equal(JsonValue.Array(), DefaultValueFactory.CreateDefaultValue(field, now)); }
public void Should_get_default_value_from_string_field() { var field = new StringField(1, "1", Partitioning.Invariant, new StringFieldProperties { DefaultValue = "default" }); Assert.Equal("default", DefaultValueFactory.CreateDefaultValue(field, Now)); }
public void Should_get_default_value_from_number_field() { var field = new NumberField(1, "1", Partitioning.Invariant, new NumberFieldProperties { DefaultValue = 12 }); Assert.Equal(12, DefaultValueFactory.CreateDefaultValue(field, Now)); }
public void Should_get_default_value_from_datetime_field_when_set_to_now() { var field = new DateTimeField(1, "1", Partitioning.Invariant, new DateTimeFieldProperties { CalculatedDefaultValue = DateTimeCalculatedDefaultValue.Now }); Assert.Equal("2017-10-12T16:30:10Z", DefaultValueFactory.CreateDefaultValue(field, Now)); }
public void Should_get_default_value_from_datetime_field() { var field = new DateTimeField(1, "1", Partitioning.Invariant, new DateTimeFieldProperties { DefaultValue = FutureDays(15) }); Assert.Equal(FutureDays(15).ToString(), DefaultValueFactory.CreateDefaultValue(field, Now)); }
public void Should_get_default_value_from_boolean_field() { var field = new BooleanField(1, "1", Partitioning.Invariant, new BooleanFieldProperties { DefaultValue = true }); Assert.Equal(true, DefaultValueFactory.CreateDefaultValue(field, Now)); }
public void Should_get_default_value_from_datetime_field_when_set_to_today() { var field = new DateTimeField(1, "1", Partitioning.Invariant, new DateTimeFieldProperties { CalculatedDefaultValue = DateTimeCalculatedDefaultValue.Today }); Assert.Equal(Now.ToString().Substring(10), DefaultValueFactory.CreateDefaultValue(field, Now)); }
public void Should_get_default_value_from_datetime_field_when_set_to_today() { var field = Fields.DateTime(1, "1", Partitioning.Invariant, new DateTimeFieldProperties { CalculatedDefaultValue = DateTimeCalculatedDefaultValue.Today }); Assert.Equal(JsonValue.Create("2017-10-12T00:00:00Z"), DefaultValueFactory.CreateDefaultValue(field, now)); }
[FriendAccessAllowed] // Built into Base, also used by Framework. internal object GetDefaultValue(DependencyObject owner, DependencyProperty property) { Debug.Assert(owner != null && property != null, "Caller must provide owner and property or this method will throw in the event of a cache miss."); // If we are not using a DefaultValueFactory (common case) // just return _defaultValue DefaultValueFactory defaultFactory = _defaultValue as DefaultValueFactory; if (defaultFactory == null) { return(_defaultValue); } // If the owner is Sealed it must not have a cached Freezable default value, // regardless of whether or not the owner is a Freezable. The reason // for this is that a default created using the FreezableDefaultValueFactory // will attempt to set itself as a local value if it is changed. Since the owner // is Sealed this will throw an exception. // // The solution to this if the owner is a Freezable is to toss out all cached // default values when we Seal. If the owner is not a Freezable we'll promote // the value to locally cached. Either way no Sealed DO can have a cached // default value, so we'll return the frozen default value instead. if (owner.IsSealed) { return(defaultFactory.DefaultValue); } // See if we already have a valid default value that was // created by a prior call to GetDefaultValue. object result = GetCachedDefaultValue(owner, property); if (result != DependencyProperty.UnsetValue) { // When sealing a DO we toss out all the cached values (see DependencyObject.Seal()). // We technically only need to throw out cached values created via the // FreezableDefaultValueFactory, but it's more consistent this way. Debug.Assert(!owner.IsSealed, "If the owner is Sealed we should not have a cached default value"); return(result); } // Otherwise we need to invoke the factory to create the DefaultValue // for this property. result = defaultFactory.CreateDefaultValue(owner, property); // Default value validation ensures that default values do not have // thread affinity. This is because a default value is typically // stored in the shared property metadata and handed out to all // instances of the owning DependencyObject type. // // DefaultValueFactory.CreateDefaultValue ensures that the default // value has thread-affinity to the current thread. We can thus // skip that portion of the default value validation by calling // ValidateFactoryDefaultValue. Debug.Assert(!(result is DispatcherObject) || ((DispatcherObject)result).Dispatcher == owner.Dispatcher); property.ValidateFactoryDefaultValue(result); // Cache the created DefaultValue so that we can consistently hand // out the same default each time we are asked. SetCachedDefaultValue(owner, property, result); return(result); }