コード例 #1
0
        public async Task <DefaultResult <List <CharacterResponse> > > GetAsync(CharacterRequestFilter filters)
        {
            var defaultResult = new DefaultResult <List <CharacterResponse> >();
            var baseFilter    = filters.GetFilterDefinition();

            defaultResult.SetData((await _characterRepository.GetAsync(baseFilter)).Select(x => (CharacterResponse)x).ToList());
            return(defaultResult);
        }
コード例 #2
0
        public async Task CharacterService_Get(CharacterRequestFilter filters)
        {
            #region LoadData
            var character1 = new Character(
                "id1",
                "name1",
                null,
                null,
                new House("id1", "name1", "mascot", "hof", "hog", "founder"),
                null,
                new System.DateTime(),
                new System.DateTime()
                );
            var character2 = new Character(
                "id2",
                "name2",
                "role",
                "school",
                new House("id2", "name2", "mascot", "hof", "hog", "founder"),
                null,
                new System.DateTime(),
                new System.DateTime()
                );
            var character3 = new Character(
                "id3",
                "name3",
                "role",
                "school",
                null,
                null,
                new System.DateTime(),
                new System.DateTime()
                );
            var character4 = new Character(
                "id4",
                "name4",
                null,
                "school",
                null,
                null,
                new System.DateTime(),
                new System.DateTime()
                );
            List <Character> characterList = new List <Character>()
            {
                character1, character2, character3, character4
            };

            var filterDefinition = filters.GetFilterDefinition();
            _characterRepositoryMock
            .Setup(x => x.GetAsync(filterDefinition, It.IsAny <System.Threading.CancellationToken>()))
            .Returns(Task.FromResult((IEnumerable <Character>)characterList));
            #endregion

            var getResult = await _characterService.GetAsync(filters);

            if (!string.IsNullOrEmpty(filters.Id))
            {
                characterList = characterList.Where(x => x.Id == filters.Id).ToList();
            }

            if (!string.IsNullOrEmpty(filters.Name))
            {
                characterList = characterList.Where(x => x.Name == filters.Name).ToList();
            }

            if (!string.IsNullOrEmpty(filters.Role))
            {
                characterList = characterList.Where(x => x.Role == filters.Role).ToList();
            }

            if (!string.IsNullOrEmpty(filters.School))
            {
                characterList = characterList.Where(x => x.School == filters.School).ToList();
            }

            if (!string.IsNullOrEmpty(filters.House))
            {
                characterList = characterList.Where(x => x.House != null && x.House.Id == filters.House).ToList();
            }

            if (!string.IsNullOrEmpty(filters.Patronus))
            {
                characterList = characterList.Where(x => x.Patronus == filters.Patronus).ToList();
            }

            Assert.True(getResult.Success);
            Assert.Equal(characterList.Count(), getResult.Data.Count());
        }