Esempio n. 1
0
        static void LoadSets(MTGToolboxContext context)
        {
            SetRepository setRepository = new SetRepository(context);

            SetService setService = new SetService();

            var setResults = setService.All();

            if (setResults.IsSuccess)
            {
                foreach (var item in setResults.Value)
                {
                    Set set = new Set();
                    set.Code = item.Code;
                    set.Name = item.Name;

                    setRepository.AddSet(set);
                }
                setRepository.Save();
            }
        }
        public void AllTest()
        {
            var 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("booster1"),
                            new JValue("booster2")
                        }
                    },
                    Border             = "border2",
                    Code               = "code2",
                    Expansion          = "expansion2",
                    GathererCode       = "gathererCode2",
                    MagicCardsInfoCode = "magicCardsInfoCode2",
                    Name               = "name2",
                    OldCode            = "oldCode2",
                    OnlineOnly         = true,
                    ReleaseDate        = "2016, 2, 2"
                }
            };

            // Test the All method.
            var moqAdapter = new Mock <IMtgApiServiceAdapter>();

            moqAdapter
            .SetupSequence(x => x.WebGetAsync <RootSetListDto>(It.IsAny <Uri>()))
            .Throws <ArgumentNullException>()
            .Throws(new MtgApiException <BadRequestException>("bad request"))
            .Throws(new MtgApiException <ForbiddenException>("forbidden"))
            .Throws(new MtgApiException <InternalServerErrorException>("server error"))
            .Throws(new MtgApiException <NotFoundException>("not found"))
            .Throws(new MtgApiException <ServiceUnavailableException>("unavailable"))
            .Throws <Exception>()
            .ReturnsAsync(new RootSetListDto()
            {
                Sets = sets
            });

            var service = new SetService(moqAdapter.Object, ApiVersion.V1_0, false);

            service = service.Where(x => x.Name, "name1");

            var result = service.All();

            Assert.False(result.IsSuccess);
            Assert.Equal("Value cannot be null.", result.Exception.Message);

            result = service.All();
            Assert.False(result.IsSuccess);
            Assert.Equal("bad request", result.Exception.Message);

            result = service.All();
            Assert.False(result.IsSuccess);
            Assert.Equal("forbidden", result.Exception.Message);

            result = service.All();
            Assert.False(result.IsSuccess);
            Assert.Equal("server error", result.Exception.Message);

            result = service.All();
            Assert.False(result.IsSuccess);
            Assert.Equal("not found", result.Exception.Message);

            result = service.All();
            Assert.False(result.IsSuccess);
            Assert.Equal("unavailable", result.Exception.Message);

            result = service.All();
            Assert.False(result.IsSuccess);
            Assert.IsType <Exception>(result.Exception);

            result = service.All();
            Assert.True(result.IsSuccess);
            Assert.Null(result.Exception);
            Assert.NotNull(result.Value);
        }