Пример #1
0
        // Initialize static fields that are sensitive to order of initialization.
        // Most compilers would probably intialize these in lexical order but it
        // may not be guaranteed in all cases so we do it directly.
        static DelayedConstraintTests()
        {
            DelegateReturningValue = new ActualValueDelegate(MethodReturningValue);
            DelegateReturningFalse = new ActualValueDelegate(MethodReturningFalse);
            DelegateReturningZero = new ActualValueDelegate(MethodReturningZero);

            SuccessDelegates = new ActualValueDelegate<object>[] { DelegateReturningValue };
            FailureDelegates = new ActualValueDelegate<object>[] { DelegateReturningFalse, DelegateReturningZero };
        }
Пример #2
0
        /// <summary>
        /// Test whether the constraint is satisfied by a delegate
        /// </summary>
        /// <param name="del">The delegate whose value is to be tested</param>
        /// <returns>A ConstraintResult</returns>
        public override ConstraintResult ApplyTo <TActual>(ActualValueDelegate <TActual> del)
        {
            long now      = Stopwatch.GetTimestamp();
            long delayEnd = TimestampOffset(now, DelayInterval.AsTimeSpan);

            object actual;

            if (PollingInterval.IsNotZero)
            {
                long nextPoll = TimestampOffset(now, PollingInterval.AsTimeSpan);
                while ((now = Stopwatch.GetTimestamp()) < delayEnd)
                {
                    if (nextPoll > now)
                    {
                        ThreadUtility.BlockingDelay((int)TimestampDiff(delayEnd < nextPoll ? delayEnd : nextPoll, now).TotalMilliseconds);
                    }
                    nextPoll = TimestampOffset(now, PollingInterval.AsTimeSpan);

                    actual = InvokeDelegate(del);

                    try
                    {
                        ConstraintResult result = BaseConstraint.ApplyTo(actual);
                        if (result.IsSuccess)
                        {
                            return(new ConstraintResult(this, actual, true));
                        }
                    }
                    catch (Exception)
                    {
                        // Ignore any exceptions when polling
                    }
                }
            }
            if ((now = Stopwatch.GetTimestamp()) < delayEnd)
            {
                ThreadUtility.BlockingDelay((int)TimestampDiff(delayEnd, now).TotalMilliseconds);
            }

            actual = InvokeDelegate(del);
            return(new ConstraintResult(this, actual, BaseConstraint.ApplyTo(actual).IsSuccess));
        }
        public void Delete_RemoveNewsWithDuplicatedId_ReturnInvalidOperationException()
        {
            // Arrange
            var news = new News
            {
                Id = 0
            };

            Use <INewsRepository>()
            .Setup(s => s.Query(It.IsAny <NewsSpecifications>()))
            .Returns(new List <News> {
                news, news
            });

            // Act
            ActualValueDelegate <object> deleteDelegate = () => Sub.Delete(news.Id);

            // Assert
            Assert.That(deleteDelegate, Throws.TypeOf <InvalidOperationException>());
        }
Пример #4
0
        public void Test_CodableConcept_TokenIndexSetter_UnsupportedCodeType()
        {
            //Arrange
            var CodeableConcept = new CodeableConcept();

            CodeableConcept.Coding = new System.Collections.Generic.List <Coding>()
            {
                new Coding()
                {
                    Code = "SomeCode", System = "SomeSystem"
                }
            };

            TokenIndex Index = new TokenIndex();

            //Act
            ActualValueDelegate <TokenIndex> testDelegate = () => IndexSetterFactory.Create(typeof(TokenIndex)).Set(CodeableConcept, Index) as TokenIndex;

            //Assert
            Assert.That(testDelegate, Throws.TypeOf <Pyro.Common.BusinessEntities.Dto.DtoPyroException>());
        }
Пример #5
0
        public void TestNxNode()
        {
            var evaluator = new ConditionEvaluator();

            var sut = new PermissionsService(new ConditionParser(), (new PermissionsScanner().All(typeof(Permissions))), evaluator);
            ActualValueDelegate <bool> del = () =>
            {
                sut.InsertSerialized(new GrantStub
                {
                    GrantType       = GrantType.Allow,
                    Index           = 1,
                    NodeKey         = "Dog.Feed",
                    PermissionType  = PermissionType.ResourceBound,
                    Identifier      = 1,
                    PermissionChain = PermissionChainName
                });
                return(true);
            };

            Assert.That(del, Throws.TypeOf <ArgumentException>());
        }
Пример #6
0
        public void Test_Address_TokenIndexSetter_UnsupportedCodeType()
        {
            //Arrange
            var    TheCode    = Hl7.Fhir.Model.Bundle.SearchEntryMode.Include;
            string CodeString = TheCode.GetLiteral();
            //string CodeString = Hl7.Fhir.Introspection.EnumMapping.Create(typeof(Hl7.Fhir.Model.Bundle.SearchEntryMode)).GetLiteral(TheCode);

            var Code = new Code <Bundle.SearchEntryMode>();

            Code.Value = TheCode;

            TokenIndex Index = new TokenIndex();

            //Act
            ActualValueDelegate <TokenIndex> testDelegate = () => IndexSetterFactory.Create(typeof(TokenIndex)).Set(Code, Index) as TokenIndex;

            //Act
            Index = IndexSetterFactory.Create(typeof(TokenIndex)).Set(Code, Index) as TokenIndex;

            //Assert
            Assert.IsNull(Index);
        }
Пример #7
0
        /// <summary>
        /// Test whether the constraint is satisfied by a delegate
        /// </summary>
        /// <param name="del">The delegate whose value is to be tested</param>
        /// <returns>True for if the base constraint fails, false if it succeeds</returns>
        public override bool Matches(ActualValueDelegate del)
        {
            int remainingDelay = delayInMilliseconds;

            while (pollingInterval > 0 && pollingInterval < remainingDelay)
            {
                remainingDelay -= pollingInterval;
                Thread.Sleep(pollingInterval);
                this.actual = del();
                if (baseConstraint.Matches(actual))
                {
                    return(true);
                }
            }

            if (remainingDelay > 0)
            {
                Thread.Sleep(remainingDelay);
            }
            this.actual = del();
            return(baseConstraint.Matches(actual));
        }
Пример #8
0
        /// <summary>
        /// Truncated Assert.That implementation throwing no exceptions on failure
        /// </summary>
        /// <typeparam name="TActual"></typeparam>
        /// <param name="actual"></param>
        /// <param name="expression"></param>
        /// <param name="timeout">Overrides RequestTimeout</param>
        /// <returns>whether the test passed</returns>
        private static bool TryAssertPoll <TActual>(ActualValueDelegate <TActual> del,
                                                    Func <IResolveConstraint> expression,
                                                    int?timeout)
        {
            int pollFor    = timeout ?? RequestTimeout;
            var constraint = expression().Resolve();

            for (int i = 0; i < pollFor * 1000 / FAST_POLL_MILLISECONDS; i++)
            {
                try
                {
                    var result = constraint.ApplyTo(del);
                    if (result.IsSuccess)
                    {
                        return(true);    // break on success
                    }
                }
                catch { }
                Thread.Sleep(FAST_POLL_MILLISECONDS);
            }              // continue with attempts until IsSuccess or RequestTimeout
            return(false); // return on failure
        }
Пример #9
0
 /// <summary>
 /// Apply a constraint to an actual value, succeeding if the constraint is satisfied
 /// and throwing an assertion exception on failure.
 /// </summary>
 /// <typeparam name="TActual">The Type being compared.</typeparam>
 /// <param name="del">An ActualValueDelegate returning the value to be tested</param>
 /// <param name="expr">A Constraint expression to be applied</param>
 public static void That <TActual>(ActualValueDelegate <TActual> del, IResolveConstraint expr)
 {
     PerformAssertWithConstraint <TActual>(expr, del);
 }
Пример #10
0
 /// <summary>
 /// Apply a constraint to an actual value, succeeding if the constraint
 /// is satisfied and throwing an InconclusiveException on failure.
 /// </summary>
 /// <param name="expr">A Constraint expression to be applied</param>
 /// <param name="del">An ActualValueDelegate returning the value to be tested</param>
 static public void That <TActual>(ActualValueDelegate <TActual> del, IResolveConstraint expr)
 {
     Assume.That(del, expr.Resolve(), null, null);
 }
Пример #11
0
 public override bool Matches(ActualValueDelegate del)
 {
     return(Matches(new ObjectInvocationDescriptor(del)));
 }
Пример #12
0
 public override bool Matches(ActualValueDelegate del)
 {
     try
     {
         var response = del();
         actual = "SUCCESS";
         return false; // the delegate must throw a ResourceException to indicate failure
     }
     catch (ResourceException ex)
     {
         actual = ex.Status;
         return ex.Status == Status;
     }
 }
Пример #13
0
 public override void ResolveFunc <T1>(
     ActualValueDelegate <T1> actual,
     IResolveConstraint constraint,
     Func <string> message
     ) => Ignore.Unless(actual, constraint, message);
Пример #14
0
 /// <summary>
 /// Test whether the constraint is satisfied by an
 /// ActualValueDelegate that returns the value to be tested.
 /// The default implementation simply evaluates the delegate
 /// but derived classes may override it to provide for delayed
 /// processing.
 /// </summary>
 /// <param name="del">An <see cref="ActualValueDelegate" /></param>
 /// <returns>True for success, false for failure</returns>
 public virtual bool Matches(ActualValueDelegate del)
 {
     return(Matches(del()));
 }
Пример #15
0
 /// <summary>
 /// Converts an ActualValueDelegate to a TestDelegate
 /// before calling the primary overload.
 /// </summary>
 /// <param name="del"></param>
 /// <returns></returns>
 public override ConstraintResult ApplyTo <TActual>(ActualValueDelegate <TActual> del)
 {
     //TestDelegate testDelegate = new TestDelegate(delegate { del(); });
     //return ApplyTo((object)testDelegate);
     return(ApplyTo(new GenericInvocationDescriptor <TActual>(del)));
 }
Пример #16
0
 public void FailsWithBadDelegates(ActualValueDelegate<object> del)
 {
     Assert.IsFalse(theConstraint.ApplyTo(del).IsSuccess);
 }
Пример #17
0
 /// <summary>
 /// Apply a constraint to an actual value, succeeding if the constraint
 /// is satisfied and issuing a warning on failure.
 /// </summary>
 /// <typeparam name="TActual">The Type being compared.</typeparam>
 /// <param name="del">An ActualValueDelegate returning the value to be tested</param>
 /// <param name="expr">A Constraint expression to be applied</param>
 public static void Unless <TActual>(ActualValueDelegate <TActual> del, IResolveConstraint expr)
 {
     Warn.Unless(del, expr.Resolve(), null, null);
 }
Пример #18
0
 public void SucceedsWithGoodDelegates(ActualValueDelegate<object> del)
 {
     SetValuesAfterDelay(300);
     Assert.That(theConstraint.ApplyTo(del).IsSuccess);
 }
        public void that_e_true_com_actual_value_delegate_e_array_de_object_e_mensagem_deve_retornar_excecao_de_expressao()
        {
            string message = string.Empty;

            try
            {
                IAssert assert = new RealAssert();
                object[] lista = new object[0];
                ActualValueDelegate del = new ActualValueDelegate(SuportDelegate);
                ResolvableConstraintExpression expression = new ResolvableConstraintExpression();

                assert.That(del, expression, "jhghjg");
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }

            Assert.AreEqual(message, "A partial expression may not be resolved");
        }
        public void that_del_e_expression_mensagem_e_array_de_object_nao_deve_retornar_execao()
        {
            IAssert Assert = new FakeAssert();
            object[] lista = new object[0];
            ActualValueDelegate del = new ActualValueDelegate(dele);
            ResolvableConstraintExpression expression = new ResolvableConstraintExpression();

            Assert.That(del, expression, "", lista);
        }
Пример #21
0
 /// <summary>
 /// Apply a constraint to an actual value, succeeding if the constraint is satisfied
 /// and throwing an assertion exception on failure.
 /// </summary>
 /// <typeparam name="TActual">The Type being compared.</typeparam>
 /// <param name="del">An ActualValueDelegate returning the value to be tested</param>
 /// <param name="expr">A Constraint expression to be applied</param>
 /// <param name="getExceptionMessage">A function to build the message included with the Exception</param>
 public static void That <TActual>(ActualValueDelegate <TActual> del, IResolveConstraint expr, Func <string> getExceptionMessage)
 {
     PerformAssertWithConstraint <TActual>(expr, del, getExceptionMessage);
 }
Пример #22
0
 /// <summary>
 /// Applies the constraint to an ActualValueDelegate that returns
 /// the value to be tested. The default implementation simply evaluates
 /// the delegate but derived classes may override it to provide for
 /// delayed processing.
 /// </summary>
 /// <param name="del">An ActualValueDelegate</param>
 /// <returns>A ConstraintResult</returns>
 public override ConstraintResult ApplyTo <TActual>(ActualValueDelegate <TActual> del)
 {
     return(ApplyTo((Delegate)del));
 }
Пример #23
0
 /// <summary>
 /// Apply a constraint to an actual value, succeeding if the constraint is satisfied
 /// and throwing an assertion exception on failure.
 /// </summary>
 /// <typeparam name="TActual">The Type being compared.</typeparam>
 /// <param name="del">An ActualValueDelegate returning the value to be tested</param>
 /// <param name="expr">A Constraint expression to be applied</param>
 /// <param name="message">The message that will be displayed on failure</param>
 /// <param name="args">Arguments to be used in formatting the message</param>
 public static void That <TActual>(ActualValueDelegate <TActual> del, IResolveConstraint expr, string message, params object[] args)
 {
     PerformAssertWithConstraint <TActual>(expr, del, message: message, args: args);
 }
Пример #24
0
 /// <summary>
 /// Apply a constraint to an actual value, succeeding if the constraint
 /// is satisfied and throwing an assertion exception on failure.
 /// </summary>
 /// <param name="del">An ActualValueDelegate returning the value to be tested</param>
 /// <param name="expr">A Constraint expression to be applied</param>
 /// <param name="message">The message that will be displayed on failure</param>
 /// <param name="args">Arguments to be used in formatting the message</param>
 public void Expect(ActualValueDelegate del, IResolveConstraint expr, string message, params object[] args)
 {
     Assert.That(del, expr, message, args);
 }
Пример #25
0
 public GenericInvocationDescriptor(ActualValueDelegate <T> del)
 {
     _del = del;
 }
        public void that_e_true_com_actual_value_delegate_e_resolve_constraint_e_mensagem_nao_deve_retornar_execao()
        {
            IAssert Assert = new FakeAssert();
            object[] lista = new object[0];
            ActualValueDelegate del = new ActualValueDelegate(dele);
            ResolvableConstraintExpression expression = new ResolvableConstraintExpression();

            Assert.That(del, expression, "mensagem");
        }
Пример #27
0
        public void TestConstructor2()
        {
            ActualValueDelegate <object> d = () => new Circle(double.NaN);

            Assert.That(d, Throws.TypeOf <ArgumentException>());
        }
Пример #28
0
 /// <summary>
 /// Apply a constraint to an actual value, succeeding if the constraint
 /// is satisfied and throwing an InconclusiveException on failure.
 /// </summary>
 /// <param name="expr">A Constraint expression to be applied</param>
 /// <param name="del">An ActualValueDelegate returning the value to be tested</param>
 /// <param name="message">The message that will be displayed on failure</param>
 static public void That(ActualValueDelegate del, IResolveConstraint expr, string message)
 {
     Assume.That(del, expr.Resolve(), message, null);
 }
Пример #29
0
#pragma warning restore 3006

        /// <summary>
        /// Retrieves the value to be tested from an ActualValueDelegate.
        /// The default implementation simply evaluates the delegate but derived
        /// classes may override it to provide for delayed processing.
        /// </summary>
        /// <param name="del">An ActualValueDelegate</param>
        /// <returns>Delegate evaluation result</returns>
        protected virtual object GetTestObject <TActual>(ActualValueDelegate <TActual> del)
        {
            return(del());
        }
Пример #30
0
 public ConstraintResult ApplyTo <TActual>(ActualValueDelegate <TActual> del)
 {
     return(CaptureResult(resolvedParent.ApplyTo(del)));
 }
Пример #31
0
 /// <summary>
 /// Apply a constraint to an actual value, succeeding if the constraint
 /// is satisfied and throwing an assertion exception on failure.
 /// </summary>
 /// <param name="expr">A Constraint expression to be applied</param>
 /// <param name="del">An ActualValueDelegate returning the value to be tested</param>
 /// <param name="message">The message that will be displayed on failure</param>
 public void Expect(ActualValueDelegate del, IResolveConstraint expr, string message)
 {
     Assert.That(del, expr.Resolve(), message, null);
 }
Пример #32
0
 public static void Check <T>(ActualValueDelegate <T> del, int count)
 {
     Check(del, count, 0.8);
 }
Пример #33
0
 /// <summary>
 /// Apply a constraint to an actual value, succeeding if the constraint
 /// is satisfied and throwing an assertion exception on failure.
 /// </summary>
 /// <param name="expr">A Constraint expression to be applied</param>
 /// <param name="del">An ActualValueDelegate returning the value to be tested</param>
 public void Expect(ActualValueDelegate del, IResolveConstraint expr)
 {
     Assert.That(del, expr.Resolve(), null, null);
 }
Пример #34
0
 public ObjectInvocationDescriptor(ActualValueDelegate del)
 {
     _del = del;
 }
Пример #35
0
 /// <summary>
 /// Converts an ActualValueDelegate to a TestDelegate
 /// before calling the primary overload.
 /// </summary>
 /// <param name="del"></param>
 /// <returns></returns>
 public override bool Matches(ActualValueDelegate del)
 {
     TestDelegate testDelegate = new TestDelegate(delegate { del(); });
     return Matches((object)testDelegate);
 }
Пример #36
0
 public void SucceedsWithGoodDelegates(ActualValueDelegate del)
 {
     SetValueTrueAfterDelay(300);
     Assert.That(theConstraint.Matches(del));
 }
Пример #37
0
 public override bool Matches <T>(ActualValueDelegate <T> del)
 {
     return(Matches(new GenericInvocationDescriptor <T>(del)));
 }
Пример #38
0
 public void FailsWithBadDelegates(ActualValueDelegate del)
 {
     Assert.IsFalse(theConstraint.Matches(del));
 }
Пример #39
0
        /// <summary>
        /// Converts an ActualValueDelegate to a TestDelegate
        /// before calling the primary overload.
        /// </summary>
        /// <param name="del"></param>
        /// <returns></returns>
        public override bool Matches(ActualValueDelegate del)
        {
            TestDelegate testDelegate = new TestDelegate(delegate { del(); });

            return(Matches((object)testDelegate));
        }
Пример #40
0
        public void ValidateEmptyDataNullOrEmpty(string testData)
        {
            ActualValueDelegate <Object> testDelegate = () => Utilities.ValidateEmptyData(testData);

            Assert.That(testDelegate, Throws.TypeOf <QuandlDataNotFoundException>());
        }