예제 #1
0
        /// <summary>
        /// Maps a collection of set DTO objects to the set model.
        /// </summary>
        /// <param name="setListDto">The list of sets DTO objects.</param>
        /// <returns>A list of set models.</returns>
        public static List <Set> MapSetsList(RootSetListDto setListDto)
        {
            if (setListDto == null)
            {
                throw new ArgumentNullException(nameof(setListDto));
            }

            if (setListDto.Sets == null)
            {
                return(null);
            }

            return(setListDto.Sets
                   .Select(x => new Set(x))
                   .ToList());
        }
예제 #2
0
        private List <ISet> MapSetsList(RootSetListDto setListDto)
        {
            if (setListDto == null)
            {
                throw new ArgumentNullException(nameof(setListDto));
            }

            if (setListDto.Sets == null)
            {
                return(new List <ISet>());
            }

            return(setListDto.Sets
                   .Select(x => ModelMapper.MapSet(x))
                   .ToList());
        }
예제 #3
0
        public async Task AllAsync_Success()
        {
            // arrange
            const string SET_NAME = "setname1";

            _mockRateLimit.Setup(x => x.IsTurnedOn).Returns(false);

            _mockHeaderManager.Setup(x => x.Update(It.IsAny <IReadOnlyNameValueList <string> >()));
            _mockHeaderManager.Setup(x => x.Get <int>(ResponseHeader.TotalCount)).Returns(2000);
            _mockHeaderManager.Setup(x => x.Get <int>(ResponseHeader.PageSize)).Returns(1000);

            var setDto = new SetDto()
            {
                Name = SET_NAME
            };
            var rootSetList = new RootSetListDto()
            {
                Sets = new List <SetDto> {
                    setDto
                },
            };

            _mockModelMapper.Setup(x => x.MapSet(It.IsAny <SetDto>())).Returns(new Set()
            {
                Name = SET_NAME
            });

            using var httpTest = new HttpTest();
            httpTest.RespondWithJson(rootSetList);

            var service = new SetService(
                _mockHeaderManager.Object,
                _mockModelMapper.Object,
                ApiVersion.V1,
                _mockRateLimit.Object);

            // act
            var result = await service.AllAsync();

            // assert
            Assert.True(result.IsSuccess);
            _mockRepository.VerifyAll();
        }
예제 #4
0
        public async Task Where_AddsQueryParameters_Success()
        {
            const string NAME  = "name1";
            const string BLOCK = "12345";

            _mockRateLimit.Setup(x => x.IsTurnedOn).Returns(false);

            _mockHeaderManager.Setup(x => x.Update(It.IsAny <IReadOnlyNameValueList <string> >()));
            _mockHeaderManager.Setup(x => x.Get <int>(ResponseHeader.TotalCount)).Returns(2000);
            _mockHeaderManager.Setup(x => x.Get <int>(ResponseHeader.PageSize)).Returns(1000);

            var rootSetList = new RootSetListDto()
            {
                Sets = new List <SetDto> {
                    new SetDto()
                },
            };

            using var httpTest = new HttpTest();
            httpTest.RespondWithJson(rootSetList);

            _mockModelMapper.Setup(x => x.MapSet(It.IsAny <SetDto>())).Returns(new Set());

            var service = new SetService(
                _mockHeaderManager.Object,
                _mockModelMapper.Object,
                ApiVersion.V1,
                _mockRateLimit.Object);

            // act
            service
            .Where(x => x.Name, NAME)
            .Where(x => x.Block, BLOCK);

            // assert
            await service.AllAsync();

            httpTest
            .ShouldHaveCalled("https://api.magicthegathering.io/v1/sets*")
            .WithQueryParams("name", "block");
        }
예제 #5
0
        public void MapSetsListTest()
        {
            PrivateType privateObject = new PrivateType(typeof(SetService));

            try
            {
                // Test sending a null parameter.
                privateObject.InvokeStatic("MapSetsList", new object[] { null });
                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("setListDto", ex.ParamName);
            }
            catch
            {
                Assert.Fail();
            }

            // Test a null sets collection inside the RootSetsListDto object.
            var setListDto = new RootSetListDto();

            Assert.IsNull(privateObject.InvokeStatic("MapSetsList", new object[] { setListDto }));

            setListDto = new RootSetListDto()
            {
                Sets = new List <SetDto>()
                {
                    new SetDto()
                    {
                        Block   = "block1",
                        Booster = new object[2]
                        {
                            new JValue("booster1"),
                            new JArray()
                            {
                                new JValue("booster2"),
                                new JValue("booster3"),
                                new JArray()
                                {
                                    new JValue("booster4"),
                                    new JValue("booster5")
                                }
                            }
                        },
                        Border             = "border1",
                        Code               = "code1",
                        Expansion          = "expansion1",
                        GathererCode       = "gathererCode1",
                        MagicCardsInfoCode = "magicCardsInfoCode1",
                        Name               = "name1",
                        OldCode            = "oldCode1",
                        OnlineOnly         = true,
                        ReleaseDate        = "2016, 1, 1"
                    },
                    new SetDto()
                    {
                        Block   = "block2",
                        Booster = new object[2]
                        {
                            new JValue("booster1"),
                            new JArray()
                            {
                                new JValue("booster2"),
                                new JValue("booster3"),
                                new JArray()
                                {
                                    new JValue("booster4"),
                                    new JValue("booster5")
                                }
                            }
                        },
                        Border             = "border2",
                        Code               = "code2",
                        Expansion          = "expansion2",
                        GathererCode       = "gathererCode2",
                        MagicCardsInfoCode = "magicCardsInfoCode2",
                        Name               = "name2",
                        OldCode            = "oldCode2",
                        OnlineOnly         = true,
                        ReleaseDate        = "2016, 2, 2"
                    }
                }
            };

            var result = privateObject.InvokeStatic("MapSetsList", new object[] { setListDto }) as List <Set>;

            Assert.AreEqual(2, result.Count);
        }