public void Deserialize_FromOracleData_WithTestTableWithUnion_And_TestTable1()
        {
            var table1 = new TestTable1()
            {
                IntProp   = 42,
                ByteProp  = 22,
                ShortProp = 62,
            };

            var oracle       = new SerializationTestOracle();
            var oracleResult = oracle.GenerateTestTableWithUnion(1024, testTable1Prop: table1);

            var serializer = new FlatBuffersSerializer();
            var o          = serializer.Deserialize <TestTableWithUnion>(oracleResult, 0, oracleResult.Length);

            Assert.AreEqual(1024, o.IntProp);

            Assert.IsInstanceOf <TestTable1>(o.UnionProp);

            var o1 = o.UnionProp as TestTable1;

            Assert.AreEqual(table1.IntProp, o1.IntProp);
            Assert.AreEqual(table1.ShortProp, o1.ShortProp);
            Assert.AreEqual(table1.ByteProp, o1.ByteProp);
        }
Пример #2
0
    protected void Test00()
    {
        // Arrange
        var(builder, v) = Setup();

        var t0Name   = new DbName(Rnd.Str);
        var t0Column = Rnd.Str;
        var t0       = new TestTable0(t0Name, t0Column);

        var t1Name   = new DbName(Rnd.Str);
        var t1Column = Rnd.Str;
        var t1       = new TestTable1(t1Name, t1Column);

        // Act
        var result = builder.AddRightJoin(v.Parts, t0, t => t.Foo, t1, t => t.Bar);

        // Assert
        var some = result.AssertSome();

        Assert.NotSame(v.Parts, some);
        Assert.Collection(some.RightJoin,
                          x =>
        {
            Assert.Equal(t0Name, x.from.TblName);
            Assert.Equal(t0Column, x.from.ColName);

            Assert.Equal(t1Name, x.to.TblName);
            Assert.Equal(t1Column, x.to.ColName);
        }
                          );
    }
Пример #3
0
        /// <summary>
        /// 修改数据。必须传入Id
        /// </summary>
        public BaseResult UptUser(TestTableParam param)
        {
            if (param.Id == null)
            {
                return(new BaseResult(false, null, Msg.ParamError));
            }
            var model = new TestTable1();

            if (param.Name != null)
            {
                model.Name = param.Name;
            }
            if (param.IDNumber != null)
            {
                model.IDNumber = param.IDNumber;
            }
            if (param.MobilePhone != null)
            {
                model.MobilePhone = param.MobilePhone;
            }
            var count = TestTableRepository.Update(model, d => d.Id == param.Id);

            //更新缓存
            TestTableCache.DelUserModel(param.Id.Value);
            return(new BaseResult(true));
        }
        public void Serialize_TestTable1_And_TestTableWithOriginalOrdering_EmitDifferentBuffers()
        {
            const int   intProp   = 123456;
            const byte  byteProp  = 42;
            const short shortProp = 1024;

            var obj = new TestTableWithOriginalOrdering()
            {
                IntProp   = intProp,
                ByteProp  = byteProp,
                ShortProp = shortProp
            };

            var buffer = FlatBuffersConvert.SerializeObject(obj);

            var obj2 = new TestTable1()
            {
                IntProp   = intProp,
                ByteProp  = byteProp,
                ShortProp = shortProp
            };

            var buffer2 = FlatBuffersConvert.SerializeObject(obj2);

            // Buffers will be different as they've been written in different orders
            Assert.IsFalse(buffer.SequenceEqual(buffer2));
        }
        public void Serialize_WithTestTableWithTable_CanBeReadByOracle()
        {
            const int   intProp   = 42;
            const byte  byteProp  = 22;
            const short shortProp = 62;

            var serializer = new FlatBuffersSerializer();

            var testTable = new TestTable1()
            {
                IntProp = intProp, ShortProp = shortProp, ByteProp = byteProp
            };

            var obj = new TestTableWithTable()
            {
                TableProp = testTable, IntProp = 1024
            };

            var buffer = new byte[256];

            serializer.Serialize(obj, buffer, 0, buffer.Length);

            var oracle       = new SerializationTestOracle();
            var oracleResult = oracle.ReadTestTableWithTable(buffer);

            Assert.AreEqual(obj.IntProp, oracleResult.IntProp);
            Assert.AreEqual(obj.TableProp.IntProp, oracleResult.TableProp.IntProp);
            Assert.AreEqual(obj.TableProp.ByteProp, oracleResult.TableProp.ByteProp);
            Assert.AreEqual(obj.TableProp.ShortProp, oracleResult.TableProp.ShortProp);
        }
        public void Serialize_TestTableWithUnion_And_TestTable1_CanBeReadByOracle()
        {
            const int   intProp   = 123456;
            const byte  byteProp  = 42;
            const short shortProp = 1024;

            var table1 = new TestTable1()
            {
                IntProp   = intProp,
                ByteProp  = byteProp,
                ShortProp = shortProp
            };

            var obj = new TestTableWithUnion()
            {
                IntProp   = 512,
                UnionProp = table1
            };

            var buffer = FlatBuffersConvert.SerializeObject(obj);

            var oracle       = new SerializationTestOracle();
            var oracleResult = oracle.ReadTestTableWithUnion(buffer);

            Assert.AreEqual(512, oracleResult.IntProp);
            Assert.AreEqual(typeof(TestTable1), oracleResult.UnionProp.GetType());

            var oracleResult1 = oracleResult.UnionProp as TestTable1;

            Assert.IsNotNull(oracleResult1);
            Assert.AreEqual(intProp, oracleResult1.IntProp);
            Assert.AreEqual(byteProp, oracleResult1.ByteProp);
            Assert.AreEqual(shortProp, oracleResult1.ShortProp);
        }
Пример #7
0
        public IHttpActionResult PutTestTable1(int id, TestTable1 testTable1)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != testTable1.Id)
            {
                return(BadRequest());
            }

            db.Entry(testTable1).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TestTable1Exists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #8
0
        public byte[] GenerateTestTableWithUnion(int intProp, TestTable1 testTable1Prop = null, TestTable2 testTable2Prop = null)
        {
            if (testTable1Prop != null && testTable2Prop != null)
            {
                throw new ArgumentException();
            }

            var fbb = new FlatBufferBuilder(8);

            var unionTableOffset = 0;
            var unionType        = TestUnion.NONE;

            if (testTable1Prop != null)
            {
                unionTableOffset = SerializationTests.TestTable1.CreateTestTable1(fbb, testTable1Prop.IntProp,
                                                                                  testTable1Prop.ByteProp, testTable1Prop.ShortProp).Value;
                unionType = TestUnion.TestTable1;
            }
            else if (testTable2Prop != null)
            {
                var stringOffset = fbb.CreateString(testTable2Prop.StringProp);
                unionTableOffset = SerializationTests.TestTable2.CreateTestTable2(fbb, stringOffset).Value;
                unionType        = TestUnion.TestTable2;
            }

            var tableOffset = SerializationTests.TestTableWithUnion.CreateTestTableWithUnion(fbb, intProp,
                                                                                             unionType, unionTableOffset);

            fbb.Finish(tableOffset.Value);
            return(GetBytes(fbb));
        }
        public void Serialize_TestTableWithNestedTestTable1_CanBeReadByOracle()
        {
            const int   intProp   = 123456;
            const byte  byteProp  = 42;
            const short shortProp = 1024;

            var nested = new TestTable1()
            {
                IntProp   = intProp,
                ByteProp  = byteProp,
                ShortProp = shortProp
            };

            var obj = new TestTableWithNestedTestTable1()
            {
                IntProp = 2048,
                Nested  = nested
            };

            var buffer = FlatBuffersConvert.SerializeObject(obj);

            var oracle       = new SerializationTestOracle();
            var oracleResult = oracle.ReadTestTableWithNestedTable1(buffer);

            Assert.AreEqual(2048, oracleResult.IntProp);

            var oracleResult1 = oracleResult.Nested as TestTable1;

            Assert.IsNotNull(oracleResult1);
            Assert.AreEqual(intProp, oracleResult1.IntProp);
            Assert.AreEqual(byteProp, oracleResult1.ByteProp);
            Assert.AreEqual(shortProp, oracleResult1.ShortProp);
        }
Пример #10
0
        public void TestRegisterColumnDefault()
        {
            var t = new TestTable1();

            Assert.That(t.AllColumns.Contains(t.Username));
            Assert.That(t.AllColumns.Contains(t.Password));
        }
Пример #11
0
        /// <summary>
        /// attach session to "main" and update table with new row
        /// </summary>
        private void MakeAndValidateTableChanges()
        {
            // create a session for "main" database
            Assert.That(dbPrimary.CreateSessionAndAttachTable("main", out session, zTab: null), Is.EqualTo(SQLite3.Result.OK));

            // validate no changes have occurred
            Assert.That(SQLiteSession.IsEmptySession(session), Is.True);

            // verify that "main" has 2 rows in TestTable1
            var mainTestTable1Rows = dbPrimary.Query <TestTable1>("Select * FROM main.TestTable1;");

            Assert.That(mainTestTable1Rows.Count, Is.EqualTo(2));

            // add a row to table
            var newRow = new TestTable1
            {
                myString       = "test",
                myInt          = 3,
                myDate         = DateTime.Now,
                myTable2Object = sampleData.myTable2Object
            };

            Assert.That(dbPrimary.Insert(newRow), Is.EqualTo(1));

            // verify that "main" now has 3 rows in TestTable1
            mainTestTable1Rows = dbPrimary.Query <TestTable1>("Select * FROM main.TestTable1;");
            Assert.That(mainTestTable1Rows.Count, Is.EqualTo(3));

            // session should no longer be empty, as we have inserted a row
            Assert.That(SQLiteSession.IsEmptySession(session), Is.False);
        }
        public void Oracle_WithTestTableWithTable_CanReadGeneratedData()
        {
            const int   intProp   = 42;
            const byte  byteProp  = 22;
            const short shortProp = 62;

            var testTable = new TestTable1()
            {
                IntProp = intProp, ShortProp = shortProp, ByteProp = byteProp
            };

            var obj = new TestTableWithTable()
            {
                TableProp = testTable, IntProp = 1024
            };

            var oracle = new SerializationTestOracle();

            var buffer = oracle.GenerateTestTableWithTable(testTable, 1024);

            var oracleResult = oracle.ReadTestTableWithTable(buffer);

            Assert.AreEqual(obj.IntProp, oracleResult.IntProp);
            Assert.AreEqual(obj.TableProp.IntProp, oracleResult.TableProp.IntProp);
            Assert.AreEqual(obj.TableProp.ByteProp, oracleResult.TableProp.ByteProp);
            Assert.AreEqual(obj.TableProp.ShortProp, oracleResult.TableProp.ShortProp);
        }
Пример #13
0
        /// <summary>
        /// 新增数据。必须传入姓名Name,手机号MobilePhone,身份证号IDNumber
        /// </summary>
        public BaseResult AddUser(TestTableParam param)
        {
            if (string.IsNullOrWhiteSpace(param.Name) || string.IsNullOrWhiteSpace(param.MobilePhone) ||
                string.IsNullOrWhiteSpace(param.IDNumber))
            {
                return(new BaseResult(false, null, Msg.ParamError));
            }
            var model = new TestTable1
            {
                Id          = Guid.NewGuid(),
                Name        = param.Name,
                IDNumber    = param.IDNumber,
                MobilePhone = param.MobilePhone,
                CreateTime  = DateTime.Now,
                T2          = 0,
                T3          = 0,
                T4          = true,
                T7          = 0,
                T9          = 0
            };
            var count = TestTableRepository.Insert(model);

            //设置缓存
            TestTableCache.SetUserModel(model);
            return(new BaseResult(count > 0, count, count > 0 ? "" : Msg.Line0));
        }
        public void Deserialize_FromOracleData_WithTestTableWithUnionAndMoreFields_And_TestTable1()
        {
            var table1 = new TestTable1()
            {
                IntProp   = 42,
                ByteProp  = 22,
                ShortProp = 62,
            };

            var oracle       = new SerializationTestOracle();
            var oracleResult = oracle.GenerateTestTableWithUnionAndMoreFields(1024, "Hello, FlatBuffers", 123.5f, 3.14, testTable1Prop: table1);

            var serializer = new FlatBuffersSerializer();
            var o          = serializer.Deserialize <TestTableWithUnionAndMoreFields>(oracleResult, 0, oracleResult.Length);

            Assert.AreEqual(1024, o.IntProp);
            Assert.AreEqual("Hello, FlatBuffers", o.StringProp);
            Assert.AreEqual(123.5f, o.FloatProp);
            Assert.AreEqual(3.14, o.DoubleProp);

            Assert.IsInstanceOf <TestTable1>(o.UnionProp);

            var o1 = o.UnionProp as TestTable1;

            Assert.AreEqual(table1.IntProp, o1.IntProp);
            Assert.AreEqual(table1.ShortProp, o1.ShortProp);
            Assert.AreEqual(table1.ByteProp, o1.ByteProp);
        }
Пример #15
0
        public ActionResult DeleteConfirmed(int id)
        {
            TestTable1 testTable1 = db.TestTable1.Find(id);

            db.TestTable1.Remove(testTable1);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #16
0
 public ActionResult Edit([Bind(Include = "Id,Name,Field1,Field2")] TestTable1 testTable1)
 {
     if (ModelState.IsValid)
     {
         db.Entry(testTable1).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(testTable1));
 }
Пример #17
0
 static void InsertSomeEntities(DbContext dbContext)
 {
     for (int i = 0; i < 1000; i++)
     {
         var table1s = new TestTable1();
         table1s.Dummy  = "Testin";
         table1s.Dummy2 = i;
         dbContext.GetTable <TestTable1>().InsertOnSubmit(table1s);
     }
     dbContext.SubmitChanges();
 }
Пример #18
0
        public IHttpActionResult GetTestTable1(int id)
        {
            TestTable1 testTable1 = db.TestTable1.Find(id);

            if (testTable1 == null)
            {
                return(NotFound());
            }

            return(Ok(testTable1));
        }
Пример #19
0
        public ActionResult Create([Bind(Include = "Id,Name,Field1,Field2")] TestTable1 testTable1)
        {
            if (ModelState.IsValid)
            {
                db.TestTable1.Add(testTable1);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(testTable1));
        }
Пример #20
0
        static void TestInsertOrder(DbContext dbContext)
        {
            var testTable1 = new TestTable1();

            testTable1.Dummy  = "First";
            testTable1.Dummy2 = 1;
            var testTable3 = new TestTable3();

            testTable3.TestTable1 = testTable1;
            dbContext.GetTable <TestTable3>().InsertOnSubmit(testTable3);
            dbContext.SubmitChanges();
        }
Пример #21
0
        public TestTable1 ReadTestTable1(byte[] buffer)
        {
            var test   = SerializationTests.TestTable1.GetRootAsTestTable1(new ByteBuffer(buffer));
            var result = new TestTable1()
            {
                IntProp   = test.IntProp,
                ByteProp  = test.ByteProp,
                ShortProp = test.ShortProp
            };

            return(result);
        }
Пример #22
0
        public IHttpActionResult PostTestTable1(TestTable1 testTable1)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.TestTable1.Add(testTable1);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = testTable1.Id }, testTable1));
        }
Пример #23
0
        public IHttpActionResult DeleteTestTable1(int id)
        {
            TestTable1 testTable1 = db.TestTable1.Find(id);

            if (testTable1 == null)
            {
                return(NotFound());
            }

            db.TestTable1.Remove(testTable1);
            db.SaveChanges();

            return(Ok(testTable1));
        }
Пример #24
0
        // GET: TestTable1/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TestTable1 testTable1 = db.TestTable1.Find(id);

            if (testTable1 == null)
            {
                return(HttpNotFound());
            }
            return(View(testTable1));
        }
Пример #25
0
        public byte[] GenerateTestTableWithTable(TestTable1 testTableProp, int intProp)
        {
            var fbb = new FlatBufferBuilder(8);

            var tableOffset = SerializationTests.TestTable1.CreateTestTable1(fbb, testTableProp.IntProp,
                                                                             testTableProp.ByteProp, testTableProp.ShortProp);

            SerializationTests.TestTableWithTable.StartTestTableWithTable(fbb);
            SerializationTests.TestTableWithTable.AddIntProp(fbb, intProp);

            SerializationTests.TestTableWithTable.AddTableProp(fbb, tableOffset);
            var offset = SerializationTests.TestTableWithTable.EndTestTableWithTable(fbb);

            fbb.Finish(offset.Value);
            return(GetBytes(fbb));
        }
        public ActionResult SecureXSS(TestTable1 testTable)
        {
            var testData = new TestTable1();

            using (var db = new TestDbContext())
            {
                testTable.Field2 = Encoder.HtmlEncode(testTable.Field2);
                db.TestTable1.Add(testTable);
                db.SaveChanges();

                testData = db.TestTable1.OrderByDescending(x => x.Id).FirstOrDefault(x => x.Name == testTable.Name);
            }

            testData.Field2 = HttpUtility.HtmlDecode(testData.Field2);
            return(View(testData));
        }
        public void Deserialize_FromOracleData_WithTestTableWithArrayOfTables()
        {
            var tableArray = new TestTable1[]
            {
                new TestTable1 {
                    ByteProp = 1, IntProp = 2, ShortProp = 3
                },
                new TestTable1 {
                    ByteProp = 4, IntProp = 5, ShortProp = 6
                },
            };

            var tableList = new List <TestTable1>
            {
                new TestTable1 {
                    ByteProp = 7, IntProp = 8, ShortProp = 9
                },
                new TestTable1 {
                    ByteProp = 10, IntProp = 11, ShortProp = 12
                },
            };

            var oracle       = new SerializationTestOracle();
            var oracleResult = oracle.GenerateTestTableWithArrayOfTables(tableArray, tableList);

            var serializer = new FlatBuffersSerializer();
            var o          = serializer.Deserialize <TestTableWithArrayOfTables>(oracleResult, 0, oracleResult.Length);

            Assert.AreEqual(o.TableArrayProp[0].IntProp, tableArray[0].IntProp);
            Assert.AreEqual(o.TableArrayProp[0].ByteProp, tableArray[0].ByteProp);
            Assert.AreEqual(o.TableArrayProp[0].ShortProp, tableArray[0].ShortProp);
            Assert.AreEqual(o.TableArrayProp[1].IntProp, tableArray[1].IntProp);
            Assert.AreEqual(o.TableArrayProp[1].ByteProp, tableArray[1].ByteProp);
            Assert.AreEqual(o.TableArrayProp[1].ShortProp, tableArray[1].ShortProp);

            Assert.AreEqual(o.TableListProp[0].IntProp, tableList[0].IntProp);
            Assert.AreEqual(o.TableListProp[0].ByteProp, tableList[0].ByteProp);
            Assert.AreEqual(o.TableListProp[0].ShortProp, tableList[0].ShortProp);
            Assert.AreEqual(o.TableListProp[1].IntProp, tableList[1].IntProp);
            Assert.AreEqual(o.TableListProp[1].ByteProp, tableList[1].ByteProp);
            Assert.AreEqual(o.TableListProp[1].ShortProp, tableList[1].ShortProp);
        }
        public void Deserialize_FromOracleData_WithTestTableWithTable()
        {
            var testTable = new TestTable1()
            {
                IntProp   = 42,
                ByteProp  = 22,
                ShortProp = 62,
            };

            var oracle       = new SerializationTestOracle();
            var oracleResult = oracle.GenerateTestTableWithTable(testTable, 1024);

            var serializer = new FlatBuffersSerializer();
            var o          = serializer.Deserialize <TestTableWithTable>(oracleResult, 0, oracleResult.Length);

            Assert.AreEqual(1024, o.IntProp);
            Assert.AreEqual(testTable.IntProp, o.TableProp.IntProp);
            Assert.AreEqual(testTable.ShortProp, o.TableProp.ShortProp);
            Assert.AreEqual(testTable.ByteProp, o.TableProp.ByteProp);
        }
Пример #29
0
        static void TestDeleteMultiple(DbContext dbContext)
        {
            var testTable1 = new TestTable1();

            testTable1.Dummy  = "Del";
            testTable1.Dummy2 = 69;
            dbContext.GetTable <TestTable1>().InsertOnSubmit(testTable1);
            var testTable31 = new TestTable3();

            testTable31.TestTable1 = testTable1;
            var testTable32 = new TestTable3();

            testTable32.TestTable1 = testTable1;

            dbContext.SubmitChanges();

            dbContext.DeleteOnSubmit(testTable31);
            dbContext.DeleteOnSubmit(testTable32);
            dbContext.DeleteOnSubmit(testTable1);
            dbContext.SubmitChanges();
        }
        public void Serialize_TestTableWithUnionAndMoreFields_And_TestTable1_CanBeReadByOracle()
        {
            const int   intProp   = 123456;
            const byte  byteProp  = 42;
            const short shortProp = 1024;

            var table1 = new TestTable1()
            {
                IntProp   = intProp,
                ByteProp  = byteProp,
                ShortProp = shortProp
            };

            var obj = new TestTableWithUnionAndMoreFields()
            {
                IntProp    = 512,
                StringProp = "Hello, world!",
                FloatProp  = 3.125f,
                DoubleProp = 3.14,
                UnionProp  = table1
            };

            var buffer = FlatBuffersConvert.SerializeObject(obj);

            var oracle       = new SerializationTestOracle();
            var oracleResult = oracle.ReadTestTableWithUnionAndMoreFields(buffer);

            Assert.AreEqual(512, oracleResult.IntProp);
            Assert.AreEqual("Hello, world!", oracleResult.StringProp);
            Assert.AreEqual(3.125f, oracleResult.FloatProp);
            Assert.AreEqual(3.14, oracleResult.DoubleProp);
            Assert.IsInstanceOf <TestTable1>(oracleResult.UnionProp);

            var oracleResult1 = oracleResult.UnionProp as TestTable1;

            Assert.IsNotNull(oracleResult1);
            Assert.AreEqual(intProp, oracleResult1.IntProp);
            Assert.AreEqual(byteProp, oracleResult1.ByteProp);
            Assert.AreEqual(shortProp, oracleResult1.ShortProp);
        }