/// <summary>
 ///     Attaches the <see cref="IFacet" /> to its <see cref="IFacet.FacetHolder" />
 /// </summary>
 /// <returns>
 ///     <c>true</c> if a non-<c>null</c> facet was added, <c>false</c> otherwise.
 /// </returns>
 public static bool AddFacet(IFacet facet) {
     if (facet != null) {
         facet.FacetHolder.AddFacet(facet);
         return true;
     }
     return false;
 }
 /// <summary>
 ///     Attaches each <see cref="IFacet" /> to its <see cref="IFacet.FacetHolder" />
 /// </summary>
 /// <returns>
 ///     <c>true</c> if any facets were added, <c>false</c> otherwise.
 /// </returns>
 public static bool AddFacets(IFacet[] facets) {
     bool addedFacets = false;
     foreach (IFacet facet in facets) {
         addedFacets |= AddFacet(facet);
     }
     return addedFacets;
 }
        public virtual IFacet Decorate(IFacet facet, ISpecification holder) {
            IIdentifier identifier = holder.Identifier;
            Type facetType = facet.FacetType;

            if (facetType == typeof (INamedFacet)) {
                return GetNamedFacet(holder, facet as INamedFacet, identifier);
            }
            if (facetType == typeof (IDescribedAsFacet)) {
                return GetDescriptionFacet(holder, facet as IDescribedAsFacet, identifier);
            }

            return facet;
        }
        // validate all the passed in types to fail at reflection time as far as possible

        public virtual IFacet Decorate(IFacet facet, ISpecification holder) {
            Type facetType = facet.FacetType;
            ISpecification specification = facet.Specification;
            IIdentifier identifier = holder.Identifier;

            if (facetType == typeof (IHideForSessionFacet)) {
                return new AuthorizationHideForSessionFacet(identifier, this, specification);
            }

            if (facetType == typeof (IDisableForSessionFacet)) {
                return new AuthorizationDisableForSessionFacet(identifier, this, specification);
            }
            return facet;
        }
        public virtual IFacet Decorate(IFacet facet, IFacetHolder holder) {
            Type facetType = facet.FacetType;
            IFacetHolder facetHolder = facet.FacetHolder;
            IIdentifier identifier = holder.Identifier;

            if (facetType == typeof (IHideForSessionFacet)) {
                return new SecurityHideForSessionFacet(identifier, this, facetHolder);
            }

            if (facetType == typeof (IDisableForSessionFacet)) {
                return new SecurityDisableForSessionFacet(identifier, this, facetHolder);
            }
            return facet;
        }
        public virtual IFacet Decorate(IFacet facet, IFacetHolder holder) {
            if (facet.FacetType == typeof (IActionInvocationFacet)) {
                return new ActionInvocationFacetWrapTransaction(((IActionInvocationFacet) facet));
            }

            if (facet.FacetType == typeof (IPropertyClearFacet)) {
                return new PropertyClearFacetWrapTransaction(((IPropertyClearFacet) facet));
            }

            if (facet.FacetType == typeof (IPropertySetterFacet)) {
                return new ProxySetterFacetWrapTransaction(((IPropertySetterFacet) facet));
            }

            return facet;
        }
        public virtual IFacet Decorate(IFacet facet, IFacetHolder holder) {
            if (facet.FacetType == typeof (IActionInvocationFacet)) {
                return new AuditActionInvocationFacet((IActionInvocationFacet) facet, manager);
            }

            if (facet.FacetType == typeof (IUpdatedCallbackFacet)) {
                return new AuditUpdatedFacet((IUpdatedCallbackFacet) facet, manager);
            }

            if (facet.FacetType == typeof (IPersistedCallbackFacet)) {
                return new AuditPersistedFacet((IPersistedCallbackFacet) facet, manager);
            }

            return facet;
        }
        public IFacet Decorate(IFacet facet, ISpecification holder) {
            if (facet.FacetType == typeof (IActionInvocationFacet)) {
                return new AuditActionInvocationFacet((IActionInvocationFacet) facet, this);
            }

            if (facet.FacetType == typeof (IUpdatedCallbackFacet)) {
                return new AuditUpdatedFacet((IUpdatedCallbackFacet) facet, this);
            }

            if (facet.FacetType == typeof (IPersistedCallbackFacet)) {
                return new AuditPersistedFacet((IPersistedCallbackFacet) facet, this);
            }

            return facet;
        }
Exemple #9
0
        public void TestDisplayNameAnnotationPickedUpOnAction()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            MethodInfo actionMethod = FindMethod(typeof(Customer8), "SomeAction");

            metamodel = facetFactory.Process(Reflector, actionMethod, MethodRemover, Specification, metamodel);
            IFacet facet = Specification.GetFacet(typeof(INamedFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is NamedFacetAbstract);
            var namedFacetAbstract = (NamedFacetAbstract)facet;

            Assert.AreEqual("some name", namedFacetAbstract.Value);
            AssertNoMethodsRemoved();
            Assert.IsNotNull(metamodel);
        }
Exemple #10
0
        public static IEnumerable <double> GetNormal(IFacet facet)
        {
            var arris = facet.ArristCollection.ToList();

            var first  = arris[0].FirstVertex;
            var second = arris[1].FirstVertex;
            var third  = arris[2].FirstVertex;

            var x = first.Y * second.Z + second.Y * third.Z + third.Y * first.Z -
                    second.Y * first.Z - third.Y * second.Z - first.Y * third.Z;
            var y = first.Z * second.X + second.Z * third.X + third.Z * first.X -
                    second.Z * first.X - third.Z * second.X - first.Z * third.X;
            var z = first.X * second.Y + second.X * third.Y + third.X * first.Y -
                    second.X * first.Y - third.X * second.Y - first.X * third.Y;

            return(facet.ReverseNormal ? new[] { -x, -y, -z } : new[] { x, y, z });
        }
        public void TestMultiLineAnnotationPickedUpOnProperty()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            PropertyInfo property = FindProperty(typeof(Customer1), "FirstName");

            metamodel = facetFactory.Process(Reflector, property, MethodRemover, Specification, metamodel);
            IFacet facet = Specification.GetFacet(typeof(IMultiLineFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is MultiLineFacetAnnotation);
            var multiLineFacetAnnotation = (MultiLineFacetAnnotation)facet;

            Assert.AreEqual(12, multiLineFacetAnnotation.NumberOfLines);
            Assert.AreEqual(36, multiLineFacetAnnotation.Width);
            Assert.IsNotNull(metamodel);
        }
        public void TestMultiLineAnnotationPickedUpOnActionParameter()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            MethodInfo method = FindMethod(typeof(Customer2), "SomeAction", new[] { typeof(string) });

            metamodel = facetFactory.ProcessParams(Reflector, method, 0, Specification, metamodel);
            IFacet facet = Specification.GetFacet(typeof(IMultiLineFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is MultiLineFacetAnnotation);
            var multiLineFacetAnnotation = (MultiLineFacetAnnotation)facet;

            Assert.AreEqual(8, multiLineFacetAnnotation.NumberOfLines);
            Assert.AreEqual(24, multiLineFacetAnnotation.Width);
            Assert.IsNotNull(metamodel);
        }
Exemple #13
0
        public void TestTypeOfFacetInferredForActionWithArrayReturnType()
        {
            MethodInfo actionMethod = FindMethod(typeof(Customer9), "SomeAction");

            facetFactory.Process(Reflector, actionMethod, MethodRemover, Specification);
            IFacet typeOfFacet = Specification.GetFacet(typeof(ITypeOfFacet));

            Assert.IsNotNull(typeOfFacet);
            Assert.IsTrue(typeOfFacet is TypeOfFacetInferredFromArray);

            var elementTypeFacet = Specification.GetFacet <IElementTypeFacet>();

            Assert.IsNotNull(elementTypeFacet);
            Assert.IsTrue(elementTypeFacet is ElementTypeFacet);
            Assert.AreEqual(typeof(Order), elementTypeFacet.Value);
            AssertNoMethodsRemoved();
        }
Exemple #14
0
        public void TestRangeAnnotationPickedUpOnProperty()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            PropertyInfo property = FindProperty(typeof(Customer1), "Prop");

            metamodel = facetFactory.Process(Reflector, property, MethodRemover, Specification, metamodel);
            IFacet facet = Specification.GetFacet(typeof(IRangeFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is RangeFacet);
            var rangeFacetAnnotation = (RangeFacet)facet;

            Assert.AreEqual(1, rangeFacetAnnotation.Min);
            Assert.AreEqual(10, rangeFacetAnnotation.Max);
            Assert.IsNotNull(metamodel);
        }
Exemple #15
0
        public void TestRangeAnnotationPickedUpOnActionParameter()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            MethodInfo method = FindMethod(typeof(Customer2), "SomeAction", new[] { typeof(int) });

            metamodel = facetFactory.ProcessParams(Reflector, method, 0, Specification, metamodel);
            IFacet facet = Specification.GetFacet(typeof(IRangeFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is RangeFacet);
            var rangeFacetAnnotation = (RangeFacet)facet;

            Assert.AreEqual(1, rangeFacetAnnotation.Min);
            Assert.AreEqual(10, rangeFacetAnnotation.Max);
            Assert.IsNotNull(metamodel);
        }
Exemple #16
0
        public void TestNamedAnnotationPickedUpOnProperty()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            PropertyInfo property = FindProperty(typeof(Customer1), "NumberOfOrders");

            metamodel = facetFactory.Process(Reflector, property, MethodRemover, Specification, metamodel);
            IFacet facet = Specification.GetFacet(typeof(INamedFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is NamedFacetAbstract);
            var namedFacetAbstract = (NamedFacetAbstract)facet;

            Assert.AreEqual("some name", namedFacetAbstract.Value);
            AssertNoMethodsRemoved();
            Assert.IsNotNull(metamodel);
        }
        public virtual IFacet Decorate(IFacet facet, ISpecification holder)
        {
            Type           facetType     = facet.FacetType;
            ISpecification specification = facet.Specification;
            IIdentifier    identifier    = holder.Identifier;

            if (facetType == typeof(IHideForSessionFacet))
            {
                return(new AuthorizationHideForSessionFacet(identifier, this, specification));
            }

            if (facetType == typeof(IDisableForSessionFacet))
            {
                return(new AuthorizationDisableForSessionFacet(identifier, this, specification));
            }
            return(facet);
        }
        private static void CheckChoices(IFacet facet) {
            var facetAsEnumFacet = facet as IEnumFacet;
            Assert.IsNotNull(facetAsEnumFacet);
            Assert.AreEqual(3, facetAsEnumFacet.GetChoices(null).Length);
            Assert.AreEqual(Cities.London, facetAsEnumFacet.GetChoices(null)[0]);
            Assert.AreEqual(Cities.NewYork, facetAsEnumFacet.GetChoices(null)[1]);
            Assert.AreEqual(Cities.Paris, facetAsEnumFacet.GetChoices(null)[2]);

            Assert.AreEqual(1, facetAsEnumFacet.GetChoices(null, new object[] {Cities.NewYork}).Length);
            Assert.AreEqual(Cities.NewYork, facetAsEnumFacet.GetChoices(null, new object[] {Cities.NewYork})[0]);

            var mock = new Mock<INakedObjectAdapter>();
            INakedObjectAdapter nakedObjectAdapter = mock.Object;
            mock.Setup(no => no.Object).Returns(Cities.NewYork);

            Assert.AreEqual("New York", facetAsEnumFacet.GetTitle(nakedObjectAdapter));
        }
Exemple #19
0
        private static FacetType GetFacetType(IFacet facet)
        {
            switch (facet.FacetType)
            {
            case FacetTypeConstants.SingleSelect:
                return(FacetType.SingleSelect);

            case FacetTypeConstants.MultiSelect:
                return(FacetType.MultiSelect);

            case FacetTypeConstants.Range:
                return(FacetType.Range);

            default:
                throw new ArgumentOutOfRangeException(nameof(IFacet.FacetType));
            }
        }
Exemple #20
0
        public void TestTableViewFacetPickedUpOnCollectionAction()
        {
            MethodInfo method = FindMethod(typeof(Customer1), "OrdersAction1");

            facetFactory.Process(Reflector, method, MethodRemover, Specification);
            IFacet facet = Specification.GetFacet(typeof(ITableViewFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is TableViewFacet);
            var tableViewFacetFromAnnotation = (TableViewFacet)facet;

            Assert.AreEqual(true, tableViewFacetFromAnnotation.Title);
            Assert.AreEqual(2, tableViewFacetFromAnnotation.Columns.Length);
            Assert.AreEqual("col7", tableViewFacetFromAnnotation.Columns[0]);
            Assert.AreEqual("col8", tableViewFacetFromAnnotation.Columns[1]);
            AssertNoMethodsRemoved();
        }
        public void TestAutoCompleteFacetFoundAndMethodRemovedForInterface()
        {
            PropertyInfo property = FindProperty(typeof(Customer27), "FirstName");
            MethodInfo   propertyAutoCompleteMethod = FindMethodIgnoreParms(typeof(Customer27), "AutoCompleteFirstName");

            facetFactory.Process(Reflector, property, MethodRemover, Specification);
            IFacet facet = Specification.GetFacet(typeof(IAutoCompleteFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is AutoCompleteFacet);
            var propertyAutoCompleteFacet = (AutoCompleteFacet)facet;

            Assert.AreEqual(propertyAutoCompleteMethod, propertyAutoCompleteFacet.GetMethod());
            AssertMethodRemoved(propertyAutoCompleteMethod);
            Assert.AreEqual(50, propertyAutoCompleteFacet.PageSize);
            Assert.AreEqual(0, propertyAutoCompleteFacet.MinLength);
        }
Exemple #22
0
        public void TestTableViewFacetPickedUpOnArray()
        {
            PropertyInfo property = FindProperty(typeof(Customer1), "Orders");

            facetFactory.Process(Reflector, property, MethodRemover, Specification);
            IFacet facet = Specification.GetFacet(typeof(ITableViewFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is TableViewFacet);
            var tableViewFacetFromAnnotation = (TableViewFacet)facet;

            Assert.AreEqual(true, tableViewFacetFromAnnotation.Title);
            Assert.AreEqual(2, tableViewFacetFromAnnotation.Columns.Length);
            Assert.AreEqual("col1", tableViewFacetFromAnnotation.Columns[0]);
            Assert.AreEqual("col2", tableViewFacetFromAnnotation.Columns[1]);
            AssertNoMethodsRemoved();
        }
        public void TestTableViewFacetPickedUpOnCollectionActionNoColumns()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            MethodInfo method = FindMethod(typeof(Customer1), "OrdersAction2");

            metamodel = facetFactory.Process(Reflector, method, MethodRemover, Specification, metamodel);
            IFacet facet = Specification.GetFacet(typeof(ITableViewFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is TableViewFacet);
            var tableViewFacetFromAnnotation = (TableViewFacet)facet;

            Assert.AreEqual(true, tableViewFacetFromAnnotation.Title);
            Assert.AreEqual(0, tableViewFacetFromAnnotation.Columns.Length);
            AssertNoMethodsRemoved();
            Assert.IsNotNull(metamodel);
        }
        public void TestDefaultFacetFoundAndMethodRemoved()
        {
            PropertyInfo property = FindProperty(typeof(Customer11), "FirstName");
            MethodInfo   propertyDefaultMethod = FindMethod(typeof(Customer11), "DefaultFirstName");

            facetFactory.Process(Reflector, property, MethodRemover, Specification);
            IFacet facet = Specification.GetFacet(typeof(IPropertyDefaultFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is PropertyDefaultFacetViaMethod);
            var propertyDefaultFacet = (PropertyDefaultFacetViaMethod)facet;

            Assert.AreEqual(propertyDefaultMethod, propertyDefaultFacet.GetMethod());
            AssertMethodRemoved(propertyDefaultMethod);
            IFacet facetExecuted = Specification.GetFacet(typeof(IExecutedControlMethodFacet));

            Assert.IsNull(facetExecuted);
        }
        public void TestViewModelPickedUp()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            var class1Type = typeof(Class1);

            metamodel = facetFactory.Process(Reflector, class1Type, MethodRemover, Specification, metamodel);
            IFacet facet = Specification.GetFacet(typeof(IViewModelFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is ViewModelFacetConvention);

            MethodInfo m1 = class1Type.GetMethod("DeriveKeys");
            MethodInfo m2 = class1Type.GetMethod("PopulateUsingKeys");

            AssertMethodsRemoved(new[] { m1, m2 });
            Assert.IsNotNull(metamodel);
        }
Exemple #26
0
        public void TestRegularExpressionAnnotationPickedUpOnActionParameter()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            MethodInfo method = FindMethod(typeof(Customer8), "SomeAction", new[] { typeof(string) });

            metamodel = facetFactory.ProcessParams(Reflector, method, 0, Specification, metamodel);
            IFacet facet = Specification.GetFacet(typeof(IRegExFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is RegExFacet);
            var regExFacet = (RegExFacet)facet;

            Assert.AreEqual("^A.*", regExFacet.ValidationPattern);
            Assert.AreEqual("Parameter message", regExFacet.FailureMessage);
            Assert.AreEqual(true, regExFacet.IsCaseSensitive);
            Assert.IsNotNull(metamodel);
        }
Exemple #27
0
        public void TestIfHaveSetterAndModifyFacetThenTheModifyFacetWinsOut()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            PropertyInfo property             = FindProperty(typeof(Customer7), "FirstName");
            MethodInfo   propertyModifyMethod = FindMethod(typeof(Customer7), "ModifyFirstName", new[] { typeof(string) });

            metamodel = facetFactory.Process(Reflector, property, MethodRemover, Specification, metamodel);
            IFacet facet = Specification.GetFacet(typeof(IPropertySetterFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is PropertySetterFacetViaModifyMethod);
            var propertySetterFacet = (PropertySetterFacetViaModifyMethod)facet;

            Assert.AreEqual(propertyModifyMethod, propertySetterFacet.GetMethod());
            AssertMethodRemoved(propertyModifyMethod);
            Assert.IsNotNull(metamodel);
        }
Exemple #28
0
        public void TestValidateFacetFoundAndMethodRemoved()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            PropertyInfo property = FindProperty(typeof(Customer12), "FirstName");
            MethodInfo   propertyValidateMethod = FindMethod(typeof(Customer12), "ValidateFirstName", new[] { typeof(string) });

            metamodel = facetFactory.Process(Reflector, property, MethodRemover, Specification, metamodel);
            IFacet facet = Specification.GetFacet(typeof(IPropertyValidateFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is PropertyValidateFacetViaMethod);
            var propertyValidateFacet = (PropertyValidateFacetViaMethod)facet;

            Assert.AreEqual(propertyValidateMethod, propertyValidateFacet.GetMethod());
            AssertMethodRemoved(propertyValidateMethod);
            Assert.IsNotNull(metamodel);
        }
Exemple #29
0
        public void TestDisableMethodOverridsDefault()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            PropertyInfo property   = FindProperty(typeof(Customer16), "SecondName");
            MethodInfo   hideMethod = FindMethod(typeof(Customer16), "DisableSecondName", new Type[0]);

            metamodel = facetFactory.Process(Reflector, property, MethodRemover, Specification, metamodel);
            IFacet facet = Specification.GetFacet(typeof(IDisableForContextFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is DisableForContextFacet);
            var disableFacet = (DisableForContextFacet)facet;

            Assert.AreEqual(hideMethod, disableFacet.GetMethod());
            AssertMethodRemoved(hideMethod);
            Assert.IsNotNull(metamodel);
        }
Exemple #30
0
        public void TestChoicesFacetFoundAndMethodRemovedWithParms()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            PropertyInfo property = FindProperty(typeof(Customer17), "FirstName");
            MethodInfo   propertyChoicesMethod = FindMethod(typeof(Customer17), "ChoicesFirstName", new[] { typeof(string) });

            metamodel = facetFactory.Process(Reflector, property, MethodRemover, Specification, metamodel);
            IFacet facet = Specification.GetFacet(typeof(IPropertyChoicesFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is PropertyChoicesFacet);
            AssertMethodRemoved(propertyChoicesMethod);
            IFacet facetExecuted = Specification.GetFacet(typeof(IExecutedControlMethodFacet));

            Assert.IsNull(facetExecuted);
            Assert.IsNotNull(metamodel);
        }
Exemple #31
0
        public void TestRegularExpressionAnnotationPickedUpOnProperty()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            PropertyInfo property = FindProperty(typeof(Customer7), "FirstName");

            metamodel = facetFactory.Process(Reflector, property, MethodRemover, Specification, metamodel);
            IFacet facet = Specification.GetFacet(typeof(IRegExFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is RegExFacet);
            var regExFacet = (RegExFacet)facet;

            Assert.AreEqual("^A.*", regExFacet.ValidationPattern);
            Assert.AreEqual("Property message", regExFacet.FailureMessage);
            Assert.AreEqual(true, regExFacet.IsCaseSensitive);
            Assert.IsNotNull(metamodel);
        }
Exemple #32
0
        public void TestHideMethodWithParameterFacet()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            PropertyInfo property   = FindProperty(typeof(Customer13), "SecondName");
            MethodInfo   hideMethod = FindMethod(typeof(Customer13), "HideSecondName", new Type[] { });

            metamodel = facetFactory.Process(Reflector, property, MethodRemover, Specification, metamodel);
            IFacet facet = Specification.GetFacet(typeof(IHideForContextFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is HideForContextFacet);
            var propertyValidateFacet = (HideForContextFacet)facet;

            Assert.AreEqual(hideMethod, propertyValidateFacet.GetMethod());
            AssertMethodRemoved(hideMethod);
            Assert.IsNotNull(metamodel);
        }
        protected string GetAddFacetLink(IFacet facet, IList <FacetParameter> selectedFacets)
        {
            StringBuilder sb         = new StringBuilder();
            bool          firstParam = true;
            bool          foundFacet = false;

            if (selectedFacets != null)
            {
                foreach (var facetParam in selectedFacets)
                {
                    if (firstParam)
                    {
                        sb.Append("?");
                        firstParam = false;
                    }
                    else
                    {
                        sb.Append("&");
                    }
                    if (facetParam.Name.Equals(facet.Id) && !facetParam.ContainsValue(facet.Value))
                    {
                        sb.Append(facetParam.AddValueToUrl(facet.Value));
                        foundFacet = true;
                    }
                    else
                    {
                        sb.Append(facetParam.ToUrl());
                    }
                }
            }
            if (!foundFacet)
            {
                if (firstParam)
                {
                    sb.Append("?");
                }
                else
                {
                    sb.Append("&");
                }
                sb.Append(GetFacetUrl(facet));
            }
            return(sb.ToString());
        }
        public void TestChoicesFacetFoundAndMethodRemovedRemote()
        {
            PropertyInfo property = FindProperty(typeof(Customer10r), "FirstName");
            MethodInfo   propertyChoicesMethod = FindMethod(typeof(Customer10r), "ChoicesFirstName");

            facetFactory.Process(Reflector, property, MethodRemover, Specification);
            IFacet facet = Specification.GetFacet(typeof(IPropertyChoicesFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is PropertyChoicesFacet);
            var propertyChoicesFacet = (PropertyChoicesFacet)facet;

            Assert.AreEqual(propertyChoicesMethod, propertyChoicesFacet.GetMethod());
            AssertMethodRemoved(propertyChoicesMethod);
            var facetExecuted = Specification.GetFacet <IExecutedControlMethodFacet>();

            Assert.IsNotNull(facetExecuted);
            Assert.AreEqual(facetExecuted.ExecutedWhere(propertyChoicesMethod), Where.Remotely);
        }
        public void TestTypeOfFacetInferredForCollectionWithGenericCollectionReturnType()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            PropertyInfo property = FindProperty(typeof(Customer4), "Orders");

            metamodel = facetFactory.Process(Reflector, property, MethodRemover, Specification, metamodel);
            IFacet typeOfFacet = Specification.GetFacet(typeof(ITypeOfFacet));

            Assert.IsNotNull(typeOfFacet);
            Assert.IsTrue(typeOfFacet is TypeOfFacetInferredFromGenerics);

            var elementTypeFacet = Specification.GetFacet <IElementTypeFacet>();

            Assert.IsNotNull(elementTypeFacet);
            Assert.IsTrue(elementTypeFacet is ElementTypeFacet);
            Assert.AreEqual(typeof(Order), elementTypeFacet.Value);
            Assert.IsNotNull(metamodel);
        }
Exemple #36
0
        public virtual IFacet Decorate(IFacet facet, ISpecification holder)
        {
            if (facet.FacetType == typeof(IActionInvocationFacet))
            {
                return(new AuditActionInvocationFacet((IActionInvocationFacet)facet, this));
            }

            if (facet.FacetType == typeof(IUpdatedCallbackFacet))
            {
                return(new AuditUpdatedFacet((IUpdatedCallbackFacet)facet, this));
            }

            if (facet.FacetType == typeof(IPersistedCallbackFacet))
            {
                return(new AuditPersistedFacet((IPersistedCallbackFacet)facet, this));
            }

            return(facet);
        }
Exemple #37
0
        public void TestDefaultPageSizePickedUp()
        {
            IImmutableDictionary <string, ITypeSpecBuilder> metamodel = new Dictionary <string, ITypeSpecBuilder>().ToImmutableDictionary();

            MethodInfo actionMethod = FindMethod(typeof(Customer1), "SomeAction");
            var        identifier   = new IdentifierImpl("Customer1", "SomeAction");
            var        actionPeer   = ImmutableSpecFactory.CreateActionSpecImmutable(identifier, null, null);

            metamodel = new FallbackFacetFactory(0).Process(Reflector, actionMethod, MethodRemover, actionPeer, metamodel);
            IFacet facet = actionPeer.GetFacet(typeof(IPageSizeFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is PageSizeFacetDefault);
            var pageSizeFacet = (IPageSizeFacet)facet;

            Assert.AreEqual(20, pageSizeFacet.Value);
            AssertNoMethodsRemoved();
            Assert.IsNotNull(metamodel);
        }
        public void TestOnUpdatingErrorLifecycleMethodPickedUpOn()
        {
            MethodInfo method1 = FindMethod(typeof(Customer11), "OnUpdatingError", new[] { typeof(Exception) });
            MethodInfo method2 = FindMethod(typeof(Customer11), "OnPersistingError", new[] { typeof(Exception) });

            facetFactory.Process(Reflector, typeof(Customer11), MethodRemover, Specification);
            IFacet facet = Specification.GetFacet(typeof(IOnUpdatingErrorCallbackFacet));

            Assert.IsNotNull(facet);
            Assert.IsTrue(facet is OnUpdatingErrorCallbackFacetViaMethod);
            var onUpdatingErrorCallbackFacetViaMethod = (OnUpdatingErrorCallbackFacetViaMethod)facet;

            Assert.AreEqual(method1, onUpdatingErrorCallbackFacetViaMethod.GetMethod());
            AssertMethodsRemoved(new[] { method1, method2 });
            // and test exception is passed through (assert in Customer11)
            INakedObject adapter = AdapterFor(new Customer11());

            onUpdatingErrorCallbackFacetViaMethod.Invoke(adapter, new Exception());
        }
        private static void CheckChoices(IFacet facet)
        {
            var facetAsEnumFacet = facet as IEnumFacet;

            Assert.IsNotNull(facetAsEnumFacet);
            Assert.AreEqual(3, facetAsEnumFacet.GetChoices(null).Length);
            Assert.AreEqual(Cities.London, facetAsEnumFacet.GetChoices(null)[0]);
            Assert.AreEqual(Cities.NewYork, facetAsEnumFacet.GetChoices(null)[1]);
            Assert.AreEqual(Cities.Paris, facetAsEnumFacet.GetChoices(null)[2]);

            Assert.AreEqual(1, facetAsEnumFacet.GetChoices(null, new object[] { Cities.NewYork }).Length);
            Assert.AreEqual(Cities.NewYork, facetAsEnumFacet.GetChoices(null, new object[] { Cities.NewYork })[0]);

            var          mock        = new Mock <INakedObject>();
            INakedObject nakedObject = mock.Object;

            mock.Setup(no => no.Object).Returns(Cities.NewYork);

            Assert.AreEqual("New York", facetAsEnumFacet.GetTitle(nakedObject));
        }
Exemple #40
0
        protected bool WeHaveExclusionFilters(IFacet[] facets, out string excludes)
        {
            excludes = string.Empty;

            var filters = new List<string>();

            foreach (var facet in facets.Where(facet => facet != this))
            {
                facet.GetFilterQueryTag(filters);
            }

            if (filters.Count == 0)
            {
                return false;
            }

            facets
                .Single(facet => facet == this)
                .GetFilterQueryTag(filters);

            excludes = string.Join(",", filters);

            return true;
        }
 public Facet(IFacet facet)
 {
     DataType = facet.DataType;
     Value    = facet.Value;
     Count    = facet.Count;
 }       
 public static bool IsNotANoopFacet(IFacet facet) {
     return facet != null && !facet.IsNoOp;
 }
 public static void AddFacet(IDictionary<Type, IFacet> facetsByClass, IFacet facet) {
     facetsByClass[facet.FacetType] = facet;
 }
 public override void AddFacet(IFacet facet) {
     nakedObjectActionPeer.AddFacet(facet);
 }
        public void CreateThreeFacetsThatAllHaveOneConstraintApplied()
        {
            SolrNetFacetTestFramework.RunSolrUrlCreationTest(@"http://localhost:8983/solr/select?q=*:*&rows=100000000&fq={!tag=brandsfilter}brand_f:(Smartphones)&fq={!tag=manufacturersfilter}manufacturer_f:(Samsung)&fq={!tag=unitpricefilter}unitprice:([500+TO+600])&facet=true&facet.field={!key=brands+ex=brandsfilter}brand_f&facet.field={!key=brandsruledout+ex=manufacturersfilter,unitpricefilter,brandsfilter}brand_f&facet.field={!key=manufacturers+ex=manufacturersfilter}manufacturer_f&facet.field={!key=manufacturersruledout+ex=brandsfilter,unitpricefilter,manufacturersfilter}manufacturer_f&facet.query={!label=500-600\+ex=unitpricefilter}unitprice:[500+TO+600]&facet.query={!label=601-1000\+ex=unitpricefilter}unitprice:[601+TO+1000]&facet.query={!label=500-600-ruledout\+ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[500+TO+600]&facet.query={!label=601-1000-ruledout\+ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[601+TO+1000]&version=2.2", solr =>
            {
                var querystring = new NameValueCollection
                {
                    {"fb", "Smartphones"},
                    {"fm", "Samsung"},
                    {"fps", "500"},
                    {"fpl", "600"}
                };

                var queryOptions = new QueryOptions();
                var brandFacet = new BrandFacet(querystring);
                var manufacturerFacet = new ManufacturerFacet(querystring);
                var priceFacet = new PriceFacet(querystring, false, new RangeQuery("500", "600"), new RangeQuery("601", "1000"));

                var facets = new IFacet[]
                {
                    brandFacet,
                    manufacturerFacet,
                    priceFacet
                };

                brandFacet.BuildDependencies(facets);
                manufacturerFacet.BuildDependencies(facets);
                priceFacet.BuildDependencies(facets);

                brandFacet.BuildQuery(queryOptions);
                manufacturerFacet.BuildQuery(queryOptions);
                priceFacet.BuildQuery(queryOptions);

                return solr.Query(SolrQuery.All, queryOptions);
            });
        }
 public static void RemoveFacet(IDictionary<Type, IFacet> facetsByClass, IFacet facet) {
     RemoveFacet(facetsByClass, facet.FacetType);
 }
 public void BuildDependencies(IFacet[] facets)
 {
     _facets = facets;
 }
 /// <summary>
 ///     Attaches the <see cref="IFacet" /> to its <see cref="IFacet.Specification" />
 /// </summary>
 /// <returns>
 ///     <c>true</c> if a non-<c>null</c> facet was added, <c>false</c> otherwise.
 /// </returns>
 public static void AddFacet(IFacet facet) {
     if (facet != null) {
         ((ISpecificationBuilder) facet.Specification).AddFacet(facet);
     }
 }
Exemple #49
0
        public void BuildFacetViewModelsForTwoFacetsWithOneBeingARangeFacetThatBothHaveMultipleConstraintsApplied()
        {
            var results =
                SolrNetFacetTestFramework.RunSolrGetResults(
                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><lst name=\"responseHeader\"><int name=\"status\">0</int><int name=\"QTime\">25</int><lst name=\"params\"><str name=\"facet\">true</str><arr name=\"facet.query\"><str>{!label=*-99.99 ex=unitpricefilter}unitprice:[* TO 99.99]</str><str>{!label=100-499.99 ex=unitpricefilter}unitprice:[100 TO 499.99]</str><str>{!label=*-99.99-ruledout ex=brandsfilter,unitpricefilter}unitprice:[* TO 99.99]</str><str>{!label=100-499.99-ruledout ex=brandsfilter,unitpricefilter}unitprice:[100 TO 499.99]</str></arr><str name=\"q\">*:*</str><arr name=\"facet.field\"><str>{!key=brands ex=brandsfilter}brand_f</str><str>{!key=brandsruledout ex=unitpricefilter,brandsfilter}brand_f</str></arr><arr name=\"fq\"><str>{!tag=unitpricefilter}unitprice:([* TO 99.99] OR [100 TO 499.99])</str><str>{!tag=brandsfilter}brand_f:(iPhone OR LCD televisions OR LED televisions OR Smartphones)</str></arr><str name=\"version\">2.2</str><str name=\"rows\">100000000</str></lst></lst><result name=\"response\" numFound=\"5\" start=\"0\"><doc><str name=\"id\">65536</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">100.0</float><str name=\"unitprice_c\">100.0000,USD</str><str name=\"name\">iPhone</str><str name=\"url\">home/electronics/phones/iphone</str><long name=\"_version_\">1435991846256902144</long></doc><doc><str name=\"id\">65537</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">200.0</float><str name=\"unitprice_c\">200.0000,USD</str><str name=\"name\">iPhone3G</str><str name=\"url\">home/electronics/phones/iphone3g</str><long name=\"_version_\">1435991846263193600</long></doc><doc><str name=\"id\">65540</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">250.0</float><str name=\"unitprice_c\">250.0000,USD</str><str name=\"name\">iPhone3GS</str><str name=\"url\">home/electronics/phones/iphone3gs</str><long name=\"_version_\">1435991846267387904</long></doc><doc><str name=\"id\">65541</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">350.0</float><str name=\"unitprice_c\">350.0000,USD</str><str name=\"name\">iPhone4</str><str name=\"url\">home/electronics/phones/iphone4</str><long name=\"_version_\">1435991846272630784</long></doc><doc><str name=\"id\">65548</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">270.0</float><str name=\"unitprice_c\">270.0000,USD</str><str name=\"name\">Omina W</str><str name=\"url\">home/electronics/phones/omina-w</str><long name=\"_version_\">1435991846282067968</long></doc></result><lst name=\"facet_counts\"><lst name=\"facet_queries\"><int name=\"{!label=*-99.99 ex=unitpricefilter}unitprice:[* TO 99.99]\">0</int><int name=\"{!label=100-499.99 ex=unitpricefilter}unitprice:[100 TO 499.99]\">5</int><int name=\"{!label=*-99.99-ruledout ex=brandsfilter,unitpricefilter}unitprice:[* TO 99.99]\">1</int><int name=\"{!label=100-499.99-ruledout ex=brandsfilter,unitpricefilter}unitprice:[100 TO 499.99]\">8</int></lst><lst name=\"facet_fields\"><lst name=\"brands\"><int name=\"iPhone\">4</int><int name=\"Mobile phones\">2</int><int name=\"iPad\">2</int><int name=\"Smartphones\">1</int><int name=\"LCD televisions\">0</int><int name=\"LED televisions\">0</int><int name=\"Plasma televisions\">0</int></lst><lst name=\"brandsruledout\"><int name=\"iPhone\">5</int><int name=\"iPad\">3</int><int name=\"Mobile phones\">2</int><int name=\"Smartphones\">2</int><int name=\"LCD televisions\">1</int><int name=\"LED televisions\">1</int><int name=\"Plasma televisions\">1</int></lst></lst><lst name=\"facet_dates\"/><lst name=\"facet_ranges\"/></lst></response>",
                    @"http://localhost:8983/solr/select?q=*:*&rows=100000000&fq={!tag=unitpricefilter}unitprice:([* TO 99.99] OR [100 TO 499.99])&fq={!tag=brandsfilter}brand_f:(iPhone OR LCD televisions OR LED televisions OR Smartphones)&facet=true&facet.query={!label=*-99.99 ex=unitpricefilter}unitprice:[* TO 99.99]&facet.query={!label=100-499.99 ex=unitpricefilter}unitprice:[100 TO 499.99]&facet.query={!label=*-99.99-ruledout ex=brandsfilter,unitpricefilter}unitprice:[* TO 99.99]&facet.query={!label=100-499.99-ruledout ex=brandsfilter,unitpricefilter}unitprice:[100 TO 499.99]&facet.field={!key=brands ex=brandsfilter}brand_f&facet.field={!key=brandsruledout ex=unitpricefilter,brandsfilter}brand_f&version=2.2");

            var querystring = new NameValueCollection
                            {
                                {"fps", "*"},
                                {"fpl", "99.99"},
                                {"fps", "100"},
                                {"fpl", "499.99"},
                                {"fb", "Smartphones"},
                                {"fb", "iPhone"},
                                {"fb", "LCD televisions"},
                                {"fb", "LED televisions"}
                            };

            var brandFacet = new BrandFacet(querystring);
            var priceFacet = new PriceFacet(querystring, false, new RangeQuery("*", "99.99"), new RangeQuery("100", "499.99"));

            var facets = new IFacet[]
                {
                    brandFacet,
                    priceFacet
                };

            brandFacet.BuildDependencies(facets);
            priceFacet.BuildDependencies(facets);

            var brandFacetViewModel = brandFacet.BuildViewModel(results);
            var priceFacetViewModel = priceFacet.BuildViewModel(results);

            var expectedBrandValues = new[] {
                new { IsApplied = false, IsDisabled = false, Count = 2, Name = "iPad", Url = "/?fps=*&fps=100&fpl=99.99&fpl=499.99&fb=iPad&fb=iPhone&fb=LCD+televisions&fb=LED+televisions&fb=Smartphones" },
                new { IsApplied = true, IsDisabled = false, Count = 4, Name = "iPhone", Url = "/?fps=*&fps=100&fpl=99.99&fpl=499.99&fb=LCD+televisions&fb=LED+televisions&fb=Smartphones" },
                new { IsApplied = true, IsDisabled = true, Count = 1, Name = "LCD televisions", Url = string.Empty },
                new { IsApplied = true, IsDisabled = true, Count = 1, Name = "LED televisions", Url = string.Empty },
                new { IsApplied = false, IsDisabled = false, Count = 2, Name = "Mobile phones", Url = "/?fps=*&fps=100&fpl=99.99&fpl=499.99&fb=iPhone&fb=LCD+televisions&fb=LED+televisions&fb=Mobile+phones&fb=Smartphones" },
                new { IsApplied = false, IsDisabled = true, Count = 1, Name = "Plasma televisions", Url = string.Empty },
                new { IsApplied = true, IsDisabled = false, Count = 1, Name = "Smartphones", Url = "/?fps=*&fps=100&fpl=99.99&fpl=499.99&fb=iPhone&fb=LCD+televisions&fb=LED+televisions" }
            };

            Assert.AreEqual(7, brandFacetViewModel.Constraints.Length);

            for (var index = 0; index < brandFacetViewModel.Constraints.Length; index++)
            {
                Assert.AreEqual(expectedBrandValues[index].IsApplied, brandFacetViewModel.Constraints[index].IsApplied);
                Assert.AreEqual(expectedBrandValues[index].IsDisabled, brandFacetViewModel.Constraints[index].IsDisabled);
                Assert.AreEqual(expectedBrandValues[index].Count, brandFacetViewModel.Constraints[index].Count);
                Assert.AreEqual(expectedBrandValues[index].Name, brandFacetViewModel.Constraints[index].Name);
                Assert.AreEqual(expectedBrandValues[index].Url, brandFacetViewModel.Constraints[index].Url);
            }

            var expectedPriceValues = new[] {
                new { IsApplied = true, IsDisabled = true, Count = 1, Name = string.Format("Up to {0}99.99", NumberFormatInfo.CurrentInfo.CurrencySymbol), Url = string.Empty },
                new { IsApplied = true, IsDisabled = false, Count = 5, Name = string.Format("{0}100.00 - {0}499.99", NumberFormatInfo.CurrentInfo.CurrencySymbol), Url = "/?fb=iPhone&fb=LCD+televisions&fb=LED+televisions&fb=Smartphones&fps=*&fpl=99.99" }
            };

            Assert.AreEqual(2, priceFacetViewModel.Constraints.Length);

            for (var index = 0; index < priceFacetViewModel.Constraints.Length; index++)
            {
                Assert.AreEqual(expectedPriceValues[index].IsApplied, priceFacetViewModel.Constraints[index].IsApplied);
                Assert.AreEqual(expectedPriceValues[index].IsDisabled, priceFacetViewModel.Constraints[index].IsDisabled);
                Assert.AreEqual(expectedPriceValues[index].Count, priceFacetViewModel.Constraints[index].Count);
                Assert.AreEqual(expectedPriceValues[index].Name, priceFacetViewModel.Constraints[index].Name);
                Assert.AreEqual(expectedPriceValues[index].Url, priceFacetViewModel.Constraints[index].Url);
            }
        }
        JProperty Build(IFacet facet, long? defaultSize)
        {
            Argument.EnsureNotNull("facet", facet);

            var specificBody = Build(facet);
            if (facet is IOrderableFacet)
            {
                var facetSize = ((IOrderableFacet)facet).Size ?? defaultSize;
                if (facetSize.HasValue)
                    specificBody["size"] = facetSize.Value.ToString(transportCulture);
            }

            var namedBody = new JObject(new JProperty(facet.Type, specificBody));

            if (facet.Filter != null)
                namedBody["filter"] = Build(facet.Filter);

            return new JProperty(facet.Name, namedBody);
        }
        public void CreateTwoFacetsThatBothHaveMultipleConstraintsApplied()
        {
            SolrNetFacetTestFramework.RunSolrUrlCreationTest(@"http://localhost:8983/solr/select?q=*:*&rows=100000000&fq={!tag=brandsfilter}brand_f:(iPhone+OR+LCD+televisions+OR+LED+televisions+OR+Smartphones)&fq={!tag=manufacturersfilter}manufacturer_f:(Apple+OR+Samsung)&facet=true&facet.field={!key=brands+ex=brandsfilter}brand_f&facet.field={!key=brandsruledout+ex=manufacturersfilter,brandsfilter}brand_f&facet.field={!key=manufacturers+ex=manufacturersfilter}manufacturer_f&facet.field={!key=manufacturersruledout+ex=brandsfilter,manufacturersfilter}manufacturer_f&version=2.2", solr =>
            {
                var querystring = new NameValueCollection
                {
                    {"fb", "Smartphones"},
                    {"fb", "iPhone"},
                    {"fb", "LCD televisions"},
                    {"fb", "LED televisions"},
                    {"fm", "Apple"},
                    {"fm", "Samsung"}
                };

                var queryOptions = new QueryOptions();
                var brandFacet = new BrandFacet(querystring);
                var manufacturerFacet = new ManufacturerFacet(querystring);

                var facets = new IFacet[]
                {
                    brandFacet,
                    manufacturerFacet
                };

                brandFacet.BuildDependencies(facets);
                manufacturerFacet.BuildDependencies(facets);

                brandFacet.BuildQuery(queryOptions);
                manufacturerFacet.BuildQuery(queryOptions);

                return solr.Query(SolrQuery.All, queryOptions);
            });
        }
        public ElasticQuery SetFacets(IFacet facet)
        {
            Facets = facet;
            return this;
		}
 public static IFacet[] GetFacets(IFacet facet, IFacetFilter filter) {
     if (filter.Accept(facet)) {
         return new[] {facet};
     }
     return new IFacet[] {};
 }
 public override void RemoveFacet(IFacet facet) {
     nakedObjectActionPeer.RemoveFacet(facet);
 }
        public void CreateTwoFacetsWithOneBeingARangeFacetThatBothHaveMultipleConstraintsApplied()
        {
            SolrNetFacetTestFramework.RunSolrUrlCreationTest(@"http://localhost:8983/solr/select?q=*:*&rows=100000000&fq={!tag=unitpricefilter}unitprice:([*+TO+99.99]+OR+[100+TO+499.99])&fq={!tag=brandsfilter}brand_f:(iPhone+OR+LCD+televisions+OR+LED+televisions+OR+Smartphones)&facet=true&facet.query={!label=*-99.99\+ex=unitpricefilter}unitprice:[*+TO+99.99]&facet.query={!label=100-499.99\+ex=unitpricefilter}unitprice:[100+TO+499.99]&facet.query={!label=*-99.99-ruledout\+ex=brandsfilter,unitpricefilter}unitprice:[*+TO+99.99]&facet.query={!label=100-499.99-ruledout\+ex=brandsfilter,unitpricefilter}unitprice:[100+TO+499.99]&facet.field={!key=brands+ex=brandsfilter}brand_f&facet.field={!key=brandsruledout+ex=unitpricefilter,brandsfilter}brand_f&version=2.2", solr =>
            {
                var querystring = new NameValueCollection
                            {
                                {"fps", "*"},
                                {"fpl", "99.99"},
                                {"fps", "100"},
                                {"fpl", "499.99"},
                                {"fb", "Smartphones"},
                                {"fb", "iPhone"},
                                {"fb", "LCD televisions"},
                                {"fb", "LED televisions"}
                            };

                var queryOptions = new QueryOptions();
                var brandFacet = new BrandFacet(querystring);
                var priceFacet = new PriceFacet(querystring, false, new RangeQuery("*", "99.99"), new RangeQuery("100", "499.99"));

                var facets = new IFacet[]
                {
                    priceFacet,
                    brandFacet
                };

                priceFacet.BuildDependencies(facets);
                brandFacet.BuildDependencies(facets);

                priceFacet.BuildQuery(queryOptions);
                brandFacet.BuildQuery(queryOptions);

                return solr.Query(SolrQuery.All, queryOptions);
            });
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="FacetExpression"/> class.
 /// </summary>
 /// <param name="facet"><see cref="IFacet" /> to represent with this expression.</param>
 public FacetExpression(IFacet facet)
 {
     this.facet = facet;
 }
        static JToken Build(IFacet facet)
        {
            if (facet is StatisticalFacet)
                return Build((StatisticalFacet)facet);

            if (facet is TermsStatsFacet)
                return Build((TermsStatsFacet)facet);

            if (facet is TermsFacet)
                return Build((TermsFacet)facet);

            if (facet is FilterFacet)
                return new JObject();

            throw new InvalidOperationException(string.Format("Unknown implementation of IFacet '{0}' can not be formatted", facet.GetType().Name));
        }
 public IFacet Decorate(IFacet facet, ISpecification holder) {
     return forFacetTypes.Contains(facet.FacetType) ? FacetToConstructorMap[facet.FacetType](facet, this) : facet;
 }
 public List<IFacet> GetFacetAndHisChilds(IFacet facet)
 {
     return Facets.Where(x => x.Branch == facet.Branch && x.Level >= facet.Level)
                  .ToList();
 }
        public void BuildTwoMultipleSelectFacetViewModelThatBothHaveMultipleConstraintsApplied()
        {
            var results =
                SolrNetFacetTestFramework.RunSolrGetResults(
                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><lst name=\"responseHeader\"><int name=\"status\">0</int><int name=\"QTime\">121</int><lst name=\"params\"><str name=\"facet\">true</str><str name=\"q\">*:*</str><arr name=\"facet.field\"><str>{!key=brands ex=brandsfilter}brand_f</str><str>{!key=brandsruledout ex=manufacturersfilter,brandsfilter}brand_f</str><str>{!key=manufacturers ex=manufacturersfilter}manufacturer_f</str><str>{!key=manufacturersruledout ex=brandsfilter,manufacturersfilter}manufacturer_f</str></arr><arr name=\"fq\"><str>{!tag=brandsfilter}brand_f:(iPhone OR LCD televisions OR LED televisions OR Smartphones)</str><str>{!tag=manufacturersfilter}manufacturer_f:(Apple OR Samsung)</str></arr><str name=\"version\">2.2</str><str name=\"rows\">100000000</str></lst></lst><result name=\"response\" numFound=\"7\" start=\"0\"><doc><str name=\"id\">65538</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">523.0</float><str name=\"unitprice_c\">523.0000,USD</str><str name=\"name\">Galaxy Note</str><str name=\"url\">home/electronics/phones/galaxy-note</str><long name=\"_version_\">1435991846240124928</long></doc><doc><str name=\"id\">65536</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">100.0</float><str name=\"unitprice_c\">100.0000,USD</str><str name=\"name\">iPhone</str><str name=\"url\">home/electronics/phones/iphone</str><long name=\"_version_\">1435991846256902144</long></doc><doc><str name=\"id\">65537</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">200.0</float><str name=\"unitprice_c\">200.0000,USD</str><str name=\"name\">iPhone3G</str><str name=\"url\">home/electronics/phones/iphone3g</str><long name=\"_version_\">1435991846263193600</long></doc><doc><str name=\"id\">65540</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">250.0</float><str name=\"unitprice_c\">250.0000,USD</str><str name=\"name\">iPhone3GS</str><str name=\"url\">home/electronics/phones/iphone3gs</str><long name=\"_version_\">1435991846267387904</long></doc><doc><str name=\"id\">65541</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">350.0</float><str name=\"unitprice_c\">350.0000,USD</str><str name=\"name\">iPhone4</str><str name=\"url\">home/electronics/phones/iphone4</str><long name=\"_version_\">1435991846272630784</long></doc><doc><str name=\"id\">65539</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">550.0</float><str name=\"unitprice_c\">550.0000,USD</str><str name=\"name\">iPhone4S</str><str name=\"url\">home/electronics/phones/iphone4s</str><long name=\"_version_\">1435991846277873664</long></doc><doc><str name=\"id\">65548</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">270.0</float><str name=\"unitprice_c\">270.0000,USD</str><str name=\"name\">Omina W</str><str name=\"url\">home/electronics/phones/omina-w</str><long name=\"_version_\">1435991846282067968</long></doc></result><lst name=\"facet_counts\"><lst name=\"facet_queries\"/><lst name=\"facet_fields\"><lst name=\"brands\"><int name=\"iPhone\">5</int><int name=\"iPad\">3</int><int name=\"Mobile phones\">2</int><int name=\"Smartphones\">2</int><int name=\"LCD televisions\">1</int><int name=\"LED televisions\">1</int><int name=\"Plasma televisions\">1</int></lst><lst name=\"brandsruledout\"><int name=\"iPhone\">5</int><int name=\"iPad\">3</int><int name=\"Mobile phones\">2</int><int name=\"Smartphones\">2</int><int name=\"LCD televisions\">1</int><int name=\"LED televisions\">1</int><int name=\"Plasma televisions\">1</int></lst><lst name=\"manufacturers\"><int name=\"Apple\">5</int><int name=\"Samsung\">2</int></lst><lst name=\"manufacturersruledout\"><int name=\"Apple\">8</int><int name=\"Samsung\">7</int></lst></lst><lst name=\"facet_dates\"/><lst name=\"facet_ranges\"/></lst></response>",
                    @"http://localhost:8983/solr/select?q=*:*&rows=100000000&fq={!tag=brandsfilter}brand_f:(iPhone+OR+LCD+televisions+OR+LED+televisions+OR+Smartphones)&fq={!tag=manufacturersfilter}manufacturer_f:(Apple+OR+Samsung)&facet=true&facet.field={!key=brands+ex=brandsfilter}brand_f&facet.field={!key=brandsruledout+ex=manufacturersfilter,brandsfilter}brand_f&facet.field={!key=manufacturers+ex=manufacturersfilter}manufacturer_f&facet.field={!key=manufacturersruledout+ex=brandsfilter,manufacturersfilter}manufacturer_f&version=2.2");

            var querystring = new NameValueCollection
            {
                    {"fb", "Smartphones"},
                    {"fb", "iPhone"},
                    {"fb", "LCD televisions"},
                    {"fb", "LED televisions"},
                    {"fm", "Apple"},
                    {"fm", "Samsung"}
                };

            var brandFacet = new BrandFacet(querystring);
            var manufacturerFacet = new ManufacturerFacet(querystring);

            var facets = new IFacet[]
                {
                    brandFacet,
                    manufacturerFacet
                };

            brandFacet.BuildDependencies(facets);
            manufacturerFacet.BuildDependencies(facets);

            var brandFacetViewModel = brandFacet.BuildViewModel(results);
            var manufacturerFacetViewModel = manufacturerFacet.BuildViewModel(results);

            var expectedBrandValues = new[] {
                new { IsApplied = false, IsDisabled = false, Count = 3, Name = "iPad", Url = "/?fm=Apple&fm=Samsung&fb=iPad&fb=iPhone&fb=LCD+televisions&fb=LED+televisions&fb=Smartphones" },
                new { IsApplied = true, IsDisabled = false, Count = 5, Name = "iPhone", Url = "/?fm=Apple&fm=Samsung&fb=LCD+televisions&fb=LED+televisions&fb=Smartphones" },
                new { IsApplied = true, IsDisabled = false, Count = 1, Name = "LCD televisions", Url = "/?fm=Apple&fm=Samsung&fb=iPhone&fb=LED+televisions&fb=Smartphones" },
                new { IsApplied = true, IsDisabled = false, Count = 1, Name = "LED televisions", Url = "/?fm=Apple&fm=Samsung&fb=iPhone&fb=LCD+televisions&fb=Smartphones" },
                new { IsApplied = false, IsDisabled = false, Count = 2, Name = "Mobile phones", Url = "/?fm=Apple&fm=Samsung&fb=iPhone&fb=LCD+televisions&fb=LED+televisions&fb=Mobile+phones&fb=Smartphones" },
                new { IsApplied = false, IsDisabled = false, Count = 1, Name = "Plasma televisions", Url = "/?fm=Apple&fm=Samsung&fb=iPhone&fb=LCD+televisions&fb=LED+televisions&fb=Plasma+televisions&fb=Smartphones" },
                new { IsApplied = true, IsDisabled = false, Count = 2, Name = "Smartphones", Url = "/?fm=Apple&fm=Samsung&fb=iPhone&fb=LCD+televisions&fb=LED+televisions" }
            };

            Assert.AreEqual(7, brandFacetViewModel.Constraints.Length);

            for (var index = 0; index < brandFacetViewModel.Constraints.Length; index++)
            {
                Assert.AreEqual(expectedBrandValues[index].IsApplied, brandFacetViewModel.Constraints[index].IsApplied);
                Assert.AreEqual(expectedBrandValues[index].IsDisabled, brandFacetViewModel.Constraints[index].IsDisabled);
                Assert.AreEqual(expectedBrandValues[index].Count, brandFacetViewModel.Constraints[index].Count);
                Assert.AreEqual(expectedBrandValues[index].Name, brandFacetViewModel.Constraints[index].Name);
                Assert.AreEqual(expectedBrandValues[index].Url, brandFacetViewModel.Constraints[index].Url);
            }

            var expectedManufacturerValues = new[] {
                new { IsApplied = true, IsDisabled = false, Count = 5, Name = "Apple", Url = "/?fb=iPhone&fb=LCD+televisions&fb=LED+televisions&fb=Smartphones&fm=Samsung" },
                new { IsApplied = true, IsDisabled = false, Count = 2, Name = "Samsung", Url = "/?fb=iPhone&fb=LCD+televisions&fb=LED+televisions&fb=Smartphones&fm=Apple" }
            };

            Assert.AreEqual(2, manufacturerFacetViewModel.Constraints.Length);

            for (var index = 0; index < manufacturerFacetViewModel.Constraints.Length; index++)
            {
                Assert.AreEqual(expectedManufacturerValues[index].IsApplied, manufacturerFacetViewModel.Constraints[index].IsApplied);
                Assert.AreEqual(expectedManufacturerValues[index].IsDisabled, manufacturerFacetViewModel.Constraints[index].IsDisabled);
                Assert.AreEqual(expectedManufacturerValues[index].Count, manufacturerFacetViewModel.Constraints[index].Count);
                Assert.AreEqual(expectedManufacturerValues[index].Name, manufacturerFacetViewModel.Constraints[index].Name);
                Assert.AreEqual(expectedManufacturerValues[index].Url, manufacturerFacetViewModel.Constraints[index].Url);
            }
        }