コード例 #1
0
        public void CacheShouldNotAddWithEmptyOrNullArguments(string mcc, string mnc)
        {
            var cache = new ConcurrentDiscoveryCache();

            cache.Add(mcc, mnc, new DiscoveryResponse(_responses[0]));

            Assert.IsTrue(cache.IsEmpty);
        }
コード例 #2
0
        public void ClearShouldClearStore()
        {
            var cache = new ConcurrentDiscoveryCache();

            cache.Add("001", "01", new DiscoveryResponse(_responses[0]));
            cache.Add("002", "02", new DiscoveryResponse(_responses[1]));
            cache.Clear();

            Assert.IsTrue(cache.IsEmpty);
        }
コード例 #3
0
        //[TestCase("r2-ref")]
        public async Task MobileConnectWebInterfaceShouldWorkEndToEndWithCache(string configKey)
        {
            RestClient      restClient     = new RestClient();
            IDiscoveryCache cache          = new ConcurrentDiscoveryCache();
            IDiscovery      discovery      = new GSMA.MobileConnect.Discovery.Discovery(cache, restClient);
            IAuthentication authentication = new GSMA.MobileConnect.Authentication.Authentication(restClient);

            var testConfig             = TestConfig.GetConfig(configKey);
            MobileConnectConfig config = new MobileConnectConfig()
            {
                DiscoveryUrl = testConfig.DiscoveryUrl,
                ClientId     = testConfig.ClientId,
                ClientSecret = testConfig.ClientSecret,
                RedirectUrl  = testConfig.RedirectUrl
            };

            MobileConnectRequestOptions blankOptions  = new MobileConnectRequestOptions();
            MobileConnectWebInterface   mobileConnect = new MobileConnectWebInterface(discovery, authentication, config);

            //Attempt discovery
            var request = new HttpRequestMessage();
            var status  = await mobileConnect.AttemptDiscoveryAsync(request, testConfig.ValidMSISDN, null, null, true, blankOptions);

            Assert.AreEqual(MobileConnectResponseType.StartAuthorization, status.ResponseType);

            var session         = status.SDKSession;
            var encryptedMsisdn = status.DiscoveryResponse.ResponseData.subscriber_id;
            var state           = "zmxncbvalskdjfhgqpwoeiruty";
            var nonce           = "qpwoeirutyalskdjfhgzmxncbv";

            //Start Authorization
            request = new HttpRequestMessage();
            status  = await mobileConnect.StartAuthorization(request, session, encryptedMsisdn, state, nonce, blankOptions);

            Assert.AreEqual(MobileConnectResponseType.Authorization, status.ResponseType);

            //Inconclusive at this point because the sandbox no longer allows us to follow redirects easily
            Assert.Inconclusive("Can't follow redirects in sandbox");

            //Authorization
            request = new HttpRequestMessage();
            var redirectedUrl = await FollowRedirects(status.Url, _basicRequestHeaders, testConfig.RedirectUrl);

            Assert.That(() => redirectedUrl.AbsoluteUri.StartsWith(testConfig.RedirectUrl));
            Assert.AreEqual(state, HttpUtils.ExtractQueryValue(redirectedUrl.Query, "state"));

            //Handle auth redirect and request token
            request = new HttpRequestMessage();
            status  = await mobileConnect.HandleUrlRedirectAsync(request, redirectedUrl, session, state, nonce);

            Assert.AreEqual(MobileConnectResponseType.Complete, status.ResponseType);
            Assert.IsNotEmpty(status.TokenResponse.ResponseData.AccessToken);
        }
コード例 #4
0
        public void RemoveShouldRemoveStoredResponse()
        {
            var cache = new ConcurrentDiscoveryCache();
            var mcc   = "001";
            var mnc   = "01";

            cache.Add(mcc, mnc, new DiscoveryResponse(_responses[0]));
            cache.Remove(mcc, mnc);
            var actual = cache.Get(mcc, mnc).Result;

            Assert.IsNull(actual);
        }
コード例 #5
0
        public void CacheShouldGetResponseWhenMultipleStored()
        {
            var cache    = new ConcurrentDiscoveryCache();
            var expected = new DiscoveryResponse(_responses[1]);
            var mcc      = "001";
            var mnc      = "01";

            cache.Add(mcc, mnc, expected);
            cache.Add("002", "02", new DiscoveryResponse(_responses[0]));
            var actual = cache.Get(mcc, mnc).Result;

            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.Cached);
            Assert.IsNotNull(actual.ResponseData.response.apis);
        }
コード例 #6
0
        public void AddShouldStoreDiscoveryResponse()
        {
            var cache    = new ConcurrentDiscoveryCache();
            var response = new DiscoveryResponse(_responses[0]);
            var mcc      = "001";
            var mnc      = "01";

            cache.Add(mcc, mnc, response);
            var actual = cache.Get(mcc, mnc).Result;

            Assert.IsFalse(cache.IsEmpty);
            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.Cached);
            Assert.AreEqual(response.ResponseData.response, actual.ResponseData.response);
        }
コード例 #7
0
        public void ConstructorShouldCreateEmptyCache()
        {
            var cache = new ConcurrentDiscoveryCache();

            Assert.IsTrue(cache.IsEmpty);
        }