Ejemplo n.º 1
0
        public void GetCharacterEquipment_InvalidMembershipId_ShouldThrowApiExceptionAccountNotFound()
        {
            IConfiguration config = Mock.Of <IConfiguration>(m => m["Bungie:ApiKey"] == "dummy-api-key");
            // assemble
            int    membershipType          = 3;
            long   membershipId            = 69;
            long   characterId             = 2305843009504575107;
            Uri    uri                     = new Uri($"https://www.bungie.net/Platform/Destiny2/{membershipType}/Profile/{membershipId}/Character/{characterId}/?components=205");
            string responseString          = TestUtils.ReadFile("GetCharacterEquipment-invalid-membership-id.json");
            Mock <HttpMessageHandler> mock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            mock
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.Is <HttpRequestMessage>(
                    req =>
                    req.Method == HttpMethod.Get &&
                    req.RequestUri == uri &&
                    req.Headers.Any(h => h.Key == "X-API-KEY" && !string.IsNullOrEmpty(h.Value.FirstOrDefault()))),
                ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.InternalServerError,
                Content    = new StringContent(responseString)
            })
            .Verifiable();
            HttpClient                httpClient       = new HttpClient(mock.Object);
            BungieApiService          bungieApiService = new BungieApiService(config, httpClient);
            CharacterEquipmentRequest request          = new CharacterEquipmentRequest(membershipType, membershipId, characterId);
            // act (and assert)
            var exception = Assert.ThrowsException <BungieApiException>(() => bungieApiService.GetCharacterEquipment(request));

            Assert.IsTrue(exception.Message.Contains("We couldn't find the account you're looking for"));
        }
Ejemplo n.º 2
0
        public void GetCharacterEquipment_Personal_ShouldReturnEquippedGear()
        {
            IConfiguration config = Mock.Of <IConfiguration>(m => m["Bungie:ApiKey"] == "dummy-api-key");
            // assemble
            int    membershipType          = 3;
            long   membershipId            = 4611686018467260757;
            long   characterId             = 2305843009504575107;
            Uri    uri                     = new Uri($"https://www.bungie.net/Platform/Destiny2/{membershipType}/Profile/{membershipId}/Character/{characterId}/?components=205");
            string responseString          = TestUtils.ReadFile("GetCharacterEquipment-valid-personal.json");
            Mock <HttpMessageHandler> mock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            mock
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.Is <HttpRequestMessage>(
                    req =>
                    req.Method == HttpMethod.Get &&
                    req.RequestUri == uri &&
                    req.Headers.Any(h => h.Key == "X-API-KEY" && !string.IsNullOrEmpty(h.Value.FirstOrDefault()))),
                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);
            CharacterEquipmentRequest request          = new CharacterEquipmentRequest(membershipType, membershipId, characterId);
            // act
            CharacterEquipmentResponse actual = bungieApiService.GetCharacterEquipment(request);

            // assert
            Assert.AreEqual(17, actual.Items.Count);
            Assert.IsTrue(actual.Items.All(item => item.ItemHash != 0 && item.ItemInstanceId != 0));
        }