Ejemplo n.º 1
0
        public void AndSeveralConstraings_WithGenerics()
        {
            AbstractConstraint all = Is.NotEqual("bar") && Is.TypeOf <string>() && Is.NotNull();

            Assert.True(all.Eval("foo"));
            Assert.Equal("not equal to bar and type of {System.String} and not equal to null", all.Message);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the method
        /// </summary>
        /// <param name="method"></param>
        /// <param name="arguments"></param>
        public override void HandleMethodCall(MethodInfo method, object[] arguments)
        {
            Method = method;

            if (ArgumentManager.HasBeenUsed)
            {
                ArgumentManager.ValidateMethodSignature(method);
                Arguments       = ArgumentManager.GetConstraints();
                ReturnArguments = ArgumentManager.GetReturnValues();
                SetExpectedCount(new Range(1, null));
                ArgumentManager.Clear();

                return;
            }

            var parameters  = method.GetParameters();
            var constraints = new AbstractConstraint[parameters.Length];

            for (int index = 0; index < parameters.Length; index++)
            {
                var parameter = parameters[index];
                constraints[index] = (parameter.IsOut)
                    ? Is.Anything()
                    : Is.Equal(arguments[index]);
            }

            Arguments = constraints;
        }
Ejemplo n.º 3
0
        public void Equal_BothListsAreICollectionWithDifferentSizes_DoesNotIterateOverCollections()
        {
            AbstractConstraint list = List.Equal(new FailsOnEqual[] { new FailsOnEqual(),
                                                                      new FailsOnEqual() });

            Assert.False(list.Eval(new FailsOnEqual[] { new FailsOnEqual() }));
        }
Ejemplo n.º 4
0
        public void Should_Be_Possible_To_Search_KeyValues_From_KeyName()
        {
            object fakeFoundKeyValues = new List <string>(new string[] { "Risk Manager", "PCN", "Workflow Manager", "Dashboard" });
            Dictionary <string, object> searchValuesParameters = new Dictionary <string, object>();

            searchValuesParameters.Add(registry_object_ItemsChoices.hive.ToString(), eHiveNames.HKEY_LOCAL_MACHINE.ToString());
            searchValuesParameters.Add(registry_object_ItemsChoices.key.ToString(), "SOFTWARE\\Modulo");
            searchValuesParameters.Add(registry_object_ItemsChoices.name.ToString(), "^.*");

            AbstractConstraint[] invokeMethodConstraints =
                new AbstractConstraint[] { new Equal("EnumValues"), new Anything(), new Anything() };

            MockRepository  mocks      = new MockRepository();
            WmiDataProvider fakeWmiPrv = mocks.DynamicMock <WmiDataProvider>();

            Expect.Call(fakeWmiPrv.InvokeMethod("", null, "")).Constraints(invokeMethodConstraints).Return(fakeFoundKeyValues);
            mocks.ReplayAll();

            RegistryObjectCollector systemDataSource = new RegistryObjectCollector()
            {
                WmiDataProvider = fakeWmiPrv
            };
            IList <string> registryKeyValues = systemDataSource.GetValues(searchValuesParameters);

            mocks.VerifyAll();

            Assert.IsNotNull(registryKeyValues);
            Assert.AreEqual(4, registryKeyValues.Count);
            Assert.IsTrue(registryKeyValues[0].Equals("Risk Manager"));
            Assert.IsTrue(registryKeyValues[1].Equals("PCN"));
            Assert.IsTrue(registryKeyValues[2].Equals("Workflow Manager"));
            Assert.IsTrue(registryKeyValues[3].Equals("Dashboard"));
        }
Ejemplo n.º 5
0
        public void Should_Be_Possible_To_Search_SubKeys_From_KeyName()
        {
            object fakeFoundSubKeys = new string[] { "Graphics", "GData", "XPTO" };
            Dictionary <string, object> searchKeysParameters = new Dictionary <string, object>();

            searchKeysParameters.Add(registry_object_ItemsChoices.hive.ToString(), eHiveNames.HKEY_LOCAL_MACHINE.ToString());
            searchKeysParameters.Add(registry_object_ItemsChoices.key.ToString(), "Microsoft");

            AbstractConstraint[] invokeMethodConstraints = new AbstractConstraint[]
            { new Equal("EnumKey"), new Anything(), new Anything() };


            MockRepository  mocks      = new MockRepository();
            WmiDataProvider fakeWmiPrv = mocks.DynamicMock <WmiDataProvider>();

            Expect.Call(fakeWmiPrv.InvokeMethod("", null, "")).Constraints(invokeMethodConstraints).Return(fakeFoundSubKeys);
            mocks.ReplayAll();

            RegistryObjectCollector systemDataSource = new RegistryObjectCollector()
            {
                WmiDataProvider = fakeWmiPrv
            };
            IList <string> registrySubKeys = systemDataSource.GetValues(searchKeysParameters);

            mocks.VerifyAll();

            Assert.IsNotNull(registrySubKeys);
            Assert.AreEqual(3, registrySubKeys.Count);
            Assert.AreEqual("Graphics", registrySubKeys[0]);
            Assert.AreEqual("GData", registrySubKeys[1]);
            Assert.AreEqual("XPTO", registrySubKeys[2]);
        }
Ejemplo n.º 6
0
        public void AndConstraints()
        {
            AbstractConstraint start = Text.StartsWith("Ayende"), end = Text.EndsWith("Rahien");
            AbstractConstraint combine = start & end;

            Assert.True(combine.Eval("Ayende Rahien"));
            Assert.Equal("starts with \"Ayende\" and ends with \"Rahien\"", combine.Message);
        }
Ejemplo n.º 7
0
        public void NotConstraint()
        {
            AbstractConstraint start  = Text.StartsWith("Ayende");
            AbstractConstraint negate = !start;

            Assert.True(negate.Eval("Rahien"));
            Assert.Equal("not starts with \"Ayende\"", negate.Message);
        }
Ejemplo n.º 8
0
        public void Like()
        {
            AbstractConstraint c = Text.Like("[Rr]ahien");

            Assert.True(c.Eval("Ayende Rahien"));
            Assert.False(c.Eval("Hello World"));
            Assert.Equal("like \"[Rr]ahien\"", c.Message);
        }
Ejemplo n.º 9
0
        public void PublicFieldValueDoesNotVerifyProperties()
        {
            string fooTestValue = "my foo";

            AbstractConstraint constraint = PublicField.Value("FooProperty", fooTestValue);

            Assert.False(constraint.Eval(new FooMessage(fooTestValue, string.Empty)), "Returned false when trying to validate a property rather than a field.");
        }
Ejemplo n.º 10
0
        public void OneOf()
        {
            AbstractConstraint list = List.OneOf(new string[] { "Ayende", "Rahien", "Hello", "World" });

            Assert.True(list.Eval("Ayende"));
            Assert.False(list.Eval("sheep"));
            Assert.Equal("one of [Ayende, Rahien, Hello, World]", list.Message);
        }
Ejemplo n.º 11
0
        public void PropertyValue()
        {
            AbstractConstraint constraint = Property.Value("Length", 6);

            Assert.True(constraint.Eval("Ayende"));
            Assert.False(constraint.Eval(new ArrayList()));
            Assert.Equal("property 'Length' equal to 6", constraint.Message);
        }
Ejemplo n.º 12
0
        public void Contains()
        {
            AbstractConstraint c = Text.Contains("Ayende");

            Assert.True(c.Eval("Ayende Rahien"));
            Assert.False(c.Eval("Hello World"));
            Assert.Equal("contains \"Ayende\"", c.Message);
        }
Ejemplo n.º 13
0
        public void InIs()
        {
            AbstractConstraint list = List.IsIn('a');

            Assert.True(list.Eval("ayende"));
            Assert.False(list.Eval("sheep"));
            Assert.Equal("list contains [a]", list.Message);
        }
Ejemplo n.º 14
0
        public void Count()
        {
            AbstractConstraint list = List.Count(Is.Equal(4));

            Assert.True(list.Eval(new string[] { "Ayende", "Rahien", "Hello", "World" }));
            Assert.False(list.Eval(new string[] { "Ayende", "Rahien", "World" }));
            Assert.False(list.Eval(5));
            Assert.Equal("collection count equal to 4", list.Message);
        }
Ejemplo n.º 15
0
        public void PublicFieldValue()
        {
            string barTestValue = "my bar";

            AbstractConstraint constraint = PublicField.Value("BarField", barTestValue);

            Assert.True(constraint.Eval(new FooMessage(string.Empty, barTestValue)), "Returned false when field was correct");
            Assert.False(constraint.Eval(new FooMessage(string.Empty, "your bar")), "Returned true when field was incorrect");
        }
Ejemplo n.º 16
0
        public void PublicFieldNotNull()
        {
            string barTestValue = "my bar";

            AbstractConstraint constraint = PublicField.IsNotNull("BarField");

            Assert.True(constraint.Eval(new FooMessage(string.Empty, barTestValue)), "Returned false when field was not null.");
            Assert.False(constraint.Eval(new FooMessage(null, null)), "Returned true when field was null");
        }
Ejemplo n.º 17
0
        public void IsTypeOf()
        {
            AbstractConstraint typeOf = Is.TypeOf(typeof(int));

            Assert.True(typeOf.Eval(3));
            Assert.False(typeOf.Eval(""));
            Assert.False(typeOf.Eval(null));
            Assert.Equal("type of {System.Int32}", typeOf.Message);
        }
Ejemplo n.º 18
0
        public void PropertyNotNull()
        {
            Exception          withoutInner = new Exception(), withInner = new Exception("", withoutInner);
            AbstractConstraint constraint = Property.IsNotNull("InnerException");

            Assert.False(constraint.Eval(withoutInner));
            Assert.True(constraint.Eval(withInner));
            Assert.Equal("not property 'InnerException' equal to null", constraint.Message);
        }
        public void SimpleReferenceTypeSuccess()
        {
            string actual   = "hello world.";
            string expected = "hello world.";

            AbstractConstraint sut = Property.AllPropertiesMatch(expected);

            Assert.True(sut.Eval(actual));
        }
Ejemplo n.º 20
0
        public void Equal()
        {
            AbstractConstraint list = List.Equal(new string[] { "Ayende", "Rahien", "Hello", "World" });

            Assert.True(list.Eval(new string[] { "Ayende", "Rahien", "Hello", "World" }));
            Assert.False(list.Eval(new string[] { "Ayende", "Rahien", "World", "Hello" }));
            Assert.False(list.Eval(new string[] { "Ayende", "Rahien", "World" }));
            Assert.False(list.Eval(5));
            Assert.Equal("equal to collection [Ayende, Rahien, Hello, World]", list.Message);
        }
Ejemplo n.º 21
0
        public void AmbiguousPropertyAccess()
        {
            DerivedPropertyAccessFodder o = new DerivedPropertyAccessFodder();

            AbstractConstraint constraint = Property.Value("Property", "4");

            // This will fail with an AmbiguousMatchException because 'Property' is not
            // unique: there are two public Property properties.
            Assert.Throws <AmbiguousMatchException>(() => Assert.True(constraint.Eval(o)));
        }
Ejemplo n.º 22
0
        public void Element()
        {
            AbstractConstraint list = List.Element(2, Is.Equal("Hello"));

            Assert.True(list.Eval(new string[] { "Ayende", "Rahien", "Hello", "World" }));
            Assert.False(list.Eval(new string[] { "Ayende", "Rahien", "World", "Hello" }));
            Assert.False(list.Eval(new string[] { "Ayende", "Rahien" }));
            Assert.False(list.Eval(5));
            Assert.Equal("element at index 2 equal to Hello", list.Message);
        }
        public void SimpleReferenceTypeFail()
        {
            string actual   = "hello world.";
            string expected = "hello wonderfull world.";

            AbstractConstraint sut = Property.AllPropertiesMatch(expected);

            Assert.False(sut.Eval(actual));
            Assert.Equal("Expected value of String is 'hello wonderfull world.', actual value is 'hello world.'", sut.Message);
        }
Ejemplo n.º 24
0
        public void ContainsAll()
        {
            AbstractConstraint list = List.ContainsAll(new string[] { "Ayende", "Rahien", "Hello", "World" });

            Assert.True(list.Eval(new string[] { "Ayende", "Rahien", "Hello", "World" }));
            Assert.False(list.Eval(new string[] { "Baaaah" }));
            Assert.False(list.Eval(5));
            list = List.ContainsAll(new string[] { "Ayende", "Rahien", "Hello", "World" });
            Assert.False(list.Eval(new string[] { "Ayende", "Rahien" }));
            Assert.Equal("list missing [Hello, World]", list.Message);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Ignores all arguments removing any existing argument constraints
        /// </summary>
        /// <returns>Fluid Interface</returns>
        IPropertyOptions <T> IPropertyOptions <T> .IgnoreArguments()
        {
            var constraints = new AbstractConstraint[Arguments.Length];

            for (int index = 0; index < Arguments.Length; index++)
            {
                constraints[index] = Is.Anything();
            }

            Arguments = constraints;
            return(this);
        }
Ejemplo n.º 26
0
        public void Equal_ConstraintIsNotICollection_StillWorks()
        {
            AbstractConstraint list = List.Equal(NameList());

            Assert.True(list.Eval(new string[] { "doron", "hi", "there" }));
            Assert.True(list.Eval(NameList()));

            Assert.False(list.Eval(new string[] { "doron", "there", "hi" }));
            Assert.False(list.Eval(new string[] { "doron", "hi" }));
            Assert.False(list.Eval(6));

            Assert.Equal("equal to collection [doron, hi, there]", list.Message);
        }
Ejemplo n.º 27
0
        public void PublicFieldValueOnImplementedInterfaceType()
        {
            string     barTestValue = "my bar";
            BarMessage message      = new BarMessage(string.Empty, barTestValue);

            AbstractConstraint baseConstraint = PublicField.Value(typeof(FooMessage), "BarField", barTestValue);

            Assert.True(baseConstraint.Eval(message), "Returned false when field was correct and field was declared in supplied type..");

            AbstractConstraint constraint = PublicField.Value(typeof(BarMessage), "BarField", barTestValue);

            Assert.False(constraint.Eval(message), "Returned true when field was correct but type was not declared on the suppleid type.");
        }
        public void ExpectedDifferentTypeThanActual()
        {
            Order order = new Order();

            order.Product        = new Product("Ratched and Clank - Tools of Destruction", 61.05);
            order.Quantity       = 4;
            order.Product.Weight = 18;

            Product expectedProduct = new Product("Ratched and Clank - Tools of Destruction", 61.05);

            AbstractConstraint sut = Property.AllPropertiesMatch(expectedProduct);

            Assert.False(sut.Eval(order));
            Assert.Equal("Expected type 'Product' doesn't match with actual type 'Order'", sut.Message);
        }
        public void PublicFieldTest()
        {
            ShippingList actual = new ShippingList();

            actual._shippingDate = new DateTime(2007, 9, 27);

            ShippingList expected = new ShippingList();

            expected._shippingDate = new DateTime(1978, 9, 27);

            AbstractConstraint sut = Property.AllPropertiesMatch(expected);

            Assert.False(sut.Eval(actual));
            Assert.Equal("Expected value of ShippingList._shippingDate is '09/27/1978 00:00:00', actual value is '09/27/2007 00:00:00'", sut.Message);
        }
Ejemplo n.º 30
0
        private IExpectation BuildDefaultExpectation(IInvocation invocation, MethodInfo method, object[] args)
        {
            ParameterInfo[] parameters = method.GetParameters();
            if (!Array.Exists(parameters, delegate(ParameterInfo p) { return(p.IsOut); }))
            {
                return(new ArgsEqualExpectation(invocation, args, GetDefaultCallCountRangeExpectation()));
            }

            //The value of an incoming out parameter variable is ignored
            AbstractConstraint[] constraints = new AbstractConstraint[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                constraints[i] = parameters[i].IsOut ? Is.Anything() : Is.Equal(args[i]);
            }
            return(new ConstraintsExpectation(invocation, constraints, GetDefaultCallCountRangeExpectation()));
        }
Ejemplo n.º 31
0
        private SolverNode CloseVariable(IVariable variable,
                                         IAbstractExpr expression,
                                         AbstractConstraint sourceConstraintToBeRemoved)
        {
            //var foldingVisitor = new ConstantFoldingVisitor();
            var foldingVisitor = new PolynomialFoldingVisitor();
            expression = expression.Accept(foldingVisitor);

            // Rewrite all constraints
            //var rewriter = new RewritingVisitor(
            //    new Dictionary<IAbstractExpr, IAbstractExpr> { { variable, expression } });
            var rewriter = new RewritingVisitor(variable, expression);
            IEnumerable<AbstractConstraint> rewrittenConstraints =
                Constraints.Except(sourceConstraintToBeRemoved)
                    .Select(c => c.Accept(rewriter, Ig.nore));

            // Create new variable->value knowledge or new backsubstition.
            var newBacksubstitutions = new Dictionary<IVariable, AbstractClosedVariable>(ClosedVariables) {{
                variable, expression is IConstant
                    ? (AbstractClosedVariable)
                        new VariableWithValue(variable, ((IConstant) expression).Value)
                    : new VariableWithBacksubstitution(variable, expression)
                }};

            // Create new node.
            return new SolverNode(rewrittenConstraints, newBacksubstitutions, this);
        }
Ejemplo n.º 32
0
 private static bool DebugIsTrueOrUnknown(AbstractConstraint c, EvaluationVisitor debugExpectedResults)
 {
     try {
         return c.Accept(debugExpectedResults, Ig.nore);
     } catch (NotSupportedException) {
         return true;
     }
 }
Ejemplo n.º 33
0
 /// <summary>
 /// SQL-92, page 270
 /// </summary>
 private string _TableConstraint(AbstractConstraint constraint)
 {
     return constraint.Accept<string>(_ReferentialConstraintDefinition, _UniqueConstraintDefinition, _CheckConstraintDefinition);
 }
Ejemplo n.º 34
0
 /// <summary>
 /// SQL-92, page 270
 /// </summary>
 private string _TableConstraintDefinition(AbstractConstraint constraint)
 {
     return string.Format(
         "{0} {1}",
         _ConstraintNameDefinition(constraint),
         _TableConstraint(constraint)
     );
 }
Ejemplo n.º 35
0
 public string CreateConstraint(AbstractConstraint constraint)
 {
     return _AlterTableStatement(constraint.table, _AddTableConstraintDefinition(constraint));
 }
Ejemplo n.º 36
0
 public string DropConstraint(AbstractConstraint constraint)
 {
     return _AlterTableStatement(constraint.table, _DropTableConstraintDefinition(constraint));
 }
Ejemplo n.º 37
0
 protected AbstractConstraintCommand(int num, XElement inner)
     : base(num)
 {
     this.constraint = XMLParser.ParseConstraint(inner);
 }
Ejemplo n.º 38
0
 /// <summary>
 /// SQL-92, page 292
 /// </summary>
 private string _DropTableConstraintDefinition(AbstractConstraint constraint)
 {
     return string.Format(
         "DROP CONSTRAINT {0}",
         nameEscaper(constraint.name)
     );
 }
Ejemplo n.º 39
0
 /// <summary>
 /// SQL-92, page 252
 /// </summary>
 private string _ConstraintNameDefinition(AbstractConstraint constraint)
 {
     return string.Format(
         "CONSTRAINT {0}",
         nameEscaper(constraint.name)
     );
 }
Ejemplo n.º 40
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="arg1"></param>
 public OperatorNot(AbstractConstraint arg1)
 {
     this.arg1 = arg1;
 }
Ejemplo n.º 41
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="arg1"></param>
 /// <param name="arg2"></param>
 public OperatorAnd(AbstractConstraint arg1, AbstractConstraint arg2)
 {
     this.arg1 = arg1;
     this.arg2 = arg2;
 }
Ejemplo n.º 42
0
 /// <summary>
 /// SQL-92, page 291
 /// </summary>
 private string _AddTableConstraintDefinition(AbstractConstraint constraint)
 {
     return string.Format(
         "ADD {0}",
         _TableConstraintDefinition(constraint)
     );
 }
Ejemplo n.º 43
0
 public void CreateConstraint(AbstractConstraint constraint)
 {
     this.traits.CreateConstraint(this.CreateTextCommand, constraint);
 }