Exemplo n.º 1
0
        public IEnumerable <dynamic> Get(string classCode, string filteringQuery, string sortingMemberCode, string sortingDirection, int?pagingSkip, int?pagingTake)
        {
            ISerializedObjectRepository serializedObjectRepository = this.Storage.GetRepository <ISerializedObjectRepository>();
            Class   @class = this.GetValidatedClass(classCode);
            Culture frontendDefaultCulture = this.GetService <ICultureManager>().GetFrontendDefaultCulture();
            Params  @params = new ParamsFactory(this).Create(filteringQuery, @class.Id, sortingMemberCode, sortingDirection, pagingSkip, pagingTake);
            IEnumerable <SerializedObject> serializedObjects = serializedObjectRepository.FilteredByCultureIdAndClassId(
                frontendDefaultCulture.Id, @class.Id, @params
                ).ToList();

            ObjectDirector objectDirector = new ObjectDirector(this);

            this.Response.Headers.Add("Filtering-Query", WebUtility.UrlEncode(filteringQuery));
            this.Response.Headers.Add("Sorting-Member-Code", sortingMemberCode);
            this.Response.Headers.Add("Sorting-Direction", sortingDirection);
            this.Response.Headers.Add("Paging-Skip", pagingSkip.ToString());
            this.Response.Headers.Add("Paging-Take", pagingTake.ToString());
            this.Response.Headers.Add("Paging-Total", serializedObjectRepository.CountByCultureIdAndClassId(frontendDefaultCulture.Id, @class.Id, @params).ToString());
            return(serializedObjects.Select(
                       so =>
            {
                DynamicObjectBuilder objectBuilder = new DynamicObjectBuilder();

                objectDirector.ConstructObject(objectBuilder, so);
                return objectBuilder.Build();
            }
                       ));
        }
Exemplo n.º 2
0
        public dynamic Get(string classCode, int id)
        {
            Object @object = this.Storage.GetRepository <IObjectRepository>().WithKey(id);
            DynamicObjectBuilder objectBuilder = new DynamicObjectBuilder();

            new ObjectDirector(this).ConstructObject(objectBuilder, @object);
            return(objectBuilder.Build());
        }
Exemplo n.º 3
0
        public void Build_WithFieldsAndValuesOfDifferentLength_ThrowsArgumentException()
        {
            var builder = new DynamicObjectBuilder();

            string[] fields = new[] { "Name" };
            string[] values = new[] { "Dave", "Smith" };
            Assert.ThrowsException <ArgumentException>(() => builder.Build(fields, values));
        }
Exemplo n.º 4
0
        public void Build_WithEmptyValie_ThrowsArgumentOutOfRangeException()
        {
            var builder = new DynamicObjectBuilder();

            string[] fields = new[] { "Name" };
            string[] values = { };
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => builder.Build(fields, values));
        }
Exemplo n.º 5
0
        public void Build_WithNullValues_ThrowsArgumentNullException()
        {
            var builder = new DynamicObjectBuilder();

            string[] fields = { "Name" };
            string[] values = null;
            Assert.ThrowsException <ArgumentNullException>(() => builder.Build(fields, values));
        }
Exemplo n.º 6
0
        public dynamic Get(string classCode, int id)
        {
            Class                @class           = this.GetValidatedClass(classCode);
            SerializedObject     serializedObject = this.GetValidatedSerializedObject(@class, id);
            DynamicObjectBuilder objectBuilder    = new DynamicObjectBuilder();

            new ObjectDirector(this).ConstructObject(objectBuilder, serializedObject);
            return(objectBuilder.Build());
        }
Exemplo n.º 7
0
        public void Build_WithValidFieldsAndValues_ReturnsDynamicObject()
        {
            var builder = new DynamicObjectBuilder();

            string[] fields = new[] { "GivenName", "FamilyName" };
            string[] values = new[] { "Dave", "Smith" };
            var      result = builder.Build(fields, values);

            Assert.AreEqual("Dave", result.GivenName);
            Assert.AreEqual("Smith", result.FamilyName);
        }
Exemplo n.º 8
0
        public void Build_WithNullValue_ReturnsDynamicObject()
        {
            var builder = new DynamicObjectBuilder();

            string[] fields = new[] { "GivenName", "MiddleNames", "FamilyName" };
            string[] values = new[] { "Dave", null, "Smith" };
            var      result = builder.Build(fields, values);

            Assert.AreEqual("Dave", result.GivenName);
            Assert.IsNull(result.MiddleNames);
            Assert.AreEqual("Smith", result.FamilyName);
        }
Exemplo n.º 9
0
        public void Build_WithNestedFieldsAndValues_ReturnsNestedDynamicObject()
        {
            var builder = new DynamicObjectBuilder();

            string[] fields = new[] { "Contact_Phone_Home", "GivenName", "FamilyName", "Contact_Email", "Contact_Phone_Mobile" };
            string[] values = new[] { "01234568", "Dave", "Smith", "*****@*****.**", "0712345689" };
            var      result = builder.Build(fields, values);

            Assert.AreEqual("Dave", result.GivenName);
            Assert.AreEqual("Smith", result.FamilyName);
            Assert.AreEqual("*****@*****.**", result.Contact.Email);
            Assert.AreEqual("01234568", result.Contact.Phone.Home);
            Assert.AreEqual("0712345689", result.Contact.Phone.Mobile);
        }
Exemplo n.º 10
0
        public IEnumerable <dynamic> Get(string classCode)
        {
            Class @class = this.Storage.GetRepository <IClassRepository>().WithCode(classCode);
            IEnumerable <Object> objects        = this.Storage.GetRepository <IObjectRepository>().FilteredByClassId(@class.Id);
            ObjectDirector       objectDirector = new ObjectDirector(this);

            return(objects.Select(
                       o => {
                DynamicObjectBuilder objectBuilder = new DynamicObjectBuilder();

                objectDirector.ConstructObject(objectBuilder, o);
                return objectBuilder.Build();
            }
                       ));
        }