public void HasClientNugetPackagePushAuthorizationsReturnsNoErrorMessageAndAndCompliesSLA()
        {
            #region arrange
            int requestsQtty = 100;
            int expectedSLA  = requestsQtty / 2;
            int errorCount   = 0;
            var watch        = new Stopwatch();


            var theClient = HasClientFactory.CreateApiClient(GetClientSettings());
            var effectiveAuthorization = EffectiveAuthorizationFactory.Create(_tenantId);
            var timestamp = DateTime.Now;
            #endregion arrange

            #region act
            watch.Start();
            for (int i = 0; i < requestsQtty; i++)
            {
                var grantResponseGranted = theClient.PushEffectiveAuthorizationGrantedAsync(effectiveAuthorization, timestamp).Result;

                if (!grantResponseGranted.IsSuccess)
                {
                    errorCount++;
                }
            }
            watch.Stop();
            var seconds = watch.Elapsed.Seconds;
            #endregion act

            //assert
            Assert.AreEqual(0, errorCount, $"{errorCount} errors on {requestsQtty} requests");
            Assert.IsTrue(seconds < expectedSLA, "Average requests timing exceeds expected SLA");
        }
        public void Client_PushEffectiveAuthorizationGranted_Valid_Event_Returns_CreatedEvent_Id()
        {
            //arrange
            var theClient = HasClientFactory.CreateApiClient(GetClientSettings());
            var effectiveAuthorization = EffectiveAuthorizationFactory.Create(_tenantId);

            //act
            var grantResponseGranted = theClient.PushEffectiveAuthorizationGranted(effectiveAuthorization, DateTime.Now);

            Assert.AreEqual(true, grantResponseGranted.IsSuccess);
            Assert.AreEqual(true, Guid.TryParse(grantResponseGranted.Message, out Guid id));
        }
        public async Task Client_PushEffectiveAuthorizationGrantedAsynk_Unauthorized_Returns_ErrorMessage()
        {
            //arrange
            var settings = GetClientSettings(_endppoint, _clientId, "InvalidSecret", _authenticationUrl, _xClientIdHeader);

            var theClient = HasClientFactory.CreateApiClient(settings);
            var effectiveAuthorization = EffectiveAuthorizationFactory.Create(_tenantId);

            //act
            var eventResponse = await theClient.PushEffectiveAuthorizationGrantedAsync(effectiveAuthorization, DateTime.Now);

            Assert.AreEqual(false, eventResponse.IsSuccess);
            Assert.AreEqual("Authentication failed!. Please check provided Authority url and credentials", eventResponse.Message);
        }
 public void CreateApiClient_WrongFormat_Url_throws_UriFormatException()
 {
     Assert.ThrowsException <UriFormatException>(() => HasClientFactory.CreateApiClient(new HttpClientSettings(new Uri("123wrong/api"), _defaultClientId, _defaultClientSecret, new Uri("https://www.some-unexisting-url.com/as/token.oauth2"), "x-client-id-example")));
 }
        public void CreateApiClient_RightFormat_URL_Returns_IPushClient()
        {
            var client = HasClientFactory.CreateApiClient(new HttpClientSettings(new Uri("https://requestb.in/1ipzzzf1"), _defaultClientId, _defaultClientSecret, new Uri("https://www.some-unexisting-url.com/as/token.oauth2"), "x-client-id-example"));

            Assert.IsInstanceOfType(client, typeof(IPushClient));
        }