Пример #1
0
        public void ShouldApplyFilterWorks()
        {
            // Arrange
            var conversationService = new ConversationService(agentService.Object, departmentService.Object, filterRepo.Object, filterExpressionFactory.Object, logRepo.Object);
            var rawConversations    = new List <Conversation>
            {
                new Conversation {
                    Id = 1, Subject = "Conversation Test 1"
                },
                new Conversation {
                    Id = 2, Subject = "test2"
                }
            }.AsQueryable();
            Filter filter = new Filter
            {
                Id         = 1,
                IfPublic   = true,
                Index      = 1,
                Type       = FilterType.All,
                Conditions = new List <FilterCondition>
                {
                    new FilterCondition {
                        FilterId = 1, MatchType = ConditionMatchType.Is, Value = "Conversation"
                    }
                }
            };

            filterExpressionFactory.Setup(t => t.Create(filter)).Returns(t => t.Subject.Contains("Conversation"));
            // Act
            var conversations = conversationService.ApplyFilter(rawConversations, filter).DefaultIfEmpty().ToList();

            // Assert
            Assert.Equal(1, conversations.Count());
        }