Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
 public MockCilRuntimeEnvironment(ModuleDefinition module, bool is32Bit)
 {
     Is32Bit            = is32Bit;
     Module             = module ?? throw new ArgumentNullException(nameof(module));
     CliMarshaller      = new DefaultCliMarshaller(this);
     ValueFactory       = new DefaultValueFactory(module, is32Bit);
     StaticFieldFactory = new StaticFieldFactory(ValueFactory);
 }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
        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));
        }
Ejemplo n.º 8
0
        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));
        }
Ejemplo n.º 9
0
        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));
        }
Ejemplo n.º 10
0
        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));
        }
Ejemplo n.º 11
0
        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));
        }
Ejemplo n.º 12
0
        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));
        }
Ejemplo n.º 13
0
            static MyValueFactory()
            {
                DefaultValueFactory.Init(types, class2type);

                mt_add.PutValidator(mf_x, Validator_int.Get(0));
                mt_add.PutValidator(mf_y, Validator_int.Get(0));
                mt_add.PutValidator(DefaultValueFactory._mf__messageId, Validator_long.Get(0));

                mt_add_result.PutValidator(mf_result, Validator_int.Get(0));
                mt_add_result.PutValidator(DefaultValueFactory._mf__messageId, Validator_long.Get(0));
                mt_add_result.PutValidator(DefaultValueFactory._mf__inReplyTo, Validator_long.Get(0));
            }
Ejemplo n.º 14
0
        public void SetUpBeforeClass()
        {
            vf = new MyValueFactory();
            ps = new MyPacketSource();
            mh = new MyMessageHandler();
            Resources res = new Resources();

            res.Add(TransportConsts.VALUE_FACTORY, vf);
            m = new Messagizer(ps, "foo:?Messagizer.format=binary", res);
            m.SetSession(mh);
            Console.WriteLine();
            Console.Write("TestMessagizer");
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates a new instance of the <see cref="CilVirtualMachine"/>.
        /// </summary>
        /// <param name="module">The module in which the CIL runs in.</param>
        /// <param name="instructions">The instructions to emulate..</param>
        /// <param name="is32Bit">Indicates whether the virtual machine should run in 32-bit mode or in 64-bit mode.</param>
        public CilVirtualMachine(ModuleDefinition module, IStaticInstructionProvider <CilInstruction> instructions, bool is32Bit)
        {
            Module       = module ?? throw new ArgumentNullException(nameof(module));
            Instructions = instructions ?? throw new ArgumentNullException(nameof(instructions));
            Architecture = instructions.Architecture;

            ValueFactory = new DefaultValueFactory(module, is32Bit);

            Is32Bit            = is32Bit;
            Status             = VirtualMachineStatus.Idle;
            CurrentState       = new CilProgramState(ValueFactory);
            Dispatcher         = new DefaultCilDispatcher();
            CliMarshaller      = new DefaultCliMarshaller(this);
            MethodInvoker      = new ReturnUnknownMethodInvoker(ValueFactory);
            StaticFieldFactory = new StaticFieldFactory(ValueFactory);
            _services[typeof(ICilRuntimeEnvironment)] = this;
        }
Ejemplo n.º 16
0
        static MyValueFactoryCuae()
        {
            DefaultValueFactory.Init(types, class2type);

            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit.SetAsyncMode(AsyncMode.QUEUED);
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit.SetResult(_mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit);
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient_doit2.SetAsyncMode(AsyncMode.FREE);
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient_doit2.SetResult(_mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2);
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit3.SetResult(_mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit3);



            //	class2type.Add( typeof( etch.bindings.csharp.examples.cuae.ConstsCuae.Request ), _mt_etch_bindings_csharp_examples_cuae_Cuae_Request );
            //	_mt_etch_bindings_csharp_examples_cuae_Cuae_Request.SetClass( typeof( etch.bindings.csharp.examples.cuae.ConstsCuae.Request ) );
            _mt_etch_bindings_csharp_examples_cuae_Cuae_Request.SetImportExportHelper
            (
                new ImportExportHelper(

                    delegate(ValueFactory vf, Object value)
            {
                return((StructValue)value);
            },
                    delegate(StructValue sv)
            {
                return(sv);
            }
                    )
            );


            //	class2type.Add( typeof( etch.bindings.csharp.examples.cuae.ConstsCuae.Response ), _mt_etch_bindings_csharp_examples_cuae_Cuae_Response );
            //  _mt_etch_bindings_csharp_examples_cuae_Cuae_Response.SetClass( typeof( etch.bindings.csharp.examples.cuae.ConstsCuae.Response ) );
            _mt_etch_bindings_csharp_examples_cuae_Cuae_Response.SetImportExportHelper
            (
                new ImportExportHelper(
                    delegate(ValueFactory vf, Object value)
            {
                return((StructValue)value);
            },
                    delegate(StructValue sv)
            {
                return(sv);
            }
                    )
            );

            _mt_etch_bindings_csharp_examples_cuae_Cuae_ReqWithMessage.SetSuperType(_mt_etch_bindings_csharp_examples_cuae_Cuae_Request);

            _mt_etch_bindings_csharp_examples_cuae_Cuae_ReqWithMessage.SetImportExportHelper
            (
                new ImportExportHelper(
                    delegate(ValueFactory vf, Object value)
            {
                return((StructValue)value);
            },
                    delegate(StructValue sv)
            {
                return(sv);
            }
                    )
            );

            _mt_etch_bindings_csharp_examples_cuae_Cuae_RespWithCode.SetSuperType(_mt_etch_bindings_csharp_examples_cuae_Cuae_Response);
            _mt_etch_bindings_csharp_examples_cuae_Cuae_RespWithCode.SetImportExportHelper
            (
                new ImportExportHelper(
                    delegate(ValueFactory vf, Object value)
            {
                return((StructValue)value);
            },
                    delegate(StructValue sv)
            {
                return(sv);
            }
                    )
            );

            // initialize the extern serializers:

            // done updating types and fields, lock them.
            types.Lock();

            class2type.Lock();


            _mt_etch_bindings_csharp_examples_cuae_Cuae_Request.PutValidator(_mf_code, Validator_int.Get(0));

            _mt_etch_bindings_csharp_examples_cuae_Cuae_ReqWithMessage.PutValidator(_mf_code, Validator_int.Get(0));
            _mt_etch_bindings_csharp_examples_cuae_Cuae_ReqWithMessage.PutValidator(_mf_msg, Validator_string.Get(0));


            _mt_etch_bindings_csharp_examples_cuae_Cuae_Response.PutValidator(_mf_msg, Validator_string.Get(0));

            _mt_etch_bindings_csharp_examples_cuae_Cuae_RespWithCode.PutValidator(_mf_msg, Validator_string.Get(0));
            _mt_etch_bindings_csharp_examples_cuae_Cuae_RespWithCode.PutValidator(_mf_code, Validator_int.Get(0));



            // params for doit
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit.PutValidator(_mf_req, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Request, 0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit.PutValidator(_mf__messageId, Validator_long.Get(0));



            // params for _result_doit
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit.PutValidator(_mf_result, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Response, 0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit.PutValidator(_mf__messageId, Validator_long.Get(0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit.PutValidator(_mf_result, Validator_RuntimeException.Get());       // thrown RuntimeException
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit.PutValidator(_mf__inReplyTo, Validator_long.Get(0));



            // params for doit2
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient_doit2.PutValidator(_mf_req, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Request, 0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient_doit2.PutValidator(_mf__messageId, Validator_long.Get(0));



            // params for _result_doit2
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.PutValidator(_mf_result, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Response, 0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.PutValidator(_mf__messageId, Validator_long.Get(0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.PutValidator(_mf_result, Validator_RuntimeException.Get());       // thrown RuntimeException
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.PutValidator(_mf__inReplyTo, Validator_long.Get(0));

            // params for doit3
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit3.PutValidator(_mf_req, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Request, 1));
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer_doit3.PutValidator(_mf__messageId, Validator_long.Get(0));



            // params for _result_doit3
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit3.PutValidator(_mf_result, Validator_StructValue.Get(_mt_etch_bindings_csharp_examples_cuae_Cuae_Response, 1));
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit3.PutValidator(_mf__messageId, Validator_long.Get(0));
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit3.PutValidator(_mf_result, Validator_RuntimeException.Get()); // thrown RuntimeException
            _mt_etch_bindings_csharp_examples_cuae_CuaeClient__result_doit3.PutValidator(_mf__inReplyTo, Validator_long.Get(0));

            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.Timeout       = 500;
            _mt_etch_bindings_csharp_examples_cuae_CuaeServer__result_doit2.ResponseField = _mf_result;
        } // end of static constructor
Ejemplo n.º 17
0
 static MyValueFactory()
 {
     DefaultValueFactory.Init(types, class2type);
 }
        [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);
        }
Ejemplo n.º 19
0
 public RequestBodyJsonBuilder(DefaultValueFactory defaultValueFactory)
 {
     this.defaultValueFactory = defaultValueFactory;
 }