예제 #1
0
        public void ShouldEncodeDate()
        {
            var filter = new MbedCloudSDK.Common.Filter.Filter();

            filter.Add("date", new DateTime(2017, 1, 1), FilterOperator.GreaterOrEqual);
            Assert.AreEqual("date__gte=2017-01-01T00:00:00.000Z", filter.FilterString);
        }
예제 #2
0
        public void ShouldDecodeWithCustomAttributes()
        {
            var filterString = "key=value&error__neq=found&range__lte=10&range__gte=2&custom_attribute__custom_1=custom_value_1&custom_attribute__custom_2__neq=custom_value_2";
            var filter       = new MbedCloudSDK.Common.Filter.Filter(filterString);

            Assert.AreEqual("key=value&error__neq=found&range__lte=10&range__gte=2&custom_attribute__custom_1=custom_value_1&custom_attribute__custom_2__neq=custom_value_2", filter.FilterString);
        }
예제 #3
0
        public void ShouldDecodeFilter()
        {
            var filterString = "key=value&error__neq=found&range__lte=10&range__gte=2";
            var filter       = new MbedCloudSDK.Common.Filter.Filter(filterString);

            Assert.AreEqual("key=value&error__neq=found&range__lte=10&range__gte=2", filter.FilterString);
        }
예제 #4
0
        public void ShouldEncodeFilterFromJsonWithCustomAttributes()
        {
            var filterString = "{\"key\": {\"$eq\": \"value\"}, \"error\": {\"$neq\": \"found\"}, \"range\": {\"$lte\": \"10\", \"$gte\": \"2\"}, \"custom_attributes\": {\"custom_1\": {\"$eq\": \"custom_value_1\"}, \"custom_2\": {\"$neq\": \"custom_value_2\"}}}";
            var filter       = new MbedCloudSDK.Common.Filter.Filter(filterString);

            Assert.AreEqual("key=value&error__neq=found&range__lte=10&range__gte=2&custom_attribute__custom_1=custom_value_1&custom_attribute__custom_2__neq=custom_value_2", filter.FilterString);
        }
예제 #5
0
        public void ShouldEncodeBareFilterFromJson()
        {
            var filterString = "{\"key\": \"value\", \"error\": {\"$neq\": \"found\"}, \"range\": {\"$lte\": \"10\", \"$gte\": \"2\"}}";
            var filter       = new MbedCloudSDK.Common.Filter.Filter(filterString);

            Assert.AreEqual("key=value&error__neq=found&range__lte=10&range__gte=2", filter.FilterString);
        }
예제 #6
0
        public void ShouldEncodeBareFilter()
        {
            var filter = new MbedCloudSDK.Common.Filter.Filter();

            filter.Add("key", "value");
            filter.Add("error", "found", FilterOperator.NotEqual);
            filter.Add("range", new FilterAttribute("10", FilterOperator.LessOrEqual), new FilterAttribute("2", FilterOperator.GreaterOrEqual));
            Assert.AreEqual("key=value&error__neq=found&range__lte=10&range__gte=2", filter.FilterString);
        }
예제 #7
0
        public void FilterReturnsCorrectJson()
        {
            var filter = new MbedCloudSDK.Common.Filter.Filter();

            filter.Add("key", "value", FilterOperator.Equals);
            filter.Add("error", "found", FilterOperator.NotEqual);
            filter.Add("range", new FilterAttribute("10", FilterOperator.LessOrEqual), new FilterAttribute("2", FilterOperator.GreaterOrEqual));
            Assert.AreEqual("{\"key\":{\"$eq\":\"value\"},\"error\":{\"$neq\":\"found\"},\"range\":{\"$lte\":\"10\",\"$gte\":\"2\"}}", filter.FilterJson.ToString(Formatting.None));
        }
예제 #8
0
        public void ContainsShouldReturnFalseIfKeyNotPresent()
        {
            var filter = new MbedCloudSDK.Common.Filter.Filter();

            filter.Add("key", "value", FilterOperator.Equals);
            var contains = filter.Contains("rubbish");

            Assert.IsFalse(contains);
        }
예제 #9
0
        public void ShouldEncodeFilterAfterAddingWithSameKey()
        {
            var filter = new MbedCloudSDK.Common.Filter.Filter();

            filter.Add("key", "value", FilterOperator.Equals);
            filter.Add("error", "found", FilterOperator.NotEqual);
            filter.Add("range", "10", FilterOperator.LessOrEqual);
            filter.Add("range", "2", FilterOperator.GreaterOrEqual);
            Assert.AreEqual("key=value&error__neq=found&range__lte=10&range__gte=2", filter.FilterString);
        }
예제 #10
0
        public void RemoveKeyNotPresentShouldLEaveFilterUnchanged()
        {
            var filter = new MbedCloudSDK.Common.Filter.Filter();

            filter.Add("key", "value", FilterOperator.Equals);
            filter.Add("error", "found", FilterOperator.NotEqual);
            filter.Add("range", new FilterAttribute("10", FilterOperator.LessOrEqual), new FilterAttribute("2", FilterOperator.GreaterOrEqual));
            filter.Remove("rubbish");
            Assert.AreEqual("key=value&error__neq=found&range__lte=10&range__gte=2", filter.FilterString);
        }
예제 #11
0
        public void RemoveShouldRemoveKeyFromFilter()
        {
            var filter = new MbedCloudSDK.Common.Filter.Filter();

            filter.Add("key", "value", FilterOperator.Equals);
            filter.Add("error", "found", FilterOperator.NotEqual);
            filter.Add("range", new FilterAttribute("10", FilterOperator.LessOrEqual), new FilterAttribute("2", FilterOperator.GreaterOrEqual));
            filter.Remove("range");
            Assert.AreEqual("key=value&error__neq=found", filter.FilterString);
        }
예제 #12
0
        public void ShouldEncodeFilterWithCustomAttributes()
        {
            var filter = new MbedCloudSDK.Common.Filter.Filter();

            filter.Add("key", "value", FilterOperator.Equals);
            filter.Add("error", "found", FilterOperator.NotEqual);
            filter.Add("range", new FilterAttribute("10", FilterOperator.LessOrEqual), new FilterAttribute("2", FilterOperator.GreaterOrEqual));
            filter.AddCustom("custom_1", new FilterAttribute("custom_value_1", FilterOperator.Equals));
            filter.AddCustom("custom_2", "custom_value_2", FilterOperator.NotEqual);
            Assert.AreEqual("key=value&error__neq=found&range__lte=10&range__gte=2&custom_attribute__custom_1=custom_value_1&custom_attribute__custom_2__neq=custom_value_2", filter.FilterString);
        }
예제 #13
0
        public void ShouldEncodeFilterWithMappedFields()
        {
            var filter = new MbedCloudSDK.Common.Filter.Filter();

            filter.Add(DeviceFilterMapEnum.Alias, "value", FilterOperator.Equals);
            filter.Add(DeviceFilterMapEnum.Alias, new FilterAttribute("wrong_value", FilterOperator.NotEqual));
            filter.Add(UpdateFilterMapEnum.FinishedAt, "found", FilterOperator.NotEqual);
            filter.Add(UpdateFilterMapEnum.FinishedAt, new FilterAttribute("not_found", FilterOperator.NotEqual));
            filter.Add("range", new FilterAttribute("10", FilterOperator.LessOrEqual), new FilterAttribute("2", FilterOperator.GreaterOrEqual));
            Assert.AreEqual("endpoint_name=value&endpoint_name__neq=wrong_value&finished__neq=found&finished__neq=not_found&range__lte=10&range__gte=2", filter.FilterString);
        }
예제 #14
0
        public void BlankFilterReturnsEmptyJson()
        {
            var filter = new MbedCloudSDK.Common.Filter.Filter();

            Assert.AreEqual(default(JObject), filter.FilterJson);
        }
예제 #15
0
        public void BlankFilterWithEmptyJsonReturnsEmptyString()
        {
            var filter = new MbedCloudSDK.Common.Filter.Filter("{}");

            Assert.AreEqual(string.Empty, filter.FilterString);
        }
예제 #16
0
        public void BlankFilterReturnsEmptyFilterString()
        {
            var filter = new MbedCloudSDK.Common.Filter.Filter();

            Assert.AreEqual(string.Empty, filter.FilterString);
        }