public void Get_HashCode()
        {
            var specification1 = new SortedPropertySpecification(_productPropertyDefinition, SortOrder.Ascending);
            var specification2 = new SortedPropertySpecification(_productPropertyDefinition, SortOrder.Ascending);

            Assert.That(specification1.GetHashCode(), Is.EqualTo(specification2.GetHashCode()));
        }
        public void To_String()
        {
            var specificationAsc  = new SortedPropertySpecification(_productPropertyDefinition, SortOrder.Ascending);
            var specificationDesc = new SortedPropertySpecification(_productPropertyDefinition, SortOrder.Descending);

            Assert.That(specificationAsc.ToString(), Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.TestDomain.OrderItem.Product ASC"));
            Assert.That(specificationDesc.ToString(), Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.TestDomain.OrderItem.Product DESC"));
        }
예제 #3
0
        public SortedPropertyComparer(SortedPropertySpecification sortedPropertySpecification, IDataManager dataManager)
        {
            ArgumentUtility.CheckNotNull("sortedPropertySpecification", sortedPropertySpecification);
            ArgumentUtility.CheckNotNull("dataManager", dataManager);

            _dataManager = dataManager;
            _sortedPropertySpecification = sortedPropertySpecification;
        }
        public void Equals()
        {
            var specification1 = new SortedPropertySpecification(_productPropertyDefinition, SortOrder.Ascending);
            var specification2 = new SortedPropertySpecification(_productPropertyDefinition, SortOrder.Ascending);
            var specification3 = new SortedPropertySpecification(_productPropertyDefinition, SortOrder.Descending);
            var specification4 = new SortedPropertySpecification(_positionPropertyDefinition, SortOrder.Ascending);

            Assert.That(specification1, Is.Not.EqualTo(null));
            Assert.That(specification1, Is.EqualTo(specification2));
            Assert.That(specification1, Is.Not.EqualTo(specification3));
            Assert.That(specification1, Is.Not.EqualTo(specification4));
        }
예제 #5
0
        public void CreateCompoundComparer()
        {
            var specification1 = new SortedPropertySpecification(_orderNumberPropertyDefinition, SortOrder.Ascending);
            var specification2 = new SortedPropertySpecification(_orderNumberPropertyDefinition, SortOrder.Descending);

            var compoundComparer = (CompoundComparer <DomainObject>)SortedPropertyComparer.CreateCompoundComparer(new[] { specification1, specification2 }, _dataManagerStub);

            Assert.That(compoundComparer.Comparers.Count, Is.EqualTo(2));

            Assert.That(((SortedPropertyComparer)compoundComparer.Comparers[0]).SortedPropertySpecification, Is.SameAs(specification1));
            Assert.That(((SortedPropertyComparer)compoundComparer.Comparers[0]).DataManager, Is.SameAs(_dataManagerStub));

            Assert.That(((SortedPropertyComparer)compoundComparer.Comparers[1]).SortedPropertySpecification, Is.SameAs(specification2));
            Assert.That(((SortedPropertyComparer)compoundComparer.Comparers[1]).DataManager, Is.SameAs(_dataManagerStub));
        }
예제 #6
0
        public void Compare_Descending()
        {
            var domainObject1 = DomainObjectMother.CreateFakeObject <Order> ();
            var domainObject2 = DomainObjectMother.CreateFakeObject <Order> ();

            PrepareDataContainer(_dataManagerStub, domainObject1, 1);
            PrepareDataContainer(_dataManagerStub, domainObject2, 2);

            var specification = new SortedPropertySpecification(_orderNumberPropertyDefinition, SortOrder.Descending);
            var comparer      = new SortedPropertyComparer(specification, _dataManagerStub);

            Assert.That(comparer.Compare(domainObject1, domainObject1), Is.EqualTo(0));
            Assert.That(comparer.Compare(domainObject1, domainObject2), Is.EqualTo(1));
            Assert.That(comparer.Compare(domainObject2, domainObject1), Is.EqualTo(-1));
            Assert.That(comparer.Compare(domainObject2, domainObject2), Is.EqualTo(0));
        }
        private Ordering GetOrdering(QueryModel queryModel, SortedPropertySpecification sortedPropertySpecification)
        {
            var instanceExpression = queryModel.SelectClause.Selector;

            var normalizedProperty = GetNormalizedProperty(
                sortedPropertySpecification.PropertyDefinition.PropertyInfo,
                TypeAdapter.Create(instanceExpression.Type));

            var memberExpression = Expression.MakeMemberAccess(
                Expression.Convert(instanceExpression, normalizedProperty.DeclaringType.ConvertToRuntimeType()),
                normalizedProperty.ConvertToRuntimePropertyInfo());

            var orderingDirection = sortedPropertySpecification.Order == SortOrder.Ascending ? OrderingDirection.Asc : OrderingDirection.Desc;

            return(new Ordering(memberExpression, orderingDirection));
        }
예제 #8
0
        public void Compare_DoesNotTriggerEvents()
        {
            var domainObject1 = DomainObjectMother.CreateFakeObject <Order> ();
            var domainObject2 = DomainObjectMother.CreateFakeObject <Order> ();

            var dataContainer1 = PrepareDataContainer(_dataManagerStub, domainObject1, 1);
            var dataContainer2 = PrepareDataContainer(_dataManagerStub, domainObject2, 2);

            var transaction = ClientTransaction.CreateRootTransaction();

            ClientTransactionTestHelper.RegisterDataContainer(transaction, dataContainer1);
            ClientTransactionTestHelper.RegisterDataContainer(transaction, dataContainer2);

            ClientTransactionTestHelperWithMocks.EnsureTransactionThrowsOnEvents(transaction);

            var specification = new SortedPropertySpecification(_orderNumberPropertyDefinition, SortOrder.Descending);
            var comparer      = new SortedPropertyComparer(specification, _dataManagerStub);

            Assert.That(comparer.Compare(domainObject1, domainObject1), Is.EqualTo(0));
        }