Beispiel #1
0
        public static void ValidateCachesException()
        {
            var exception = Substitute.For <DbException>();

            var invalidConnection = Substitute.For <IDbConnection>();

            invalidConnection
            .When(x => x.Open())
            .Do(x =>
            {
                throw exception;
            });

            var factory = new DbConnectionFactory(LocalDbConnection, c => invalidConnection);

            try
            {
                factory.Validate();
            }
            catch (DbException)
            {
            }

            try
            {
                // This should cache the result and not call open.
                factory.Validate();
            }
            catch (DbException)
            {
            }

            invalidConnection.Received(1).Open();
        }
Beispiel #2
0
        public static void ValidateOpensConnectionEachTime()
        {
            var validConnection = Substitute.For <IDbConnection>();

            var factory = new DbConnectionFactory(LocalDbConnection, c => validConnection);

            const int CallCount = 2;

            for (int i = 0; i < CallCount; ++i)
            {
                Assert.DoesNotThrow(() => factory.Validate());
            }

            validConnection.Received(CallCount).Open();
        }
        public static void ValidateOpensConnectionEachTime()
        {
            var validConnection = Substitute.For<IDbConnection>();

            var factory = new DbConnectionFactory(LocalDbConnection, c => validConnection);

            const int CallCount = 2;

            for (int i = 0; i < CallCount; ++i)
            {
                Assert.DoesNotThrow(() => factory.Validate());
            }

            validConnection.Received(CallCount).Open();
        }
        public static void ValidateCachesException()
        {
            var exception = Substitute.For<DbException>();

            var invalidConnection = Substitute.For<IDbConnection>();

            invalidConnection
                .When(x => x.Open())
                .Do(x =>
                {
                    throw exception;
                });

            var factory = new DbConnectionFactory(LocalDbConnection, c => invalidConnection);

            try
            {
                factory.Validate();
            }
            catch (DbException)
            {
            }

            try
            {
                // This should cache the result and not call open.
                factory.Validate();
            }
            catch (DbException)
            {
            }

            invalidConnection.Received(1).Open();
        }