Ejemplo n.º 1
0
        public async Task GetDictionariesByNames_filterbyKey_multipleDictionaries()
        {
            // Arrange
            var dictionaryIds      = new[] { Guid.NewGuid(), Guid.NewGuid() };
            var abstractTypeId     = Guid.NewGuid();
            var dictionaryEntryIds = new Guid[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };//entries0[0], entries0[1], entries0 parent, //entries1[0], entries1[1], entries1 parent,
            var dictionaryNames    = new[] { "TestingDictionary1", "TestingDictionary2" };
            var parentKey          = "ParentElement";
            //resulting dictionary
            var entries0 = new DictionaryEntry[]
            {
                new DictionaryEntry()//match
                {
                    Id           = dictionaryEntryIds[0],
                    DictionaryId = dictionaryIds[0],
                    Key          = "element0",
                    Value        = "element0",
                    Visible      = true,
                },
                new DictionaryEntry()//match
                {
                    Id           = dictionaryEntryIds[1],
                    DictionaryId = dictionaryIds[0],
                    Key          = "element1",
                    Value        = "element1",
                    Visible      = true,
                },
                new DictionaryEntry()//not a match
                {
                    Id           = Guid.NewGuid(),
                    DictionaryId = dictionaryIds[0],
                    Key          = "element2",
                    Value        = "element2",
                    Visible      = true,
                },
            };
            var entries1 = new DictionaryEntry[]
            {
                new DictionaryEntry()//match
                {
                    Id           = dictionaryEntryIds[3],
                    DictionaryId = dictionaryIds[1],
                    Key          = "element0",
                    Value        = "element0",
                    Visible      = true,
                },
                new DictionaryEntry()//not a match
                {
                    Id           = dictionaryEntryIds[4],
                    DictionaryId = dictionaryIds[1],
                    Key          = "element1",
                    Value        = "element1",
                    Visible      = true,
                },
                new DictionaryEntry()//not a match
                {
                    Id           = Guid.NewGuid(),
                    DictionaryId = dictionaryIds[1],
                    Key          = "element2",
                    Value        = "element2",
                    Visible      = true,
                },
            };

            //parent dictionary entry
            _efContextMock.MockAsyncQueryable(new[] {
                new Dictionary()
                {
                    Id                = dictionaryIds[0],
                    AbstractTypeId    = abstractTypeId,
                    Name              = dictionaryNames[0],
                    DictionaryEntries = entries0.ToList(),
                },
                new Dictionary()
                {
                    Id                = dictionaryIds[1],
                    AbstractTypeId    = abstractTypeId,
                    Name              = dictionaryNames[1],
                    DictionaryEntries = entries1.ToList(),
                },
            }.AsQueryable(), context => context.Dictionary);
            _efContextMock.MockAsyncQueryable(new[]
            {
                entries0[0],
                entries0[1],
                entries0[2],
                entries1[0],
                entries1[1],
                entries1[2],
                new DictionaryEntry()
                {
                    Id    = dictionaryEntryIds[2],
                    Key   = parentKey,
                    Value = parentKey,
                },
                new DictionaryEntry()
                {
                    Id    = dictionaryEntryIds[5],
                    Key   = parentKey,
                    Value = parentKey,
                },
            }.AsQueryable(), context => context.DictionaryEntry);
            //relations
            _efContextMock.MockAsyncQueryable(new DependentItem[]
            {
                new DependentItem()
                {
                    ChildId  = dictionaryEntryIds[0],
                    ParentId = dictionaryEntryIds[2],
                },
                new DependentItem()
                {
                    ChildId  = dictionaryEntryIds[1],
                    ParentId = dictionaryEntryIds[2],
                },
                new DependentItem()
                {
                    ChildId  = dictionaryEntryIds[4],
                    ParentId = dictionaryEntryIds[5],
                },
            }.AsQueryable(), context => context.DependentItem);

            // Act
            var result = await _dictionaryServiceMock.GetDictionariesByNames(abstractTypeId, dictionaryNames, parentKey, true);

            // Assert
            Assert.Multiple(() =>
            {
                result.Should().HaveCount(2);
                result[0].DictionaryEntries.Should().HaveCount(2);
                result[1].DictionaryEntries.Should().HaveCount(1);
            });
        }
Ejemplo n.º 2
0
        public async Task SearchDictionaries_filterByKey()
        {
            // Arrange
            var dictionaryId       = Guid.NewGuid();
            var abstractTypeId     = Guid.NewGuid();
            var dictionaryEntryIds = new Guid[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
            var dictionaryName     = "TestingDictionary_qwerty_abcd";
            var nameToSearch       = "qwerty";
            var parentKey          = "ParentElement";
            //resulting dictionary
            var entries = new DictionaryEntry[]
            {
                new DictionaryEntry()//match
                {
                    Id           = dictionaryEntryIds[0],
                    DictionaryId = dictionaryId,
                    Key          = "element0",
                    Value        = "element0",
                    Visible      = true,
                },
                new DictionaryEntry()//match
                {
                    Id           = dictionaryEntryIds[1],
                    DictionaryId = dictionaryId,
                    Key          = "element1",
                    Value        = "element1",
                    Visible      = true,
                },
                new DictionaryEntry()//not a match
                {
                    Id           = Guid.NewGuid(),
                    DictionaryId = dictionaryId,
                    Key          = "element2",
                    Value        = "element2",
                    Visible      = true,
                },
            };

            //parent dictionary entry
            _efContextMock.MockAsyncQueryable(new[] {
                new Dictionary()
                {
                    Id                = dictionaryId,
                    AbstractTypeId    = abstractTypeId,
                    Name              = dictionaryName,
                    DictionaryEntries = entries.ToList(),
                }
            }.AsQueryable(), context => context.Dictionary);
            _efContextMock.MockAsyncQueryable(new[]
            {
                entries[0],
                entries[1],
                entries[2],
                new DictionaryEntry()
                {
                    Id    = dictionaryEntryIds[2],
                    Key   = parentKey,
                    Value = parentKey,
                }
            }.AsQueryable(), context => context.DictionaryEntry);
            //relations
            _efContextMock.MockAsyncQueryable(new DependentItem[]
            {
                new DependentItem()
                {
                    ChildId  = dictionaryEntryIds[0],
                    ParentId = dictionaryEntryIds[2],
                },
                new DependentItem()
                {
                    ChildId  = dictionaryEntryIds[1],
                    ParentId = dictionaryEntryIds[2],
                },
            }.AsQueryable(), context => context.DependentItem);

            // Act
            var result = await _dictionaryServiceMock.SearchDictionaries(abstractTypeId, nameToSearch, parentKey);

            // Assert
            Assert.Multiple(() =>
            {
                result.Should().HaveCount(1);
                result[0].DictionaryEntries.Should().HaveCount(2);
            });
        }