示例#1
0
 public void SetUp()
 {
     Matcher = new AndConstraint(new GreaterThanConstraint(40), new LessThanConstraint(50));
     GoodValues = new object[] { 42 };
     BadValues = new object[] { 37, 53 };
     Description = "greater than 40 and less than 50";
 }
示例#2
0
 protected override void SetUp()
 {
     Matcher     = new AndConstraint(Is.GreaterThan(40), Is.LessThan(50));
     GoodValues  = new object[] { 42 };
     BadValues   = new object[] { 37, 53 };
     Description = "greater than 40 and less than 50";
 }
示例#3
0
        /// <summary>
        /// Build a collection of constraint (in fact one by expected item)
        /// Pay really attention that CollectionContainsConstraint is expecting one unique item!
        /// So if you cant to check for several items, you need to apply several Constraint (one by expected item)
        /// </summary>
        protected virtual void BuildInternalConstraint()
        {
            NUnitCtr.Constraint ctr = null;
            foreach (var item in Expected)
            {
                var localCtr = new NUnitCtr.CollectionContainsConstraint(StringComparerHelper.Build(item));
                var usingCtr = localCtr.Using(Comparer);

                if (ctr != null)
                {
                    ctr = new AndConstraint(ctr, usingCtr);
                }
                else
                {
                    ctr = usingCtr;
                }
            }

            if (ctr == null)
            {
                ctr = new NUnitCtr.EmptyCollectionConstraint();
            }

            IResolveConstraint exp = ctr;

            InternalConstraint = exp.Resolve();
        }
示例#4
0
 public void SetUp()
 {
     Matcher     = new AndConstraint(new GreaterThanConstraint(40), new LessThanConstraint(50));
     GoodValues  = new object[] { 42 };
     BadValues   = new object[] { 37, 53 };
     Description = "greater than 40 and less than 50";
 }
        /// <summary>
        /// Asserts that the dictionary contains the specified key. Keys are compared using
        /// their <see cref="object.Equals(object)" /> implementation.
        /// </summary>
        /// <param name="expected">The expected key</param>
        /// <param name="because">
        /// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
        /// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
        /// </param>
        /// <param name="reasonArgs">
        /// Zero or more objects to format using the placeholders in <see cref="because" />.
        /// </param>
        public WhichValueConstraint <TKey, TValue> ContainKey(TKey expected,
                                                              string because = "", params object [] reasonArgs)
        {
            AndConstraint <GenericDictionaryAssertions <TKey, TValue> > andConstraint = ContainKeys(new [] { expected }, because, reasonArgs);

            return(new WhichValueConstraint <TKey, TValue>(andConstraint.And, Subject[expected]));
        }
示例#6
0
        private IConstraint ConvertJsonToConstraint(JObject jObject)
        {
            if (jObject["and"] != null)
            {
                var andConstraint = new AndConstraint();
                foreach (var item in jObject["and"])
                {
                    andConstraint.Add(ConvertJsonToConstraint((item as JObject)));
                }

                return(andConstraint);
            }
            if (jObject["or"] != null)
            {
                var orConstraint = new OrConstraint();
                foreach (var item in jObject["or"])
                {
                    orConstraint.Add(ConvertJsonToConstraint((item as JObject)));
                }

                return(orConstraint);
            }
            if (jObject["equals"] != null)
            {
                var equalsConstraint = new EqualsConstraint();

                equalsConstraint.Property     = jObject["equals"][0]["doc"]?.ToString();
                equalsConstraint.ValueToEqual = jObject["equals"][1]?.ToString();

                return(equalsConstraint);
            }
            if (jObject["in"] != null)
            {
                var inConstraint = new InConstraint();

                inConstraint.Property      = jObject["in"][0]["doc"]?.ToString();
                inConstraint.ValuesToEqual = jObject["in"][1]?.ToObject <string[]>();

                return(inConstraint);
            }
            if (jObject["paths"] != null)
            {
                var pathsConstraint = new PathConstraint();

                pathsConstraint.Fields = jObject["paths"][0]["doc"]?.ToString();

                return(pathsConstraint);
            }
            if (jObject["not"] != null)
            {
                var notConstraint = new NotConstraint();

                notConstraint.ConstraintToInvert = ConvertJsonToConstraint(jObject["not"] as JObject);

                return(notConstraint);
            }

            return(null);
        }
 public static ICollection <T> Then <T>(this AndConstraint <WaitableListAssertions <T> > andWaitableAssertion) where T : IWaitable
 {
     if (andWaitableAssertion == null)
     {
         throw new ArgumentNullException(nameof(andWaitableAssertion));
     }
     return(andWaitableAssertion.And.SubjectCollection);
 }
示例#8
0
        private static IConstraint CreateActionConstraint <TController>(ActionDescriptor actionDescriptor)
        {
            var controllerTypeConstraint = new ControllerTypeConstraint <TController>();
            var actionConstraint         = new ControllerActionConstraint(actionDescriptor);
            var contContraint            = new AndConstraint(controllerTypeConstraint, actionConstraint);

            return(contContraint);
        }
示例#9
0
        public virtual ConstraintDsl <TDsl> ExceptFor <TController>(Expression <Func <TController, object> > func) where TController : Controller
        {
            var actionDescriptor         = func.CreateActionDescriptor();
            var controllerTypeConstraint = new ControllerTypeConstraint <TController>();
            var actionConstraint         = new ControllerActionConstraint(actionDescriptor);
            var contContraint            = new AndConstraint(controllerTypeConstraint, actionConstraint);

            AddRegistration(CreateInstanceRegistration(new NotConstraint(contContraint), actionDescriptor, actionDescriptor.ControllerDescriptor, FilterScope.Action));
            return(this);
        }
示例#10
0
        /// <summary>
        /// Expects the current collection to contain all elements of <paramref name="expected"/> in that exact order.
        /// </summary>
        public static AndConstraint <GenericCollectionAssertions <T> > BeEqualTo <T>(this GenericCollectionAssertions <T> collectionShould, IReadOnlyList <T> expected)
        {
            AndConstraint <GenericCollectionAssertions <T> > andConstraint = collectionShould.HaveSameCount(expected);

            for (int i = 0; i < expected.Count; i++)
            {
                andConstraint = collectionShould.HaveElementAt(i, expected[i]);
            }

            return(andConstraint);
        }
示例#11
0
        /// <inheritdoc />
        public override ConstraintResult ApplyTo <TActual>(TActual actual)
        {
            var constraint = _constraints[0];

            for (var i = 1; i < _constraints.Length; i++)
            {
                constraint = new AndConstraint(constraint, _constraints[i]);
            }

            return(constraint.ApplyTo(actual));
        }
示例#12
0
        public void ConjoinedConstraints()
        {
            Constraint constrainedInRange = new AndConstraint(
                new GreaterThanConstraint(800),
                new LessThanConstraint(900));
            int actual = 850;

            Assert.That(actual, constrainedInRange);

            // This case can be simplified by using the constraint for ranges.
            Assert.That(actual, new RangeConstraint(800, 900));
        }
示例#13
0
        public AndConstraint <GenericCollectionAssertions <IbanCountry> > HaveConfiguredRegistry
        (
            IEnumerable <IbanCountry> registry,
            string because = "",
            params object[] becauseArgs
        )
        {
            AndConstraint <GenericCollectionAssertions <IbanCountry> > innerAssertion = null;

            VerifyCalled(should => innerAssertion = should.HaveRegistry(registry, because, becauseArgs));

            return(innerAssertion);
        }
示例#14
0
        public AndConstraint <GenericCollectionAssertions <TRule> > HaveConfiguredRule <TRule>
        (
            string because = "",
            params object[] becauseArgs
        )
            where TRule : IIbanValidationRule
        {
            AndConstraint <GenericCollectionAssertions <TRule> > innerAssertion = null;

            VerifyCalled(should => innerAssertion = should.HaveRule <TRule>(because, becauseArgs));

            return(innerAssertion);
        }
示例#15
0
文件: Tests.cs 项目: genveir/Advent
        private Set ParseSimpleSetFromOutput(string output)
        {
            var parts = output.Split(new char[] { '(', ')', 'S', 'E', 'T', '[', ']', ':', ' ' }, StringSplitOptions.RemoveEmptyEntries);

            var elements = new Constant[9];

            for (int n = 0; n < 18; n += 2)
            {
                var constraintVals = parts[n].Split(".").Select(int.Parse).ToArray();
                var constraint     = new AndConstraint(constraintVals[0], constraintVals[1]);

                var value = int.Parse(parts[n + 1]);

                elements[n / 2] = new Constant(value, constraint);
            }

            return(new Set(elements));
        }
        public AndConstraint <GenericCollectionAssertions <T> > ContainEquivalent(IEnumerable <T> expected)
        {
            var actual     = _assertions.Subject;
            var reason     = string.Empty;
            var reasonArgs = new object[0];

            if (expected == null)
            {
                throw new NullReferenceException("Cannot verify containment against a <null> collection");
            }
            var expectedList = expected as IList <T> ?? expected.ToList();

            if (!expectedList.Any())
            {
                throw new ArgumentException("Cannot verify containment against an empty collection");
            }
            var continuation = new AndConstraint <GenericCollectionAssertions <T> >(_assertions);

            if (ReferenceEquals(actual,
                                null))
            {
                Execute.Verification.BecauseOf(reason,
                                               reasonArgs)
                .FailWith("Expected {context:collection} to contain {0}{reason}, but found <null>.",
                          new object[]
                {
                    expected
                });
                // not needed but keep resharper happy
                return(continuation);
            }

            var expectedJson = expectedList
                               .Select(expObj => JsonConvert.SerializeObject(expObj));
            var actualJson = actual
                             .Select(actObj => JsonConvert.SerializeObject(actObj));

            actualJson
            .Should()
            .Contain(expectedJson);

            return(continuation);
        }
        public void GetFavoriteProductName_ForFirstCostumer_ReturnProductId()
        {
            var mockDb = new Mock <IDatabase>();

            mockDb.Setup(x => x.Customers).Returns(new List <Customer>());
            mockDb.Setup(y => y.Orders).Returns(new List <Order>());
            mockDb.Setup(y => y.Products).Returns(new List <Product>());
            Repository repository = new Repository(mockDb.Object);


            //act
            var productId = repository.GetOrders(3);

            AndConstraint <FluentAssertions.Collections.GenericCollectionAssertions <Order> > andConstraint = productId.Should().OnlyHaveUniqueItems();
        }
示例#18
0
 public static AndConstraint <ODataComplexValue> WithTypeName(this AndConstraint <ODataComplexValue> value, string expectedTypeName)
 {
     value.And.TypeName.Should().BeEquivalentTo(expectedTypeName);
     return(new AndConstraint <ODataComplexValue>(value.And));
 }
示例#19
0
 public AndConstraintResult(AndConstraint constraint, object actual, ConstraintResult leftResult, ConstraintResult rightResult)
     : base(constraint, actual, leftResult.IsSuccess && rightResult.IsSuccess)
 {
     this.leftResult  = leftResult;
     this.rightResult = rightResult;
 }
示例#20
0
 public void SetUp()
 {
     theConstraint = new AndConstraint(new GreaterThanConstraint(40), new LessThanConstraint(50));
     expectedDescription = "greater than 40 and less than 50";
     stringRepresentation = "<and <greaterthan 40> <lessthan 50>>";
 }
示例#21
0
 public void SetUp()
 {
     theConstraint        = new AndConstraint(new GreaterThanConstraint(40), new LessThanConstraint(50));
     expectedDescription  = "greater than 40 and less than 50";
     stringRepresentation = "<and <greaterthan 40> <lessthan 50>>";
 }
示例#22
0
 public static OkResult ThenOk <T>(this AndConstraint <T> _)
 => new OkResult();
示例#23
0
 public MoneyConstraint(decimal amount, Currency currency)
 {
     Delegate = new AndConstraint(
         Must.Have.Property(nameof(Money.Amount), Is.EqualTo(amount)),
         Must.Have.Property(nameof(Money.CurrencyCode), Is.EqualTo(currency.IsoCode)));
 }