コード例 #1
0
        public void TestUnsupportedOperationsThrow()
        {
            var cache        = Cache();
            var transactions = cache.Ignite.GetTransactions();

            Action <object> dummy = obj => { };

            Action <ITransaction>[] actions =
            {
                t => t.Commit(),
                t => t.CommitAsync(),
                t => dummy(t.StartTime),
                t => dummy(t.ThreadId),
                t => t.AddMeta("test",             "test"),
                t => t.Meta <string>("test"),
                t => t.RemoveMeta <string>("test"),
            };

            using (transactions.TxStart())
            {
                var local      = transactions.GetLocalActiveTransactions().Single();
                var constraint = new ReusableConstraint(Is.TypeOf <InvalidOperationException>()
                                                        .And.Message.EqualTo("Operation is not supported by rollback only transaction."));
                foreach (var action in actions)
                {
                    Assert.Throws(constraint, () => action(local));
                }
            }
        }
コード例 #2
0
        public static IAssertionResult <TT, TS> ThatNunit <TT, TS>(this IValueProvider <TT, TS> valueProvider, IResolveConstraint constraint)
        {
            var reusableConstraint = new ReusableConstraint(constraint);
            var assertion          = Assertion.FromDelegate <TT>(x => NUnit.Framework.Assert.That(x, reusableConstraint));

            return(valueProvider.Assert(assertion, Helper.AssertionConfiguration));
        }
コード例 #3
0
        public void TestDisconnect()
        {
            var cache = GetTransactionalCache();

            var constraint = new ReusableConstraint(Is.TypeOf <IgniteClientException>()
                                                    .And.Message.EqualTo("Transaction context has been lost due to connection errors."));

            try
            {
                using (Client.GetTransactions().TxStart())
                {
                    var igniteToStop = new[] { (int?)null, 1, 2 }
                    .Select(i => GetIgnite(i))
                    .FirstOrDefault(ign => ign.GetTransactions().GetLocalActiveTransactions().Any());

                    Assert.IsNotNull(igniteToStop);
                    Ignition.Stop(igniteToStop.Name, true);

                    Assert.Catch(() => cache.Put(1, 1));
                    Assert.Throws(constraint, () => cache.Put(1, 1));
                }
            }
            catch (IgniteClientException ex)
            {
                Assert.That(ex, constraint);
            }

            Assert.DoesNotThrow(() => cache.Put(1, 1));
            Assert.IsNull(Client.GetTransactions().Tx);
        }
コード例 #4
0
        //todo прокинуть timeouts
        public static IAssertionResult <T, TSource> That <T, TSource>(this IValueProvider <T, TSource> valueProvider, IResolveConstraint constraint, string message, int?timeout = null)
        {
            var reusableConstraint     = new ReusableConstraint(constraint);
            var assertionDelegate      = Assertion.FromDelegate <T>(x => Assert.That(x, reusableConstraint, message));
            var assertionConfiguration = timeout.GetConfiguration();

            return(valueProvider.Assert(assertionDelegate, assertionConfiguration));
        }
コード例 #5
0
        public void ReusableConstraintsTest()
        {
            ReusableConstraint myConstraintNotNull  = Is.Not.Null;
            ReusableConstraint myConstraintNotEmpty = Is.Not.Empty;
            ReusableConstraint myConstraint         = myConstraintNotNull.Resolve() & myConstraintNotEmpty.Resolve();

            Assert.That("Not a null and empty", myConstraint);
        }
コード例 #6
0
            public void ReusableConstraints()
            {
                // Create a constraint.
                ReusableConstraint isNotEqualTo4 = Is.Not.EqualTo(4);

                // This one will resolve and succeed.
                Assert.That(5, isNotEqualTo4);

                // This one will now succeed too.
                Assert.That(6, isNotEqualTo4);
            }
コード例 #7
0
        public void TestMultipleRollbackThrows()
        {
            var cache        = Cache();
            var transactions = cache.Ignite.GetTransactions();

            using (transactions.TxStart())
            {
                var local = (TransactionRollbackOnlyProxy)transactions.GetLocalActiveTransactions().Single();
                local.Rollback();
                var constraint = new ReusableConstraint(Is.TypeOf <InvalidOperationException>()
                                                        .And.Message.Contains("Transaction " + local.Id + " is closed"));
                Assert.Throws(constraint, () => local.Rollback());
                Assert.Throws(constraint, () => local.RollbackAsync().Wait());
            }
        }
コード例 #8
0
        public static void That <T, TSource>(this IValueProvider <T, TSource> provider, IResolveConstraint constraint, string failMessage = "")
        {
            var reusableConstraint = new ReusableConstraint(constraint);
            var assertion          = Assertion.FromDelegate <T>(x =>
            {
                using (new TestExecutionContext.IsolatedContext())
                {
                    Assert.That(x, reusableConstraint, message: failMessage);
                }
            });

            Kontur.RetryableAssertions.Wait.Assertion(provider, new AssertionConfiguration <T>
            {
                Timeout          = 20_000,
                Interval         = 100,
                Assertion        = assertion,
                ExceptionMatcher = exceptionMatcher,
            });
コード例 #9
0
        public void TestTimeout()
        {
            var timeout = TimeSpan.FromMilliseconds(200);
            var cache   = GetTransactionalCache();

            cache.Put(1, 1);
            using (var tx = Client.GetTransactions().TxStart(TransactionConcurrency.Pessimistic,
                                                             TransactionIsolation.ReadCommitted,
                                                             timeout))
            {
                Thread.Sleep(TimeSpan.FromMilliseconds(300));
                var constraint = new ReusableConstraint(Is.TypeOf <IgniteClientException>()
                                                        .And.Message.Contains("Cache transaction timed out"));
                Assert.Throws(constraint, () => cache.Put(1, 10));
                Assert.Throws(constraint, () => tx.Commit());
            }

            Assert.AreEqual(1, cache.Get(1));
        }
コード例 #10
0
        public void TestThrowsIfEndAlreadyCompletedTransaction()
        {
            var tx = Client.GetTransactions().TxStart();

            tx.Commit();

            var constraint = new ReusableConstraint(Is.TypeOf <InvalidOperationException>()
                                                    .And.Message.Contains("Transaction")
                                                    .And.Message.Contains("is closed"));

            Assert.Throws(constraint, () => tx.Commit());
            Assert.Throws(constraint, () => tx.Rollback());

            using (tx = Client.GetTransactions().TxStart())
            {
            }

            Assert.Throws(constraint, () => tx.Commit());
            Assert.Throws(constraint, () => tx.Rollback());
        }
コード例 #11
0
        public static IAssertionResult <T, TSource> That <T, TSource>(this IValueProvider <T, TSource> provider, IResolveConstraint constraint)
        {
            var reusableConstraint = new ReusableConstraint(constraint);
            var assertion          = Assertion.FromDelegate <T>(x =>
            {
                using (new TestExecutionContext.IsolatedContext())
                {
                    NUnit.Framework.Assert.That(x, reusableConstraint);
                }
            });
            var configuration = new AssertionConfiguration <T>
            {
                Timeout          = 2000,
                Interval         = 100,
                Assertion        = assertion,
                ExceptionMatcher = ExceptionMatcher.FromTypes(typeof(WebDriverException), typeof(InvalidOperationException), typeof(ElementNotFoundException))
            };

            return(Kontur.RetryableAssertions.Wait.Assertion(provider, configuration));
        }
コード例 #12
0
        static Dictionary <string, ReusableConstraint> IncompatibleFieldType(Dictionary <string, ReusableConstraint> expectedCaseToConstraint)
        {
            var newExpectedCaseToConstraint = new Dictionary <string, ReusableConstraint>(expectedCaseToConstraint);

            foreach (var pair in expectedCaseToConstraint)
            {
                var testCaseName       = pair.Key;
                var expectedConstraint = pair.Value.Resolve();
                if (expectedConstraint is SkipTestConstraint)
                {
                    continue;
                }
                var expectedExceptionType = TestTools.ThrowsConstraintExceptionType(expectedConstraint);
                if (expectedExceptionType is null || expectedExceptionType == typeof(NullReferenceException))
                {
                    newExpectedCaseToConstraint[testCaseName] = new ReusableConstraint(Throws.TypeOf <NullReferenceException>());
                }
            }
            return(newExpectedCaseToConstraint);
        }
コード例 #13
0
ファイル: CacheLinqTest.Misc.cs プロジェクト: pks-os/gridgain
        public void TestInvokeThrowsNotSupportedException()
        {
            var constraint = new ReusableConstraint(Is.TypeOf <NotSupportedException>()
                                                    .And.Message.StartsWith("The LINQ expression '")
                                                    .And.Message.Contains("Invoke")
                                                    .And.Message.Contains(
                                                        "could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable() or ToList()."));

            Func <ICacheEntry <int, Person>, bool> filter = entry => false;

            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            Assert.Throws(constraint, () => GetPersonCache().AsCacheQueryable()
                          .Where(x => filter(x))
                          .ToList());

            Func <ICacheEntry <int, Person>, int> selector = x => x.Key;

            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            Assert.Throws(constraint, () => GetPersonCache().AsCacheQueryable()
                          .Select(x => selector(x))
                          .FirstOrDefault());
        }
コード例 #14
0
        public static Transmission AddPropertyContraint(this Transmission transmission, ReusableConstraint constraint, string propertyName)
        {
            transmission.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => {
                var t = sender as Transmission;
                if (e.PropertyName == propertyName)
                {
                    Assert.That(t, Has.Property(propertyName));
                    var value = t.GetType().GetProperty(propertyName).GetValue(t, null);
                    if (value != null)
                    {
                        Assert.That(value, constraint, propertyName);
                    }
                }
            };

            return(transmission);
        }
コード例 #15
0
            void Run(string testSuiteLabel, string testCaseName, IATestCase <T, F> testCase, ReusableConstraint expectedConstraint)
            {
                TestTools.Log(testCaseName + ":", writeLine: false);
                var testCaseLabel = $"{testSuiteLabel}, testCase={testCaseName}";

                var resolvedConstraint = expectedConstraint.Resolve();

                if (resolvedConstraint is SkipTestConstraint)
                {
                    TestTools.Log(resolvedConstraint);
                    return;
                }

                var instance = field.IsStatic ? default : CloneInstancePrototype <T>(instanceType);
                               var origValue             = GetOrigValue(field);
                               var expectedExceptionType = TestTools.ThrowsConstraintExceptionType(resolvedConstraint);

                               ConstraintResult constraintResult;

                               if (expectedExceptionType is null || expectedExceptionType == typeof(IncompatibleFieldTypeException))
                               {
                                   constraintResult = TestTools.AssertThat(() =>
                    {
                        Assert.AreNotEqual(origValue, testValue, "{0}: expected !Equals(origValue, testValue) (indicates static field didn't get reset properly)", testCaseLabel);
                        var value = testCase.Get(ref instance);
                        // The ?.ToString() is a trick to ensure that value is fully evaluated from the ref value.
                        _ = value?.ToString();
                        Assert.AreEqual(TryConvert(origValue), value, "{0}: expected Equals(origValue, value)", testCaseLabel);
                        testCase.Set(ref instance, testValue);
                        var newValue = field.GetValue(instance);
                        Assert.AreEqual(testValue, TryConvert(newValue), "{0}: expected Equals(testValue, field.GetValue(instance))", testCaseLabel);
                        TestTools.Log($"{field.Name}: {origValue} => {testCase.Get(ref instance)}");
                        testCase.Set(ref instance, value); // reset field value
                        if (field.FieldType.IsInstanceOfType(newValue) is false)
                        {
                            throw new IncompatibleFieldTypeException($"expected field.GetValue(instance) is {field.FieldType.Name} " +
                                                                     "(runtime sometimes allows setting fields to values of incompatible types without any above checks failing/throwing)");
                        }
                    }, expectedConstraint, testCaseLabel);
                               }