示例#1
0
 internal Client(IJsonClient json, string url, string name, Dictionary <string, string> data)
 {
     _json = json;
     _url  = url;
     Name  = name;
     Data  = data.ToImmutableDictionary();
 }
示例#2
0
        internal BaseClient(IJsonClient jsonClient, IErrorMessages errorMessages)
        {
            this.JsonClient    = jsonClient;
            this.ErrorMessages = errorMessages;

            this.UrlHelpers = new UrlHelpers();
        }
 public ProductionService()
 {
     _cache      = MemoryCache.Default;
     _jsonClient = new JsonClient(true)
     {
         BaseURL = "https://www.dr.dk/mu-online/api/1.4"
     };
 }
        /// <summary>
        /// Asynchronously processes a JSON message sent from a <see cref="IJsonClient"/>
        /// </summary>
        private async Task HandleJSONMessageAsync(IJsonClient client)
        {
            var message = await client.Receive();

            var destination = message.Value <string>("Destination");

            if (destination != null)
            {
            }
        }
 /// <summary>
 /// Runs an asynchronous JSON message loop for a <see cref="IJsonClient"/>
 /// </summary>
 public async Task HandleClient(IJsonClient client)
 {
     try
     {
         this.connections.TryAdd(client, 0);
         while (!client.IsClosed)
         {
             await this.HandleJSONMessageAsync(client);
         }
     }
     catch (Exception ex)
     {
         this.logger.LogError($"Exception in RPC message loop: {ex.Message}");
     }
     finally
     {
         byte b;
         this.connections.TryRemove(client, out b);
     }
 }
 private BankEntitiesService()
 {
     LocalEntityCache = new EntityCache (this);
     JsonClient = new JsonClientImpl ();
 }
示例#7
0
 public BaseResource(IJsonClient client, IMemoryCache <string> cache = null)
 {
     _cache = cache;
     Client = client;
 }
示例#8
0
 private IAuthenticationClient CreateClient(IJsonClient jsonClient)
 {
     return(new AuthenticationClient(jsonClient, this.ErrorMessages));
 }
示例#9
0
 public IdentityWs(HttpClient http)
 {
     _json = new HttpJsonClient(http);
 }
示例#10
0
 private ISearchClient CreateClient(IJsonClient jsonClient)
 {
     return(new SearchClient(jsonClient, this.ErrorMessages));
 }
示例#11
0
 internal IdentityWs(IJsonClient json)
 {
     _json = json;
 }
示例#12
0
 public StreamService(string baseUrl, IJsonClient jsonClient)
 {
     this.baseUrl = baseUrl;
     this.jsonClient = jsonClient;
 }
 private ILanguagesClient CreateClient(IJsonClient jsonClient)
 {
     return(new LanguagesClient(jsonClient, this.ErrorMessages));
 }
 private static VersionJson GetVersion(IJsonClient restClient, Uri appRoot)
 {
     return(restClient.Get <VersionJson>(
                $"{appRoot}__version.js",
                useDefaultCredentials: true));
 }
 public StreamController(string apiUrl, IJsonClient jsonClient, IStreamItemMapper mapper)
 {
     this.apiUrl     = apiUrl;
     this.jsonClient = jsonClient;
     this.mapper     = mapper;
 }
示例#16
0
        static void Main(string[] args)
        {
            // Prologue
            IJsonClient json = Setup(args);
            IdentityWs  ws   = new IdentityWs(json);

            // Alias creation/linking
            ws.GetAliasAsync("*****@*****.**").Result.Should().BeNull("the alias has not been created yet");
            Alias  alias1    = ws.CreateAliasAsync("*****@*****.**", "password1").Result;
            Action linkWrong = () => ws.CreateLinkedAliasAsync("*****@*****.**", "*****@*****.**").Wait();

            linkWrong.Should().Throw <IdentityException>().Which.StatusCode.Should().Be(HttpStatusCode.NotFound, "the link target doesn't exist");
            Action linkDup = () => ws.CreateLinkedAliasAsync("*****@*****.**", "*****@*****.**").Wait();

            linkDup.Should().Throw <IdentityException>().Which.StatusCode.Should().Be(HttpStatusCode.Conflict, "the alias already exists");
            Action createDup = () => ws.CreateAliasAsync("*****@*****.**", "password2").Wait();

            createDup.Should().Throw <IdentityException>().Which.StatusCode.Should().Be(HttpStatusCode.Conflict, "the alias already exists");
            Alias  alias2      = ws.CreateLinkedAliasAsync("*****@*****.**", "*****@*****.**").Result;
            Action changeWrong = () => alias2.ChangePasswordAsync("wrong", "strong.password").Wait();

            changeWrong.Should().Throw <IdentityException>().Which.StatusCode.Should().Be(HttpStatusCode.Unauthorized, "the password is wrong");
            alias2.ChangePasswordAsync("password1", "strong.password").Wait();
            alias1.ChangePasswordAsync("strong.password", "stronger.password").Wait();

            // Password reset
            string resetTok      = alias2.GenerateResetTokenAsync().Result;
            string resetTokWrong = (resetTok[0] == '0' ? "1" : "0") + resetTok.Substring(1);
            Action resetWrong    = () => alias2.ChangePasswordViaResetTokenAsync(resetTokWrong, "impossible").Wait();

            resetWrong.Should().Throw <IdentityException>().Which.StatusCode.Should().Be(HttpStatusCode.Unauthorized, "the reset token is wrong");
            alias2.ChangePasswordViaResetTokenAsync(resetTok, "strongest.password").Wait();

            // Confirmation and email
            alias1.IsConfirmationTokenLoaded.Should().BeFalse("the token is automatically loaded only on alias get, not create");
            Action unfetched = () => _ = alias1.IsConfirmed;

            unfetched.Should().Throw <InvalidOperationException>("the confirmation token has not been loaded");
            alias1.FetchConfirmationTokenAsync().Wait();
            alias1.IsConfirmed.Should().BeFalse("the alias has not been confirmed yet");
            string confTok      = alias1.ConfirmationToken;
            string confTokWrong = (confTok[0] == '0' ? "1" : "0") + confTok.Substring(1);
            Action confWrong    = () => alias1.ConfirmAsync(confTokWrong).Wait();

            confWrong.Should().Throw <IdentityException>().Which.StatusCode.Should().Be(HttpStatusCode.Unauthorized, "the confirmation token is wrong");
            alias1.ConfirmAsync(confTok).Wait();
            alias1.IsConfirmed.Should().BeTrue("the alias was just confirmed");
            ws.GetAliasAsync("*****@*****.**").Result.IsConfirmed.Should().BeTrue("it's a copy of the confirmed alias");
            alias2.FetchConfirmationTokenAsync().Wait();
            alias2.IsConfirmed.Should().BeFalse("confirmation is at the alias level");
            alias2.EmailAsync("*****@*****.**", "Hello", "World!", "<html><body><strong>World!</strong></body></html>").Wait();

            // Client creation
            alias1.GetClientAsync("test1").Result.Should().BeNull("the client has not been created yet");
            Client client1   = alias1.CreateClientAsync("test1").Result;
            Action clientDup = () => alias2.CreateClientAsync("test1").Wait();

            clientDup.Should().Throw <IdentityException>().Which.StatusCode.Should().Be(HttpStatusCode.Conflict, "the client already exists for the being");
            Dictionary <string, string> data = new Dictionary <string, string>
            {
                ["flubble"] = "1",
                ["Bup"]     = "False"
            };
            Client client2 = alias2.CreateClientAsync("test2", data).Result;

            alias1.GetClientAsync("test2").Result.Data.Should().BeEquivalentTo(data, "it's a copy of the client just created with such data");

            // Login and alias deletion
            Action oldPassword = () => client1.LogInAsync("password1").Wait();

            oldPassword.Should().Throw <IdentityException>().Which.StatusCode.Should().Be(HttpStatusCode.Unauthorized, "the password was changed");
            client1.LogInAsync("strongest.password").Wait();
            alias1.DeleteAsync().Wait();
            Action tooEnthusiastic = () => alias2.DeleteAsync().Wait();

            tooEnthusiastic.Should().Throw <IdentityException>().Which.StatusCode.Should().Be(HttpStatusCode.Forbidden, "one alias must remain");
            client2.LogInAsync("strongest.password").Wait();
            Action tooLate = () => client1.LogInAsync("strongest.password").Wait();

            tooLate.Should().Throw <HttpRequestException>("the server will 404 because the alias has been deleted");

            // Client deletion
            client2.DeleteAsync().Wait();
            Alias  alias2Copy           = ws.GetAliasAsync("*****@*****.**").Result;
            Client client1ViaAlias2Copy = alias2Copy.GetClientAsync("test1").Result;

            client1ViaAlias2Copy.LogInAsync("strongest.password").Wait();
            client1ViaAlias2Copy.DeleteAsync().Wait();
            ws.GetAliasAsync("*****@*****.**").Result.Should().BeNull("everything should be deleted once the last service is deleted");

            // Epilogue
            (json as RecordingHttpJsonClient)?.Persist();
            Console.WriteLine("Test run succeeded");
        }
示例#17
0
 public ProductController(IJsonClient jsonClient)
 {
     _jsonClient = jsonClient;
 }
 private static IEnumerable <HealthCheck> GetChecks(IJsonClient restClient, Uri check)
 {
     return(restClient.Get <IEnumerable <HealthCheck> >(check.ToString(),
                                                        useDefaultCredentials: true));
 }
 internal AuthenticationClient(IJsonClient jsonClient, IErrorMessages errorMessages)
 {
     this.JsonClient    = jsonClient;
     this.ErrorMessages = errorMessages;
 }
示例#20
0
 internal UsersClient(IJsonClient jsonClient, IErrorMessages errorMessages)
     : base(jsonClient, errorMessages)
 {
 }
示例#21
0
 internal SearchClient(IJsonClient jsonClient, IErrorMessages errorMessages)
     : base(jsonClient, errorMessages)
 {
 }
示例#22
0
 internal Alias(IJsonClient json, string url, string emailAddress)
 {
     _json        = json;
     _url         = url;
     EmailAddress = emailAddress;
 }
 private IEpisodesClient CreateClient(IJsonClient jsonClient)
 {
     return(new EpisodesClient(jsonClient, this.ErrorMessages));
 }
示例#24
0
 internal EpisodesClient(IJsonClient jsonClient, IErrorMessages errorMessages)
     : base(jsonClient, errorMessages)
 {
 }
示例#25
0
 public StreamController(string apiUrl, IJsonClient jsonClient, IStreamItemMapper mapper)
 {
     this.apiUrl = apiUrl;
     this.jsonClient = jsonClient;
     this.mapper = mapper;
 }
示例#26
0
 private IUpdatesClient CreateClient(IJsonClient jsonClient)
 {
     return(new UpdatesClient(jsonClient, this.ErrorMessages));
 }
示例#27
0
 internal Alias(IJsonClient json, string url, string emailAddress, string confirmationToken) : this(json, url, emailAddress)
 {
     _confirmationToken        = confirmationToken;
     IsConfirmationTokenLoaded = true;
 }
示例#28
0
 public PriceController(IJsonClient jsonClient)
 {
     _jsonClient = jsonClient;
 }
示例#29
0
 /// <summary>
 /// Constructor
 /// </summary>
 public CallbackService(IJsonClient jsonClient)
 {
     _jsonClient = jsonClient;
 }
示例#30
0
 public LeagueRequestService(IJsonClient jsonClient)
 {
     _jsonClient = jsonClient;
 }