Beispiel #1
0
        public void UsingConstructorAlsoSetsComparisonValue()
        {
            /** When using the constructor and passing a value for `Name`, `Property` or `Expression`,
             * `ComparisonValue` is also set on the `Field` instance; this is used when
             *
             * - determining `Field` equality
             * - getting the hash code for a `Field` instance
             *
             * IMPORTANT: Boost values are **not** taken into account when determining equality.
             */
            var fieldStringWithBoostTwo   = new Field("name^2");
            var fieldStringWithBoostThree = new Field("name^3");

            Expression <Func <Project, object> > expression = p => p.Name;
            var fieldExpression = new Field(expression);

            var fieldProperty = new Field(typeof(Project).GetProperty(nameof(Project.Name)));

            fieldStringWithBoostTwo.GetHashCode().Should().NotBe(0);
            fieldStringWithBoostThree.GetHashCode().Should().NotBe(0);
            fieldExpression.GetHashCode().Should().NotBe(0);
            fieldProperty.GetHashCode().Should().NotBe(0);

            fieldStringWithBoostTwo.Should().Be(fieldStringWithBoostThree);             //<1> <<field-name-with-boost,Fields can constructed with a name that contains a boost>>
        }
		public void UsingConstructorAlsoSetsComparisonValue()
		{
			/** When using the constructor and passing a value for `Name`, `Property` or `Expression`,
			* `ComparisonValue` is also set on the `Field` instance; this is used when
			*
			* - determining `Field` equality
			* - getting the hash code for a `Field` instance
			*
			* IMPORTANT: Boost values are not taken into account when determining equality.
			*/
			var fieldStringWithBoostTwo = new Field("name^2");
			var fieldStringWithBoostThree = new Field("name^3");

			Expression<Func<Project, object>> expression = p => p.Name;
			var fieldExpression = new Field(expression);

			var fieldProperty = new Field(typeof(Project).GetProperty(nameof(Project.Name)));

			fieldStringWithBoostTwo.GetHashCode().Should().NotBe(0);
			fieldStringWithBoostThree.GetHashCode().Should().NotBe(0);
			fieldExpression.GetHashCode().Should().NotBe(0);
			fieldProperty.GetHashCode().Should().NotBe(0);

			fieldStringWithBoostTwo.Should().Be(fieldStringWithBoostThree); //<1> <<field-name-with-boost,Fields can constructed with a name that contains a boost>>
		}