public void DocumentStreamHandlesNullFiltersCorrectly()
        {
            // ARRANGE
            CollectionConfigurationError[] errors;
            var documentStreamInfo = new DocumentStreamInfo()
            {
                DocumentFilterGroups = null
            };
            var documentStream = new DocumentStream(documentStreamInfo, out errors, new ClockMock());
            var request        = new RequestTelemetry()
            {
                Id = "apple"
            };

            // ACT
            CollectionConfigurationError[] runtimeErrors;
            bool result = documentStream.CheckFilters(request, out runtimeErrors);

            // ASSERT
            Assert.AreEqual(0, errors.Length);
            Assert.AreEqual(0, runtimeErrors.Length);

            Assert.IsFalse(result);
        }
        public void DocumentStreamFiltersRequestsCorrectly()
        {
            // ARRANGE
            CollectionConfigurationError[] errors;
            FilterInfo filterApple = new FilterInfo {
                FieldName = "Id", Predicate = Predicate.Contains, Comparand = "apple"
            };
            FilterInfo filterOrange = new FilterInfo {
                FieldName = "Id", Predicate = Predicate.Contains, Comparand = "orange"
            };
            FilterInfo filterMango = new FilterInfo {
                FieldName = "Id", Predicate = Predicate.Contains, Comparand = "mango"
            };

            // (apple AND orange) OR mango
            var documentStreamInfo = new DocumentStreamInfo()
            {
                DocumentFilterGroups =
                    new[]
                {
                    new DocumentFilterConjunctionGroupInfo()
                    {
                        TelemetryType = TelemetryType.Request,
                        Filters       = new FilterConjunctionGroupInfo {
                            Filters = new[] { filterApple, filterOrange }
                        }
                    },
                    new DocumentFilterConjunctionGroupInfo()
                    {
                        TelemetryType = TelemetryType.Request,
                        Filters       = new FilterConjunctionGroupInfo {
                            Filters = new[] { filterMango }
                        }
                    }
                }
            };
            var documentStream = new DocumentStream(documentStreamInfo, out errors, new ClockMock());
            var requests       = new[]
            {
                new RequestTelemetry()
                {
                    Id = "apple"
                }, new RequestTelemetry()
                {
                    Id = "orange"
                }, new RequestTelemetry()
                {
                    Id = "mango"
                },
                new RequestTelemetry()
                {
                    Id = "apple orange"
                }, new RequestTelemetry()
                {
                    Id = "apple mango"
                },
                new RequestTelemetry()
                {
                    Id = "orange mango"
                }, new RequestTelemetry()
                {
                    Id = "apple orange mango"
                },
                new RequestTelemetry()
                {
                    Id = "none of the above"
                }
            };

            // ACT
            var  results           = new bool[requests.Length];
            bool errorsEncountered = false;

            for (int i = 0; i < requests.Length; i++)
            {
                CollectionConfigurationError[] runtimeErrors;
                results[i] = documentStream.CheckFilters(requests[i], out runtimeErrors);
                if (runtimeErrors.Any())
                {
                    errorsEncountered = true;
                }
            }

            // ASSERT
            Assert.AreEqual(0, errors.Length);

            Assert.IsFalse(errorsEncountered);

            Assert.IsFalse(results[0]);
            Assert.IsFalse(results[1]);
            Assert.IsTrue(results[2]);
            Assert.IsTrue(results[3]);
            Assert.IsTrue(results[4]);
            Assert.IsTrue(results[5]);
            Assert.IsTrue(results[6]);
            Assert.IsFalse(results[7]);
        }