Ejemplo n.º 1
0
        public void TestAddChild()
        {
            IStore store = new ThreadStaticStore();
            IDbContextFactory contextFactory = new DbContextFactory();

            using (UnitOfWork unitwork = new UnitOfWork(store, contextFactory))
            {
                IRepository<Demo, Guid> demoRepository = new Repository<Demo, Guid>(store);
                IRepository<DemoChild, Guid> demoChildRepository = new Repository<DemoChild, Guid>(store);
                IRepository<DemoBrother, Guid> demoBrotherRepository = new Repository<DemoBrother, Guid>(store);
                Demo demo = new Demo()
                {
                    Name = "C"
                };

                DemoChild child = new DemoChild();
                demo.Children.Add(child);

                DemoBrother brother = new DemoBrother();
                demo.Brothers.Add(brother);

                demoRepository.SaveOrUpdate(demo);
                demoChildRepository.SaveOrUpdate(child);
                demoBrotherRepository.SaveOrUpdate(brother);

                unitwork.SaveChanges();
            }
        }
    public void TestMethod1()
    {
        XmlSerializer sr   = new XmlSerializer(typeof(ClassToSerialize));
        var           demo = new DemoChild();
        var           ser  = new ClassToSerialize {
            anotherOne = demo
        };
        var stream = new MemoryStream();

        sr.Serialize(stream, ser);
    }
Ejemplo n.º 3
0
        public void ShouldSupportOrientDBObjectType()
        {
            var employee = new DemoEmployee();
            employee.SomeOtherId = Guid.NewGuid();
            employee.Name = "Janet";
            employee.Age = 33;
            employee.SomeVeryLongNumber = 12345678901234567;
            employee.BirthDate = new DateTime(2015, 1, 24, 2, 2, 2);
            employee.Salary = (decimal)23434.1234567891;
            employee.Commission = (double)23434.1234567891;
            employee.Allowance = (float)3434.1234567891;
            employee.IsMarried = true;
            employee.SomeIntegerList = new List<int>();
            employee.SomeIntegerList.Add(1);
            employee.SomeIntegerList.Add(2);
            employee.SomeIntegerList.Add(3);
            employee.SomeIntegerArrayList = new int[3] { 4, 2, 3 };
            employee.SomeDecimalList = new List<decimal>();
            employee.SomeDecimalList.Add((decimal)23434.1234567891);
            employee.SomeDecomeArray = new decimal[3] { (decimal)23434.1234567890, (decimal)23434.1234567890, (decimal)23434.1234567890 };
            employee.Kids = new List<DemoChild>();

            var kid = new DemoChild();
            kid.Name = "Janet";
            kid.Age = 33;
            kid.SomeVeryLongNumber = 12345678901234567;
            kid.BirthDate = new DateTime(2015, 1, 24, 2, 2, 2);
            kid.Salary = (decimal)23434.1234567891;
            kid.Commission = (double)23434.1234567891;
            kid.Allowance = (float)3434.1234567891;
            kid.IsMarried = true;

            kid.SomeIntegerList = new List<int>();
            kid.SomeIntegerList.Add(1);
            kid.SomeIntegerList.Add(2);
            kid.SomeIntegerList.Add(3);
            kid.SomeIntegerArrayList = new int[3] { 4, 2, 3 };

            kid.SomeDecimalList = new List<decimal>();
            kid.SomeDecimalList.Add((decimal)23434.1234567891);
            kid.SomeDecomeArray = new decimal[3] { (decimal)23434.1234567890, (decimal)23434.1234567890, (decimal)23434.1234567890 };
            employee.Kids.Add(kid);

            employee.SomeIListInteger = new List<int>();
            employee.SomeIListInteger.Add(7);
            employee.MyKeyValues = new Dictionary<string, long>();
            employee.MyKeyValues.Add("1", 578933315553);
            employee.MyKeyValues.Add("2", 123445555555555);

            employee.MyFavoriteColor = DemoEmployee.Color.Yellow;

            var document = _database.Insert<DemoEmployee>(employee).Run();
            Assert.NotNull(document);
            Assert.NotNull(document.ORID);
            Assert.AreEqual(employee.SomeOtherId, document.GetField<Guid>("SomeOtherId"));
            Assert.AreEqual(employee.Name, document.GetField<string>("Name"));
            Assert.AreEqual(employee.Age, document.GetField<int>("Age"));
            Assert.AreEqual(employee.SomeVeryLongNumber, document.GetField<long>("SomeVeryLongNumber"));
            Assert.AreEqual(employee.BirthDate, document.GetField<DateTime>("BirthDate"));
            Assert.AreEqual(employee.Salary, document.GetField<Decimal>("Salary"));
            Assert.AreEqual(employee.Commission, document.GetField<Double>("Commission"));

            Assert.AreEqual(employee.Allowance, document.GetField<float>("Allowance"));

            Assert.AreEqual(employee.IsMarried, document.GetField<bool>("IsMarried"));

            Assert.IsNotNull(employee.SomeIntegerList);
            Assert.That(document.GetField<List<int>>("SomeIntegerList"), Is.EquivalentTo(employee.SomeIntegerList));

            Assert.IsNotNull(employee.SomeDecimalList);
            Assert.That(document.GetField<List<decimal>>("SomeDecimalList"), Is.EquivalentTo(employee.SomeDecimalList));

            Assert.IsNotNull(employee.SomeDecomeArray);
            Assert.That(document.GetField<List<decimal>>("SomeDecomeArray"), Is.EquivalentTo(employee.SomeDecomeArray));

            var result = document.To<DemoEmployee>();

        }