コード例 #1
0
 public JsonProperty Visit(BooleanField field)
 {
     return(CreateProperty(field, jsonProperty =>
     {
         jsonProperty.Type = JsonObjectType.Boolean;
     }));
 }
コード例 #2
0
        public void CleanTest()
        {
            BooleanField target = new BooleanField(); // TODO: Initialize to an appropriate value

            // Required
            AssertExtras.Raises <ValidationException>(
                () => target.Clean(null)
                ).WithMessage("This field is required.");

            Assert.IsTrue((bool)target.Clean(true));
            Assert.IsTrue((bool)target.Clean(bool.TrueString));
            Assert.IsTrue((bool)target.Clean("1"));
            Assert.IsTrue((bool)target.Clean(1));
            Assert.IsTrue((bool)target.Clean("on"));
            Assert.IsTrue((bool)target.Clean("asdfakjsdfaksjdhf"));

            target.Required = false;
            Assert.IsFalse((bool)target.Clean(null));
            Assert.IsFalse((bool)target.Clean(false));
            Assert.IsFalse((bool)target.Clean(string.Empty));
            Assert.IsFalse((bool)target.Clean(bool.FalseString));
            Assert.IsFalse((bool)target.Clean("0"));
            Assert.IsFalse((bool)target.Clean(0));
            Assert.IsFalse((bool)target.Clean(" "));
            Assert.IsFalse((bool)target.Clean("off"));
        }
コード例 #3
0
        public void DefaultValTest()
        {
            BooleanField bf = new BooleanField(110);

            Assert.That(false, Is.EqualTo(bf.Obj));
            Assert.That(110, Is.EqualTo(bf.Tag));
            CharField cf = new CharField(300);

            Assert.That('\0', Is.EqualTo(cf.getValue()));
            Assert.That(300, Is.EqualTo(cf.Tag));
            DateTimeField dtf = new DateTimeField(3);

            Assert.That(3, Is.EqualTo(dtf.Tag));
            StringField sf = new StringField(32);

            Assert.That(32, Is.EqualTo(sf.Tag));
            Assert.That("", Is.EqualTo(sf.Obj));
            IntField ifld = new IntField(239);

            Assert.That(239, Is.EqualTo(ifld.Tag));
            Assert.That(0, Is.EqualTo(ifld.Obj));
            DecimalField df = new DecimalField(1);

            Assert.That(1, Is.EqualTo(df.Tag));
            Assert.That(new Decimal(0.0), Is.EqualTo(df.Obj));
        }
コード例 #4
0
        // Fields
        private ContentElement CreateField(ContentFieldDto contentFieldDto)
        {
            ContentField contentField;

            if (contentFieldDto is BooleanFieldDto)
            {
                var booleanFieldDto = contentFieldDto as BooleanFieldDto;
                contentField = new BooleanField {
                    Value = booleanFieldDto.Value
                };
            }
            else if (contentFieldDto is MediaFieldDto)
            {
                var mediaFieldDto = contentFieldDto as MediaFieldDto;

                if (mediaFieldDto.Media.Count > 1)
                {
                    contentField = CreateMultiMediaField(mediaFieldDto);
                }
                else
                {
                    contentField = CreateMediaField(mediaFieldDto);
                }
            }
            else
            {
                throw new NotSupportedException("No mapping from element dto " + contentFieldDto.Type + " to element model.");
            }

            contentField.Name = contentFieldDto.Name;

            return(contentField);
        }
コード例 #5
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = ByteField.GetHashCode();
         hashCode = (hashCode * 397) ^ SByteField.GetHashCode();
         hashCode = (hashCode * 397) ^ Int16Field.GetHashCode();
         hashCode = (hashCode * 397) ^ UInt16Field.GetHashCode();
         hashCode = (hashCode * 397) ^ Int32Field;
         hashCode = (hashCode * 397) ^ (int)UInt32Field;
         hashCode = (hashCode * 397) ^ Int64Field.GetHashCode();
         hashCode = (hashCode * 397) ^ UInt64Field.GetHashCode();
         hashCode = (hashCode * 397) ^ DecimalField.GetHashCode();
         hashCode = (hashCode * 397) ^ SingleFiled.GetHashCode();
         hashCode = (hashCode * 397) ^ DoubleField.GetHashCode();
         hashCode = (hashCode * 397) ^ (StringField != null ? StringField.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)MyEnumField;
         hashCode = (hashCode * 397) ^ BooleanField.GetHashCode();
         hashCode = (hashCode * 397) ^ DateTimeField.GetHashCode();
         hashCode = (hashCode * 397) ^ DateTimeOffsetField.GetHashCode();
         hashCode = (hashCode * 397) ^ GuidField.GetHashCode();
         hashCode = (hashCode * 397) ^ TimeSpanField.GetHashCode();
         hashCode = (hashCode * 397) ^ (UrlField != null ? UrlField.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (NullField != null ? NullField.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (IntArrayField != null ? IntArrayField.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (StringArrayField != null ? StringArrayField.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (EmptyArrayField != null ? EmptyArrayField.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (NullArrayField != null ? NullArrayField.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (DictionaryArrayField != null ? DictionaryArrayField.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ObjectArrayField != null ? ObjectArrayField.GetHashCode() : 0);
         return(hashCode);
     }
 }
コード例 #6
0
ファイル: BooleanFieldTests.cs プロジェクト: ifle/squidex
        public async Task Should_not_add_error_if_boolean_is_valid()
        {
            var sut = new BooleanField(1, "my-bolean", Partitioning.Invariant);

            await sut.ValidateAsync(CreateValue(true), errors);

            Assert.Empty(errors);
        }
コード例 #7
0
 string FigureOutFormFieldType(IFieldType field)
 {
     return(field switch
     {
         NumberField _ => "number-field",
         BooleanField _ => "boolean-field",
         _ => "text-field",
     });
コード例 #8
0
ファイル: BooleanFieldTests.cs プロジェクト: ifle/squidex
        public async Task Should_add_errors_if_value_is_not_valid()
        {
            var sut = new BooleanField(1, "my-bolean", Partitioning.Invariant);

            await sut.ValidateAsync(CreateValue("Invalid"), errors);

            errors.ShouldBeEquivalentTo(
                new[] { "<FIELD> is not a valid value." });
        }
コード例 #9
0
        public static FormDefinition Boolean()
        {
            var field = new BooleanField(null)
            {
                IsDirectBinding = true
            };

            return(BuildWith(field));
        }
コード例 #10
0
 public void BooleanFieldTest()
 {
     BooleanField field = new BooleanField(10, true);
     Assert.That(field.Obj, Is.EqualTo(true));
     Assert.That(field.getValue(), Is.EqualTo(true));
     Assert.That(field.Tag, Is.EqualTo(10));
     field.Obj = false;
     Assert.That(field.Obj, Is.EqualTo(false));
 }
コード例 #11
0
ファイル: FieldTests.cs プロジェクト: ChuangYang/quickfixn
 public void BooleanFieldTest()
 {
     BooleanField field = new BooleanField(10, true);
     Assert.That(field.Obj, Is.EqualTo(true));
     Assert.That(field.getValue(), Is.EqualTo(true));
     Assert.That(field.Tag, Is.EqualTo(10));
     field.Obj = false;
     Assert.That(field.Obj, Is.EqualTo(false));
 }
コード例 #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));
        }
コード例 #13
0
        public void BooleanField_GetValue_ReturnsFalseWhenBlank()
        {
            using (var item = new TestItemContext())
            {
                item.SetField(TestFields.BOOLEAN, "");

                var field = new BooleanField(new Lazy <Field>(() => item[TestFields.BOOLEAN]), null);

                Assert.IsFalse(field.Value);
            }
        }
コード例 #14
0
        private static Control CreateBooleanField(SPField field, SPList list, SPListItem item, SPControlMode mode)
        {
            BooleanField bf = new BooleanField();

            bf.ListId      = list.ID;
            bf.ItemId      = item.ID;
            bf.FieldName   = field.Title;
            bf.ID          = field.Title;
            bf.ControlMode = mode;
            return(bf);
        }
コード例 #15
0
        public void BooleanField_GetValue_WhenTrue()
        {
            using (var item = new TestItemContext())
            {
                item.SetField(TestFields.BOOLEAN, "1");

                var field = new BooleanField(new LazyField(() => item[TestFields.BOOLEAN], "TEST", TestFields.BOOLEAN), null);

                Assert.True(field.Value);
            }
        }
コード例 #16
0
ファイル: BooleanFieldTests.cs プロジェクト: ifle/squidex
        public async Task Should_add_errors_if_boolean_is_required()
        {
            var sut = new BooleanField(1, "my-bolean", Partitioning.Invariant, new BooleanFieldProperties {
                IsRequired = true
            });

            await sut.ValidateAsync(CreateValue(null), errors);

            errors.ShouldBeEquivalentTo(
                new[] { "<FIELD> is required." });
        }
コード例 #17
0
        public void BooleanField_GetValue_ReturnsFalseWhenZero()
        {
            using (var item = new TestItemContext())
            {
                item.SetField(TestFields.BOOLEAN, "0");

                var field = new BooleanField(new LazyField(() => item[TestFields.BOOLEAN], "TEST", TestFields.BOOLEAN), null);

                Assert.False(field.Value);
            }
        }
コード例 #18
0
ファイル: FieldMapTests.cs プロジェクト: unzhin/quickfixn
        public void IsFieldSetTest()
        {
            FieldMap     fieldmap = new FieldMap();
            BooleanField field    = new BooleanField(200, true);

            Assert.That(fieldmap.IsSetField(field), Is.EqualTo(false));
            Assert.That(fieldmap.IsSetField(field.Tag), Is.EqualTo(false));
            fieldmap.SetField(field);
            Assert.That(fieldmap.IsSetField(field), Is.EqualTo(true));
            Assert.That(fieldmap.IsSetField(field.Tag), Is.EqualTo(true));
        }
コード例 #19
0
ファイル: FieldMapTests.cs プロジェクト: kennystone/quickfixn
 public void BooleanFieldTest()
 {
     BooleanField field = new BooleanField(200, true);
     BooleanField refield = new BooleanField(200);
     fieldmap.SetField(field);
     fieldmap.GetField(refield);
     Assert.That(true, Is.EqualTo(refield.Obj));
     field.setValue(false);
     fieldmap.SetField(field);
     fieldmap.GetField(refield);
     Assert.That(false, Is.EqualTo(refield.Obj));
 }
コード例 #20
0
        public void BooleanField_CanImplicitCastToBool()
        {
            using (var item = new TestItemContext())
            {
                item.SetField(TestFields.BOOLEAN, "1");

                var field = new BooleanField(new Lazy <Field>(() => item[TestFields.BOOLEAN]), null);

                bool boolean = field;

                Assert.IsTrue(boolean);
            }
        }
コード例 #21
0
        public void BooleanField_CanImplicitCastToCheckboxField()
        {
            using (var item = new TestItemContext())
            {
                item.SetField(TestFields.BOOLEAN, "1");

                var field = new BooleanField(new Lazy <Field>(() => item[TestFields.BOOLEAN]), null);

                CheckboxField sitecoreField = field;

                Assert.IsTrue(sitecoreField.Checked);
            }
        }
コード例 #22
0
        public void BooleanFieldTest()
        {
            BooleanField field   = new BooleanField(200, true);
            BooleanField refield = new BooleanField(200);

            fieldmap.SetField(field);
            fieldmap.GetField(refield);
            Assert.That(true, Is.EqualTo(refield.Obj));
            field.setValue(false);
            fieldmap.SetField(field);
            fieldmap.GetField(refield);
            Assert.That(false, Is.EqualTo(refield.Obj));
        }
コード例 #23
0
        /// <summary>
        /// Get Field Value from Filter
        /// </summary>
        /// <param name="FilterContainer">Filter container</param>
        /// <param name="ConfigProperty">Config property instance</param>
        /// <returns>Value of Field in Filter</returns>
        public object GetFieldValue_From_Filter(Control FilterContainer, ConfigProperty ConfigProperty)
        {
            BooleanField booleanField = (BooleanField)FilterContainer.Controls.Find(ConfigProperty.PropertyInfo.Name, true).First();

            if (booleanField.Value != null)
            {
                return(booleanField.Value);
            }
            else
            {
                return(null);
            }
        }
コード例 #24
0
ファイル: DataFieldBase.cs プロジェクト: SpocWeb/DemoCode
 internal static IDataField CreateDataField(IField field, ModuleSchema schema)
 {
     return(field switch
     {
         StringField f => new StringDataField(f),
         BooleanField f => new BooleanDataField(f),
         NumericField f => new NumericDataField(f),
         EnumField f => new EnumDataField(f),
         InstrumentField f => new InstrumentDataField(f, schema),
         OverlayField f => new OverlayDataField(f, schema),
         TempoField f => new TempoDataField(f),
         _ => throw new ArgumentException($"Can't handle {field} yet")
     });
コード例 #25
0
        public TransformalizeFormPart()
        {
            Arrangement = new TextField {
                Text = @"<cfg name=""Form"">

  <parameters>
    
    <!-- primary key must be defined here as an integer - default it to zero to indicate a new submission -->
    <add name=""FormId"" type=""int"" value=""0"" label=""Id"" primary-key=""true"" />
    
    <!-- if you plan to mark things as deleted, add this field on insert with a default of false (not deleted) -->
    <add name=""Deleted"" type=""bool"" value=""false"" input=""false"" scope=""insert"" />
    
    <!-- if you want to audit who created a record on insert -->
    <add name=""Created"" type=""datetime"" input=""false"" t=""now()"" scope=""insert"" format=""o"" />
    <add name=""CreatedBy"" type=""string"" input=""false"" t=""username()"" scope=""insert"" label=""Created By""  />
    
    <!-- if you want to audit who updated a record on update -->
    <add name=""Updated"" type=""datetime"" input=""false"" t=""now()"" scope=""update"" format=""o"" />
    <add name=""UpdatedBy"" type=""string"" input=""false"" t=""username()"" scope=""update"" label=""Updated By"" />

    <!-- your custom fields are defined here -->
    <!-- hint: set prompt to true to prompt the user -->
    <!-- hint: set label and hint as necessary -->
    <!-- hint: use type and input-type to control user input -->
    <!-- hint: use transforms and validation to control user input -->
  
  </parameters>

  <connections>
    <!-- hint: define a connection here or use one from common settings (e.g. Transformalize > Settings) -->
    <!-- hint: if the table does not already exist, you'll have to create it yourself -->
    <add name=""connection-name"" table=""table-name"" />
  </connections>

</cfg>"
            };

            LocationEnableHighAccuracy = new BooleanField()
            {
                Value = false
            };
            LocationMaximumAge = new NumericField()
            {
                Value = 0
            };
            LocationTimeout = new NumericField()
            {
                Value = -1
            };
        }
コード例 #26
0
        private Control Layout(Panel Container, BooleanField Field, DataForm _)
        {
            TextBlock TextBlock = new TextBlock()
            {
                TextWrapping = TextWrapping.Wrap,
                Text         = Field.Label
            };

            if (Field.Required)
            {
                Run Run = new Run("*");
                TextBlock.Inlines.Add(Run);
                Run.Foreground = new SolidColorBrush(Colors.Red);
            }

            CheckBox CheckBox;

            CheckBox = new CheckBox()
            {
                Name      = VarToName(Field.Var),
                Content   = TextBlock,
                Margin    = new Thickness(0, 3, 0, 3),
                IsEnabled = !Field.ReadOnly,
                ToolTip   = Field.Description
            };

            if (!CommonTypes.TryParse(Field.ValueString, out bool IsChecked))
            {
                CheckBox.IsChecked = null;
            }
            else
            {
                CheckBox.IsChecked = IsChecked;
            }

            if (Field.HasError)
            {
                CheckBox.Background = new SolidColorBrush(Colors.PeachPuff);
            }
            else if (Field.NotSame)
            {
                CheckBox.Background = new SolidColorBrush(Colors.LightGray);
            }

            CheckBox.Click += this.CheckBox_Click;

            Container.Children.Add(CheckBox);

            return(CheckBox);
        }
コード例 #27
0
ファイル: FieldMapTests.cs プロジェクト: kennystone/quickfixn
 public void ClearAndIsEmptyTest()
 {
     MockFieldMap fieldmap = new MockFieldMap();
     BooleanField field = new BooleanField(200, true);
     Assert.That(fieldmap.IsEmpty(), Is.EqualTo(true));
     fieldmap.SetField(field);
     Assert.That(fieldmap.IsEmpty(), Is.EqualTo(false));
     fieldmap.Clear();
     Assert.That(fieldmap.IsEmpty(), Is.EqualTo(true));
     Group g = new Group(100, 101);
     fieldmap.AddGroup(g);
     Assert.That(fieldmap.IsEmpty(), Is.EqualTo(false));
     fieldmap.Clear();
     Assert.That(fieldmap.IsEmpty(), Is.EqualTo(true));
 }
コード例 #28
0
        public static void TestBooleanField()
        {
            AgentData agent = new AgentData();

            agent.StartNode = new NodeData();

            BooleanField booleanField = new BooleanField();

            booleanField.FieldName = "BooleanField";
            booleanField.Value     = true;
            agent.StartNode.Fields.Add(booleanField);

            byte[]    bytes       = Serializer.Serialize(agent);
            AgentData deAgentData = Serializer.DeSerialize <AgentData>(bytes);
        }
コード例 #29
0
        public static void TestBooleanField()
        {
            BehaviorTreeElement behaviorTree = new BehaviorTreeElement();

            behaviorTree.StartNode = new NodeData();

            BooleanField booleanField = new BooleanField();

            booleanField.FieldName = "BooleanField";
            booleanField.Value     = true;
            behaviorTree.StartNode.Fields.Add(booleanField);

            byte[] bytes = Serializer.Serialize(behaviorTree);
            BehaviorTreeElement deBehaviorTreeData = Serializer.DeSerialize <BehaviorTreeElement>(bytes);
        }
コード例 #30
0
        public void BooleanField_SetValue_SavesWhenSetTrue()
        {
            using (var item = new TestItemContext())
            {
                var field = new BooleanField(new Lazy <Field>(() => item[TestFields.BOOLEAN]), null);

                using (new SecurityDisabler())
                {
                    field.Value = true;
                }

                CheckboxField sitecoreField = item[TestFields.BOOLEAN];

                Assert.IsTrue(sitecoreField.Checked);
            }
        }
コード例 #31
0
        public void BooleanField_SetValue_SavesWhenSetFalse()
        {
            using (var item = new TestItemContext())
            {
                var field = new BooleanField(new LazyField(() => item[TestFields.BOOLEAN], "TEST", TestFields.BOOLEAN), null);

                using (new SecurityDisabler())
                {
                    field.Value = false;
                }

                CheckboxField sitecoreField = item[TestFields.BOOLEAN];

                Assert.False(sitecoreField.Checked);
            }
        }
コード例 #32
0
ファイル: FieldMapTests.cs プロジェクト: unzhin/quickfixn
        public void ClearAndIsEmptyTest()
        {
            FieldMap     fieldmap = new FieldMap();
            BooleanField field    = new BooleanField(200, true);

            Assert.That(fieldmap.IsEmpty(), Is.EqualTo(true));
            fieldmap.SetField(field);
            Assert.That(fieldmap.IsEmpty(), Is.EqualTo(false));
            fieldmap.Clear();
            Assert.That(fieldmap.IsEmpty(), Is.EqualTo(true));
            Group g = new Group(100, 101);

            fieldmap.AddGroup(g);
            Assert.That(fieldmap.IsEmpty(), Is.EqualTo(false));
            fieldmap.Clear();
            Assert.That(fieldmap.IsEmpty(), Is.EqualTo(true));
        }
コード例 #33
0
        /// <summary>
        /// Create Field in Filter
        /// </summary>
        /// <param name="param">Parameters</param>
        /// <returns>The created field</returns>
        public BaseField CreateField_In_Filter(CreateField_In_Filter_Params param)
        {
            BooleanField booleanField = new BooleanField();

            booleanField.StopAutoSizeConfig();
            booleanField.Name             = param.ConfigProperty.PropertyInfo.Name;
            booleanField.SizeLabel        = param.SizeLabel;
            booleanField.SizeControl      = param.SizeControl;
            booleanField.OrientationField = Orientation.Horizontal;
            booleanField.TabIndex         = param.TabIndex;
            booleanField.Text_Label       = param.ConfigProperty.DisplayProperty.Title;

            booleanField.ConfigSizeField();
            param.FilterContainer.Controls.Add(booleanField);

            return(booleanField);
        }
コード例 #34
0
        public static Field[] ToFieldArray(this IEnumerable<ICustomFieldDefinition> items,
            ICollection<Field> collection, string namePrefix, Action<Field, ICustomFieldDefinition> initialize = null)
        {
            var result = new List<Field>();
            foreach (var item in items)
            {
                var flags = item.IsRequired ? Required : NotRequired;
                var caption = ToLocalText(item.Title);
                var name = (namePrefix ?? "") + item.Name;
                Field field;

                switch (item.FieldType)
                {
                    case CustomFieldType.Boolean:
                        field = new BooleanField(collection, name, caption, 0, flags);
                        break;
                    case CustomFieldType.Date:
                        field = new DateTimeField(collection, name, caption, 0, flags) { DateTimeKind = DateTimeKind.Unspecified };
                        break;
                    case CustomFieldType.DateTime:
                        field = new DateTimeField(collection, name, caption, 0, flags) { DateTimeKind = DateTimeKind.Local };
                        break;
                    case CustomFieldType.Decimal:
                        field = new DecimalField(collection, name, caption, item.Size, flags);
                        break;
                    case CustomFieldType.Int32:
                        field = new Int32Field(collection, name, caption, item.Size, flags);
                        break;
                    case CustomFieldType.Int64:
                        field = new Int64Field(collection, name, caption, item.Size, flags);
                        break;
                    default:
                        field = new StringField(collection, name, caption, item.Size, flags);
                        break;
                }

                field.DefaultValue = item.DefaultValue.TrimToNull();
                result.Add(field);

                if (initialize != null)
                    initialize(field, item);
            }

            return result.ToArray();
        }
コード例 #35
0
ファイル: FieldTests.cs プロジェクト: ChuangYang/quickfixn
 public void DefaultValTest()
 {
     BooleanField bf = new BooleanField(110);
     Assert.That(false, Is.EqualTo(bf.Obj));
     Assert.That(110, Is.EqualTo(bf.Tag));
     CharField cf = new CharField(300);
     Assert.That('\0', Is.EqualTo(cf.getValue()));
     Assert.That(300, Is.EqualTo(cf.Tag));
     DateTimeField dtf = new DateTimeField(3);
     Assert.That(3, Is.EqualTo(dtf.Tag));
     StringField sf = new StringField(32);
     Assert.That(32, Is.EqualTo(sf.Tag));
     Assert.That("", Is.EqualTo(sf.Obj));
     IntField ifld = new IntField(239);
     Assert.That(239, Is.EqualTo(ifld.Tag));
     Assert.That(0, Is.EqualTo(ifld.Obj));
     DecimalField df = new DecimalField(1);
     Assert.That(1, Is.EqualTo(df.Tag));
     Assert.That(new Decimal(0.0), Is.EqualTo(df.Obj));
 }
コード例 #36
0
ファイル: FieldMapTests.cs プロジェクト: kennystone/quickfixn
 public void IsFieldSetTest()
 {
     MockFieldMap fieldmap = new MockFieldMap();
     BooleanField field = new BooleanField(200, true);
     Assert.That(fieldmap.IsSetField(field), Is.EqualTo(false));
     Assert.That(fieldmap.IsSetField(field.Tag), Is.EqualTo(false));
     fieldmap.SetField(field);
     Assert.That(fieldmap.IsSetField(field), Is.EqualTo(true));
     Assert.That(fieldmap.IsSetField(field.Tag), Is.EqualTo(true));
 }