Example #1
0
        PersistenceTestResult TrySave()
        {
            IDataConnection conn = null;

            try
            {
                conn = spec.SessionProvider.GetConnection();
                using (var tran = conn.GetTransactionFactory().GetTransaction())
                {
                    identity = conn.GetPersister().Add(spec.Entity);
                    if (identity == null)
                    {
                        throw new InvalidOperationException($"The entity identity returned by {nameof(IPersister)}.{nameof(IPersister.Add)} should not be null.");
                    }
                    tran.Commit();
                }
            }
            catch (Exception ex)
            {
                return(new PersistenceTestResult(typeof(T))
                {
                    SaveException = ex
                });
            }
            finally
            {
                conn?.Dispose();
            }

            return(null);
        }
Example #2
0
        PersistenceTestResult TryCompare()
        {
            IDataConnection conn = null;

            try
            {
                conn = spec.SessionProvider.GetConnection();
                conn.EvictFromCache(spec.Entity);

                var retrieved = conn.GetQuery().Get <T>(identity);
                if (ReferenceEquals(retrieved, null))
                {
                    return new PersistenceTestResult(typeof(T))
                           {
                               SavedObjectNotFound = true
                           }
                }
                ;

                var equalityResult = spec.EqualityRule.GetEqualityResult(spec.Entity, retrieved);
                EnsureEqualityResultMayBeReportedUpon(equalityResult);

                return(new PersistenceTestResult(typeof(T))
                {
                    EqualityResult = equalityResult
                });
            }
            catch (Exception ex)
            {
                return(new PersistenceTestResult(typeof(T))
                {
                    ComparisonException = ex
                });
            }
            finally
            {
                conn?.Dispose();
            }
        }
Example #3
0
        PersistenceTestResult TrySetup()
        {
            IDataConnection conn = null;

            try
            {
                conn = spec.SessionProvider.GetConnection();
                spec.Setup?.Invoke(conn);
            }
            catch (Exception ex)
            {
                return(new PersistenceTestResult(typeof(T))
                {
                    SetupException = ex
                });
            }
            finally
            {
                conn?.Dispose();
            }

            return(null);
        }
Example #4
0
        protected T DoInSession <T>(Block <T> block)
        {
            IDataSessionManager sessionManager = Resolve <IDataSessionManager>();

            using (IDataSession session = sessionManager.CreateSession(DatabaseName))
            {
                IDataConnection connection = null;

                try
                {
                    connection = session.OpenConnection();

                    return(block());
                }
                finally
                {
                    if (connection != null)
                    {
                        connection.Dispose();
                    }
                }
            }
        }