Example #1
0
        private void SubComponentFieldNotInserted_Generic(System.Type type)
        {
            int id;

            using (ISession session = OpenSession())
                using (ITransaction tx = session.BeginTransaction())
                {
                    BaseParent p = (BaseParent)Activator.CreateInstance(type);
                    p.Component.SubComponent.FieldNotInserted = 10;
                    session.Save(p);

                    tx.Commit();

                    id = p.Id;
                }

            using (ISession session = OpenSession())
                using (ITransaction tx = session.BeginTransaction())
                {
                    BaseParent p = (BaseParent)session.Get(type, id);

                    Assert.AreEqual(0, p.Component.SubComponent.FieldNotInserted,
                                    "Field should not have been inserted.");

                    tx.Commit();
                }
        }
        private async Task ComponentFieldNotInserted_GenericAsync(System.Type type, CancellationToken cancellationToken = default(CancellationToken))
        {
            int id;

            using (ISession session = OpenSession())
                using (ITransaction tx = session.BeginTransaction())
                {
                    BaseParent p = (BaseParent)Activator.CreateInstance(type);
                    p.Component.FieldNotInserted = 10;
                    await(session.SaveAsync(p, cancellationToken));

                    await(tx.CommitAsync(cancellationToken));

                    id = p.Id;
                }

            using (ISession session = OpenSession())
                using (ITransaction tx = session.BeginTransaction())
                {
                    BaseParent p = (BaseParent)await(session.GetAsync(type, id, cancellationToken));

                    Assert.AreEqual(0, p.Component.FieldNotInserted,
                                    "Field should not have been inserted.");

                    await(tx.CommitAsync(cancellationToken));
                }
        }
Example #3
0
        private void ComponentFieldNotUpdated_Generic(System.Type type)
        {
            int id;
            int fieldInitialValue = 10;
            int fieldNewValue     = 30;

            using (ISession session = OpenSession())
                using (ITransaction tx = session.BeginTransaction())
                {
                    BaseParent p = (BaseParent)Activator.CreateInstance(type);
                    p.Component.FieldNotUpdated = fieldInitialValue;
                    session.Save(p);

                    tx.Commit();

                    id = p.Id;
                }

            using (ISession session = OpenSession())
                using (ITransaction tx = session.BeginTransaction())
                {
                    BaseParent p = (BaseParent)session.Get(type, id);

                    Assert.AreEqual(fieldInitialValue, p.Component.FieldNotUpdated,
                                    String.Format("Field should have initial inserted value of {0}.", fieldInitialValue));

                    p.Component.FieldNotUpdated = fieldNewValue;
                    p.Component.NormalField     = 10;

                    tx.Commit();
                }

            using (ISession session = OpenSession())
                using (ITransaction tx = session.BeginTransaction())
                {
                    BaseParent p = (BaseParent)session.Get(type, id);

                    Assert.AreEqual(fieldInitialValue, p.Component.FieldNotUpdated,
                                    "Field should not have been updated.");

                    tx.Commit();
                }
        }
        private async Task ComponentFieldNotUpdated_GenericAsync(System.Type type, CancellationToken cancellationToken = default(CancellationToken))
        {
            int id;
            int fieldInitialValue = 10;
            int fieldNewValue     = 30;

            using (ISession session = OpenSession())
                using (ITransaction tx = session.BeginTransaction())
                {
                    BaseParent p = (BaseParent)Activator.CreateInstance(type);
                    p.Component.FieldNotUpdated = fieldInitialValue;
                    await(session.SaveAsync(p, cancellationToken));

                    await(tx.CommitAsync(cancellationToken));

                    id = p.Id;
                }

            using (ISession session = OpenSession())
                using (ITransaction tx = session.BeginTransaction())
                {
                    BaseParent p = (BaseParent)await(session.GetAsync(type, id, cancellationToken));

                    Assert.AreEqual(fieldInitialValue, p.Component.FieldNotUpdated,
                                    String.Format("Field should have initial inserted value of {0}.", fieldInitialValue));

                    p.Component.FieldNotUpdated = fieldNewValue;
                    p.Component.NormalField     = 10;

                    await(tx.CommitAsync(cancellationToken));
                }

            using (ISession session = OpenSession())
                using (ITransaction tx = session.BeginTransaction())
                {
                    BaseParent p = (BaseParent)await(session.GetAsync(type, id, cancellationToken));

                    Assert.AreEqual(fieldInitialValue, p.Component.FieldNotUpdated,
                                    "Field should not have been updated.");

                    await(tx.CommitAsync(cancellationToken));
                }
        }