Ejemplo n.º 1
0
        public void EquipItems_EquipZeroItems_ShouldSucceedButdoNothing()
        {
            IConfiguration            config         = Mock.Of <IConfiguration>(m => m["Bungie:ApiKey"] == "dummy-api-key");
            int                       membershipType = 3;
            long                      characterId    = 2305843009504575107;
            Uri                       uri            = new Uri($"https://www.bungie.net/Platform/Destiny2/Actions/Items/EquipItems/");
            string                    responseString = TestUtils.ReadFile("EquipItems-zero-items.json");
            Mock <HttpMessageHandler> mock           = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            mock
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.Is <HttpRequestMessage>(
                    req =>
                    req.Method == HttpMethod.Post &&
                    req.RequestUri == uri &&
                    req.Headers.Any(h => h.Key == "X-API-KEY" && !string.IsNullOrEmpty(h.Value.FirstOrDefault()) &&
                                    req.Headers.Any(h => h.Key == "Authorization" && !string.IsNullOrWhiteSpace(h.Value.FirstOrDefault())) &&
                                    req.Content.Headers.Any(h => h.Key == "Content-Type" && h.Value.FirstOrDefault().Contains("application/json")))),
                ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(responseString)
            })
            .Verifiable();
            HttpClient         httpClient       = new HttpClient(mock.Object);
            BungieApiService   bungieApiService = new BungieApiService(config, httpClient);
            EquipItemsRequest  request          = new EquipItemsRequest("access.token", membershipType, characterId, new long[] { });
            EquipItemsResponse actual           = bungieApiService.EquipItems(request);

            Assert.AreEqual(0, actual.EquipResults.Count);
        }
Ejemplo n.º 2
0
        public void EquipItems_JustOneItem_ShouldChangeCorrespondingItem()
        {
            IConfiguration config = Mock.Of <IConfiguration>(m => m["Bungie:ApiKey"] == "dummy-api-key");
            // for example, if i tell it to equip the recluse, it should change whatever was
            // in my energy weapon slot before this. since this is all just item hashes and ids,
            // this is just something that i figured out manually for the test.

            // uint recluseItemHash = 3354242550;
            long recluseItemInstanceId = 6917529123204409619;
            // uint suddenDeathItemHash = 1879212552;
            // long suddenDeathItemInstanceId = 6917529043814140192;

            int    membershipType          = 3;
            long   characterId             = 2305843009504575107;
            Uri    uri                     = new Uri($"https://www.bungie.net/Platform/Destiny2/Actions/Items/EquipItems/");
            string responseString          = TestUtils.ReadFile("EquipItems-equip-recluse-success.json");
            Mock <HttpMessageHandler> mock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            mock
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.Is <HttpRequestMessage>(
                    req =>
                    req.Method == HttpMethod.Post &&
                    req.RequestUri == uri &&
                    req.Headers.Any(h => h.Key == "X-API-KEY" && !string.IsNullOrEmpty(h.Value.FirstOrDefault()) &&
                                    req.Headers.Any(h => h.Key == "Authorization" && !string.IsNullOrWhiteSpace(h.Value.FirstOrDefault())) &&
                                    req.Content.Headers.Any(h => h.Key == "Content-Type" && h.Value.FirstOrDefault().Contains("application/json")))),
                ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(responseString)
            })
            .Verifiable();
            HttpClient         httpClient       = new HttpClient(mock.Object);
            BungieApiService   bungieApiService = new BungieApiService(config, httpClient);
            EquipItemsRequest  request          = new EquipItemsRequest("access.token", membershipType, characterId, new long[] { recluseItemInstanceId });
            EquipItemsResponse actual           = bungieApiService.EquipItems(request);

            Assert.AreEqual(1, actual.EquipResults.Count);
            Assert.AreEqual(BungiePlatformErrorCodes.Success, actual.EquipResults[0].EquipStatus);
        }
Ejemplo n.º 3
0
        public void EquipItems_SomeInvalidItemInstanceIDs_ShouldSuccessfullyEquipItemsAndReturnErrorStatusForInvalidItem()
        {
            IConfiguration config = Mock.Of <IConfiguration>(m => m["Bungie:ApiKey"] == "dummy-api-key");
            long           invalidItemInstanceId = 69;
            long           recluseItemInstanceId = 6917529123204409619;

            int    membershipType          = 3;
            long   characterId             = 2305843009504575107;
            Uri    uri                     = new Uri($"https://www.bungie.net/Platform/Destiny2/Actions/Items/EquipItems/");
            string responseString          = TestUtils.ReadFile("EquipItems-some-invalid-items.json");
            Mock <HttpMessageHandler> mock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            mock
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.Is <HttpRequestMessage>(
                    req =>
                    req.Method == HttpMethod.Post &&
                    req.RequestUri == uri &&
                    req.Headers.Any(h => h.Key == "X-API-KEY" && !string.IsNullOrEmpty(h.Value.FirstOrDefault()) &&
                                    req.Headers.Any(h => h.Key == "Authorization" && !string.IsNullOrWhiteSpace(h.Value.FirstOrDefault())) &&
                                    req.Content.Headers.Any(h => h.Key == "Content-Type" && h.Value.FirstOrDefault().Contains("application/json")))),
                ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(responseString)
            })
            .Verifiable();
            HttpClient       httpClient       = new HttpClient(mock.Object);
            BungieApiService bungieApiService = new BungieApiService(config, httpClient);

            long[]             itemsToEquip = new long[] { invalidItemInstanceId, recluseItemInstanceId };
            EquipItemsRequest  request      = new EquipItemsRequest("access.token", membershipType, characterId, itemsToEquip);
            EquipItemsResponse actual       = bungieApiService.EquipItems(request);

            Assert.AreEqual(2, actual.EquipResults.Count);
            Assert.AreEqual(69, actual.EquipResults[0].ItemInstanceId);
            Assert.AreEqual(BungiePlatformErrorCodes.DestinyItemNotFound, actual.EquipResults[0].EquipStatus);
            Assert.AreEqual(recluseItemInstanceId, actual.EquipResults[1].ItemInstanceId);
            Assert.AreEqual(BungiePlatformErrorCodes.Success, actual.EquipResults[1].EquipStatus);
        }
Ejemplo n.º 4
0
        public void EquipItems_AccessTokenInvalidExpired_ShouldThrowApiExceptionUnauthorized()
        {
            IConfiguration            config = Mock.Of <IConfiguration>(m => m["Bungie:ApiKey"] == "dummy-api-key");
            long                      recluseItemInstanceId = 6917529123204409619;
            int                       membershipType        = 3;
            long                      characterId           = 2305843009504575107;
            Uri                       uri            = new Uri($"https://www.bungie.net/Platform/Destiny2/Actions/Items/EquipItems/");
            string                    responseString = TestUtils.ReadFile("EquipItems-invalid-unauthorized.html");
            Mock <HttpMessageHandler> mock           = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            mock
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.Is <HttpRequestMessage>(
                    req =>
                    req.Method == HttpMethod.Post &&
                    req.RequestUri == uri &&
                    req.Headers.Any(h => h.Key == "X-API-KEY" && !string.IsNullOrEmpty(h.Value.FirstOrDefault()) &&
                                    req.Headers.Any(h => h.Key == "Authorization" && !string.IsNullOrWhiteSpace(h.Value.FirstOrDefault())) &&
                                    req.Content.Headers.Any(h => h.Key == "Content-Type" && h.Value.FirstOrDefault().Contains("application/json")))),
                ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.Unauthorized,
                Content    = new StringContent(responseString)
            })
            .Verifiable();
            HttpClient       httpClient       = new HttpClient(mock.Object);
            BungieApiService bungieApiService = new BungieApiService(config, httpClient);

            long[]             itemsToEquip = new long[] { recluseItemInstanceId };
            EquipItemsRequest  request      = new EquipItemsRequest("access.token", membershipType, characterId, itemsToEquip);
            BungieApiException exception    = Assert.ThrowsException <BungieApiException>(() => bungieApiService.EquipItems(request));

            Assert.IsTrue(exception.Message.Contains("Unauthorized"));
        }
Ejemplo n.º 5
0
        public void EquipItems_EquipEveryInventoryItem_AllShouldSucceed()
        {
            IConfiguration config = Mock.Of <IConfiguration>(m => m["Bungie:ApiKey"] == "dummy-api-key");
            // item instance IDs
            long perfectParadox         = 6917529138356180356;
            long suddenDeath            = 6917529043814140192;
            long apexPredator           = 6917529137866710642;
            long maskOfRull             = 6917529110566559001;
            long reverieDawnGauntlets   = 6917529138010460936;
            long plateOfTranscendence   = 6917529109687230597;
            long peacekeepers           = 6917529122999918127;
            long markOfTheGreatHunt     = 6917529128966008940;
            long starMapShell           = 6917529134911753611;
            long soloStandSparrow       = 6917529096117947574;
            long safePassageShip        = 6917529128292261186;
            long sentinelSubclass       = 6917529102011422104;
            long clanBanner             = 6917529137830892799;
            long prismaticInfernoEmblem = 6917529105645094388;
            long finisher        = 6917529137848551327;
            long emote           = 6917529101999517414;
            long lanternOfOsiris = 6917529137968184629;

            int    membershipType          = 3;
            long   characterId             = 2305843009504575107;
            Uri    uri                     = new Uri($"https://www.bungie.net/Platform/Destiny2/Actions/Items/EquipItems/");
            string responseString          = TestUtils.ReadFile("EquipItems-equip-all.json");
            Mock <HttpMessageHandler> mock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            mock
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.Is <HttpRequestMessage>(
                    req =>
                    req.Method == HttpMethod.Post &&
                    req.RequestUri == uri &&
                    req.Headers.Any(h => h.Key == "X-API-KEY" && !string.IsNullOrEmpty(h.Value.FirstOrDefault()) &&
                                    req.Headers.Any(h => h.Key == "Authorization" && !string.IsNullOrWhiteSpace(h.Value.FirstOrDefault())) &&
                                    req.Content.Headers.Any(h => h.Key == "Content-Type" && h.Value.FirstOrDefault().Contains("application/json")))),
                ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(responseString)
            })
            .Verifiable();
            HttpClient       httpClient       = new HttpClient(mock.Object);
            BungieApiService bungieApiService = new BungieApiService(config, httpClient);

            long[] itemsToEquip = new long[] {
                perfectParadox,
                suddenDeath,
                apexPredator,
                maskOfRull,
                reverieDawnGauntlets,
                plateOfTranscendence,
                peacekeepers,
                markOfTheGreatHunt,
                starMapShell,
                soloStandSparrow,
                safePassageShip,
                sentinelSubclass,
                clanBanner,
                prismaticInfernoEmblem,
                finisher,
                emote,
                lanternOfOsiris
            };
            EquipItemsRequest  request = new EquipItemsRequest("access.token", membershipType, characterId, itemsToEquip);
            EquipItemsResponse actual  = bungieApiService.EquipItems(request);

            Assert.AreEqual(17, actual.EquipResults.Count);
            Assert.IsTrue(actual.EquipResults.All(r => r.EquipStatus == BungiePlatformErrorCodes.Success));
        }