Esempio n. 1
0
        public async Task TestGetPageByProjection()
        {
            // arrange
            var dummy1 = await _persistence.CreateAsync(null, _dummy1);

            var dummy2 = await _persistence.CreateAsync(null, _dummy2);

            var builder = Builders <Dummy> .Filter;
            var filter  = builder.Empty;

            var projection = ProjectionParams.FromValues("inner_dummy.description", "content", "key", "create_time_utc");

            // act
            dynamic result = await _persistence.GetPageByFilterAndProjectionAsync(null, filter, null, null, projection);

            // assert
            Assert.NotNull(result);
            Assert.Equal(2, result.Data.Count);
            Assert.Equal(dummy1.Key, result.Data[0].key);
            Assert.Equal(dummy1.Content, result.Data[0].content);
            Assert.Equal(dummy1.InnerDummy.Description, result.Data[0].inner_dummy.description);
            Assert.Equal(dummy1.CreateTimeUtc.ToString(), result.Data[0].create_time_utc.ToString());
            Assert.Equal(dummy2.Key, result.Data[1].key);
            Assert.Equal(dummy2.Content, result.Data[1].content);
        }
Esempio n. 2
0
        public async Task TestGetPageByProjectionAndSortedByMultipleFields()
        {
            // arrange
            var dummy1 = await _persistence.CreateAsync(null, _dummy1);

            var dummy2 = await _persistence.CreateAsync(null, _dummy2);

            var dummy3 = await _persistence.CreateAsync(null, _dummy3);

            // keys: Key 1, Key 2, Key 3
            // dummy_type: not_dummy, dummy, dummy

            var sortParams = new SortParams()
            {
                new SortField("dummy_type", false),
                new SortField("key", false)
            };

            // result -> 1 (not dummy, Key 1), 3 (dummy, Key 3), 2 (dummy, Key 2)

            var projection = ProjectionParams.FromValues("key");

            // act
            dynamic result = await _persistence.GetAsync(null, null, null, sortParams, projection);

            // assert
            Assert.NotNull(result);
            Assert.Equal(3, result.Data.Count);

            Assert.Equal(dummy1.Key, result.Data[0].key);
            Assert.Equal(dummy3.Key, result.Data[1].key);
            Assert.Equal(dummy2.Key, result.Data[2].key);
        }
Esempio n. 3
0
        public void It_Should_Convert_Parameters_From_Values_As_One_String()
        {
            var parameters = ProjectionParams.FromValues("field1,field2, field3");

            Assert.Equal(3, parameters.Count);
            Assert.Equal("field1", parameters[0]);
            Assert.Equal("field2", parameters[1]);
            Assert.Equal("field3", parameters[2]);
        }
Esempio n. 4
0
        public void It_Should_Convert_Parameters_From_Multiple_Grouped_Values4()
        {
            var parameters = ProjectionParams.FromValues("object1(object2(object3(field1)), field2)", "field2");

            Assert.Equal(3, parameters.Count);
            Assert.Equal("object1.object2.object3.field1", parameters[0]);
            Assert.Equal("object1.field2", parameters[1]);
            Assert.Equal("field2", parameters[2]);
        }
Esempio n. 5
0
        public void It_Should_Convert_Parameters_From_Grouped_Values_As_One_String()
        {
            var parameters = ProjectionParams.FromValues("object1(object2(field1,field2,object3(field1)))");

            Assert.Equal(3, parameters.Count);
            Assert.Equal("object1.object2.field1", parameters[0]);
            Assert.Equal("object1.object2.field2", parameters[1]);
            Assert.Equal("object1.object2.object3.field1", parameters[2]);
        }
Esempio n. 6
0
        public void It_Should_Convert_Parameters_From_Grouped_Values()
        {
            var parameters = ProjectionParams.FromValues("object1(field1)", "object2(field1, field2)", "field3");

            Assert.Equal(4, parameters.Count);
            Assert.Equal("object1.field1", parameters[0]);
            Assert.Equal("object2.field1", parameters[1]);
            Assert.Equal("object2.field2", parameters[2]);
            Assert.Equal("field3", parameters[3]);
        }
Esempio n. 7
0
        public void It_Should_Convert_Parameters_From_Multiple_Grouped_And_Delimitered_Values()
        {
            var parameters = ProjectionParams.FromValues(';', "A:abc,def;B:bcd;C(D:d,f,g;F:f)");

            Assert.Equal(4, parameters.Count);
            Assert.Equal("A:abc,def", parameters[0]);
            Assert.Equal("B:bcd", parameters[1]);
            Assert.Equal("C.D:d,f,g", parameters[2]);
            Assert.Equal("C.F:f", parameters[3]);
        }
Esempio n. 8
0
        public void It_Should_Convert_Parameters_From_Multiple_Grouped_Values_And_Another_Delimiter()
        {
            var parameters = ProjectionParams.FromValues(';', "field1;object1(field1);object2(field1;field2);object3(field1);field2;field3");

            Assert.Equal(7, parameters.Count);
            Assert.Equal("field1", parameters[0]);
            Assert.Equal("object1.field1", parameters[1]);
            Assert.Equal("object2.field1", parameters[2]);
            Assert.Equal("object2.field2", parameters[3]);
            Assert.Equal("object3.field1", parameters[4]);
            Assert.Equal("field2", parameters[5]);
            Assert.Equal("field3", parameters[6]);
        }
Esempio n. 9
0
        public void It_Should_Convert_Parameters_From_Multiple_Grouped_Values1()
        {
            var parameters = ProjectionParams.FromValues("object1(field1, object2(field1, field2, field3, field4), field3)", "field2");

            Assert.Equal(7, parameters.Count);
            Assert.Equal("object1.field1", parameters[0]);
            Assert.Equal("object1.object2.field1", parameters[1]);
            Assert.Equal("object1.object2.field2", parameters[2]);
            Assert.Equal("object1.object2.field3", parameters[3]);
            Assert.Equal("object1.object2.field4", parameters[4]);
            Assert.Equal("object1.field3", parameters[5]);
            Assert.Equal("field2", parameters[6]);
        }
Esempio n. 10
0
        public async Task TestGetByIdAndWrongProjection()
        {
            // arrange
            var dummy = await _persistence.CreateAsync(null, _dummy1);

            var projection = ProjectionParams.FromValues("Wrong_Key", "Wrong_Content");

            // act
            dynamic result = await _persistence.GetOneByIdAsync(null, dummy.Id, projection);

            // assert
            Assert.Null(result);
        }
Esempio n. 11
0
        public void It_Should_Return_Projected_Fields_For_Object()
        {
            dynamic obj = CreateExpandoObject();

            var projectionParams = ProjectionParams.FromValues("Id,Name");

            dynamic result = projectionParams.FromObject(obj as ExpandoObject);

            Assert.Equal(obj.Id, result.Id);
            Assert.Equal(obj.Name, result.Name);

            AssertProperties(result, "Id", "Name");
        }
Esempio n. 12
0
        public async Task TestGetByWrongIdAndProjection()
        {
            // arrange
            var dummy = await _persistence.CreateAsync(null, _dummy1);

            var projection = ProjectionParams.FromValues("inner_dummy.description", "content", "key");

            // act
            dynamic result = await _persistence.GetOneByIdAsync(null, "wrong_id", projection);

            // assert
            Assert.Null(result);
        }
Esempio n. 13
0
        public async Task TestGetByIdAndIdProjection()
        {
            // arrange
            var dummy = await _persistence.CreateAsync(null, _dummy1);

            var projection = ProjectionParams.FromValues("id");

            // act
            dynamic result = await _persistence.GetOneByIdAsync(null, dummy.Id, projection);

            // assert
            Assert.NotNull(result);
            Assert.Equal(dummy.Id, result.id);
        }
Esempio n. 14
0
        public async Task TestGetByIdAndProjectionFromArray()
        {
            // arrange
            var dummy = await _persistence.CreateAsync(null, _dummy1);

            var projection = ProjectionParams.FromValues("key", "inner_dummies(name, description)");

            // act
            dynamic result = await _persistence.GetOneByIdAsync(null, dummy.Id, projection);

            // assert
            Assert.NotNull(result);
            Assert.Equal(dummy.Key, result.key);
            Assert.Equal(dummy.InnerDummies[0].Name, result.inner_dummies[0].name);
            Assert.Equal(dummy.InnerDummies[1].Description, result.inner_dummies[1].description);
        }
Esempio n. 15
0
        public void It_Should_Return_Projected_Fields_For_Object_With_Nested_Properties()
        {
            dynamic obj = CreateExpandoObject();

            var projectionParams = ProjectionParams.FromValues("Id,Description,Data(Id,Amount)");

            dynamic result = projectionParams.FromObject(obj as ExpandoObject);

            Assert.Equal(obj.Id, result.Id);
            Assert.Equal(obj.Description, result.Description);
            Assert.Equal(obj.Data.Id, result.Data.Id);
            Assert.Equal(obj.Data.Amount, result.Data.Amount);

            AssertProperties(result, "Id", "Description", "Data");
            AssertProperties(result.Data, "Id", "Amount");
        }
Esempio n. 16
0
        public async Task TestGetByIdAndProjection()
        {
            // arrange
            var dummy = await _persistence.CreateAsync(null, _dummy1);

            var projection = ProjectionParams.FromValues("inner_dummy.description", "content", "key", "create_time_utc", "dummy_type");

            // act
            dynamic result = await _persistence.GetOneByIdAsync(null, dummy.Id, projection);

            // assert
            Assert.NotNull(result);
            Assert.Equal(dummy.Key, result.key);
            Assert.Equal(dummy.Content, result.content);
            Assert.Equal(dummy.InnerDummy.Description, result.inner_dummy.description);
            Assert.Equal(dummy.CreateTimeUtc.ToString(), result.create_time_utc.ToString());
            Assert.Equal(dummy.DummyType.ToString(), result.dummy_type.ToString());
        }
Esempio n. 17
0
        public async Task TestGetPageByWrongProjection()
        {
            // arrange
            var dummy1 = await _persistence.CreateAsync(null, _dummy1);

            var dummy2 = await _persistence.CreateAsync(null, _dummy2);

            var builder = Builders <Dummy> .Filter;
            var filter  = builder.Empty;

            var projection = ProjectionParams.FromValues("Wrong_InnerDummy.Description", "Wrong_Content", "Wrong_Key");

            // act
            dynamic result = await _persistence.GetPageByFilterAndProjectionAsync(null, filter, null, null, projection);

            // assert
            Assert.NotNull(result);
            Assert.Empty(result.Data);
        }
 protected static ProjectionParams GetProjectionParams(HttpRequest request)
 {
     return(ProjectionParams.FromValues(HttpRequestHelper.ExtractFromQuery("projection", request)));
 }