示例#1
0
        public void TypedAccessors_NonConvertile()
        {
            var guid = Guid.NewGuid();
            var bean = new Bean();

            bean.Put("p", guid);
            Assert.Equal(guid, bean.Get <Guid>("p"));
            Assert.Equal(guid, bean.Get <Guid?>("p"));
        }
示例#2
0
        public void TypedAccessors_Dates()
        {
            var bean = new Bean();

            bean.Put("x", new DateTime(2011, 11, 11));
            Assert.Equal(2011, bean.Get <DateTime>("x").Year);

            bean.Put("x", "2012-12-12");
            Assert.Equal(2012, bean.Get <DateTime>("x").Year);

            bean.Put("x", "?");
            Assert.Equal(new DateTime(), bean.Get <DateTime>("x"));
        }
示例#3
0
        public void TypedAccessors_Conversion()
        {
            AssertExtensions.WithCulture("ru", delegate() {
                var bean = new Bean();

                bean.Put("x", "3.14");
                Assert.Equal(3.14, bean.Get <double?>("x"));
                Assert.Equal(3.14M, bean.Get <decimal>("x"));

                bean.Put("x", "abc");
                Assert.Equal(0, bean.Get <int>("x"));
                Assert.Null(bean.Get <int?>("x"));
            });
        }
示例#4
0
        void BeanOptions(BeanApi api)
        {
            /// ## Bean Options
            /// You can configure the BeanAPI to dispense new Beans with some default options
            ///
            /// **.ValidateGetColumns**
#if CODE
            // Sets whether a Bean throws `ColumnNotFoundException` if
            // you request a column which isn't stored in the Bean. True by default
            api.BeanOptions.ValidateGetColumns = true;

            Bean bean = api.Dispense("books");
            bean.Put("ColumnOne", 1);              // Add a single column
            int one = bean.Get <int>("ColumnOne"); // OK
            int two = bean.Get <int>("ColumnTwo"); // throws ColumnNotFoundException
#endif
        }
示例#5
0
        void TypedAccessors(Bean bean)
        {
            /// ## Typed Accessors
            /// To access bean properties in a strongly-typed fashion, use the `Get<T>` method:
#if CODE
            bean.Get <string>("title");
            bean.Get <decimal>("price");
            bean.Get <bool?>("someFlag");
#endif
            /// And there is a companion `Put` method which is chainable:
#if CODE
            bean
            .Put("name", "Jane Doe")
            .Put("comment", null);
#endif
            /// See also: [Custom Bean Classes](#custom-bean-classes)
        }
示例#6
0
        public void TypedAccessors_Enums()
        {
            var bean = new Bean();

            bean.Put("x", DayOfWeek.Thursday);
            Assert.Equal(DayOfWeek.Thursday, bean.Get <DayOfWeek>("x"));

            bean.Put("x", "THURSDAY");
            Assert.Equal(DayOfWeek.Thursday, bean.Get <DayOfWeek>("x"));

            bean.Put("x", (ulong)DayOfWeek.Thursday);
            Assert.Equal(DayOfWeek.Thursday, bean.Get <DayOfWeek>("x"));

            bean.Put("x", "?");
            Assert.Equal(default(DayOfWeek), bean.Get <DayOfWeek>("x"));

            bean.Put("x", 4);
            Assert.Equal(DayOfWeek.Thursday, bean.Get <DayOfWeek?>("x"));
        }
示例#7
0
        public void TypedAccessors()
        {
            var bean = new Bean();

            Assert.Equal(0, bean.Get <int>("x"));
            Assert.Null(bean.Get <int?>("x"));

            bean.Put("x", 0);
            Assert.Equal(0, bean.Get <int>("x"));
            Assert.Equal(0, bean.Get <int?>("x"));

            bean.Put("x", null);
            Assert.Equal(0, bean.Get <int>("x"));
            Assert.Null(bean.Get <int?>("x"));

            bean.Put("x", new Nullable <int>(1));
            Assert.Equal(1, bean.Get <int>("x"));
        }
示例#8
0
        public void TypedAccessors()
        {
            var bean = new Bean();

            Assert.Equal(0, bean.Get<int>("x"));
            Assert.Null(bean.Get<int?>("x"));

            bean.Put("x", 0);
            Assert.Equal(0, bean.Get<int>("x"));
            Assert.Equal(0, bean.Get<int?>("x"));

            bean.Put("x", null);
            Assert.Equal(0, bean.Get<int>("x"));
            Assert.Null(bean.Get<int?>("x"));

            bean.Put("x", new Nullable<int>(1));
            Assert.Equal(1, bean.Get<int>("x"));
        }
示例#9
0
 public void TypedAccessors_NonConvertile()
 {
     var guid = Guid.NewGuid();
     var bean = new Bean();
     bean.Put("p", guid);
     Assert.Equal(guid, bean.Get<Guid>("p"));
     Assert.Equal(guid, bean.Get<Guid?>("p"));
 }
示例#10
0
        public void TypedAccessors_Enums()
        {
            var bean = new Bean();

            bean.Put("x", DayOfWeek.Thursday);
            Assert.Equal(DayOfWeek.Thursday, bean.Get<DayOfWeek>("x"));

            bean.Put("x", "THURSDAY");
            Assert.Equal(DayOfWeek.Thursday, bean.Get<DayOfWeek>("x"));

            bean.Put("x", (ulong)DayOfWeek.Thursday);
            Assert.Equal(DayOfWeek.Thursday, bean.Get<DayOfWeek>("x"));

            bean.Put("x", "?");
            Assert.Equal(default(DayOfWeek), bean.Get<DayOfWeek>("x"));

            bean.Put("x", 4);
            Assert.Equal(DayOfWeek.Thursday, bean.Get<DayOfWeek?>("x"));
        }
示例#11
0
        public void TypedAccessors_Dates()
        {
            var bean = new Bean();

            bean.Put("x", new DateTime(2011, 11, 11));
            Assert.Equal(2011, bean.Get<DateTime>("x").Year);

            bean.Put("x", "2012-12-12");
            Assert.Equal(2012, bean.Get<DateTime>("x").Year);

            bean.Put("x", "?");
            Assert.Equal(new DateTime(), bean.Get<DateTime>("x"));
        }
示例#12
0
        public void TypedAccessors_Conversion()
        {
            AssertExtensions.WithCulture("ru", delegate() {
                var bean = new Bean();

                bean.Put("x", "3.14");
                Assert.Equal(3.14, bean.Get<double?>("x"));
                Assert.Equal(3.14M, bean.Get<decimal>("x"));

                bean.Put("x", "abc");
                Assert.Equal(0, bean.Get<int>("x"));
                Assert.Null(bean.Get<int?>("x"));
            });
        }
示例#13
0
 void TypedAccessors(Bean bean)
 {
     /// ## Typed Accessors
     /// To access bean properties in a strongly-typed fashion, use the `Get<T>` method:
     #if CODE
     bean.Get<string>("title");
     bean.Get<decimal>("price");
     bean.Get<bool?>("someFlag");
     #endif
     /// And there is a companion `Put` method which is chainable:
     #if CODE
     bean
         .Put("name", "Jane Doe")
         .Put("comment", null);
     #endif
     /// See also: [Custom Bean Classes](#custom-bean-classes)
 }