public async Task ListenAsync_shoud_not_listen_twice() { var jsRuntimeMock = new Mock <IJSRuntime>(); var awsHelperMock = new Mock <IAwsHelper>(); jsRuntimeMock.Setup(m => m.InvokeAsync <object>(It.Is <string>(s => s == "amplifyWrapper.hub.listen"), It.Is <IAwsHelper>(r => r == awsHelperMock.Object))) .ReturnsAsync(new object()) .Verifiable(); var sut = new AwsJsInterop(jsRuntimeMock.Object, awsHelperMock.Object); await sut.ListenAsync(); await sut.ListenAsync(); jsRuntimeMock.Verify(m => m.InvokeAsync <object>(It.Is <string>(s => s == "amplifyWrapper.hub.listen"), It.Is <IAwsHelper>(r => r == awsHelperMock.Object)), Times.Exactly(1)); }
protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { var config = new AwsConfig { Aws_cognito_identity_pool_id = "eu-west-2:5ad8c79a-2cdc-4da4-a94c-1c42becdf301", Aws_cognito_region = "eu-west-2", Aws_user_pools_id = "eu-west-2_MUFO3Qdac", Aws_user_pools_web_client_id = "1ou6jkhe2u8j7sj14rek4a6mcq", Oauth = new AwsOAuth { Domain = "football-championship-dev.auth.eu-west-2.amazoncognito.com", Scope = new string[] { "phone", "email", "openid", "profile", "aws.cognito.signin.user.admin" }, RedirectSignIn = NavigationManager.BaseUri, RedirectSignOut = NavigationManager.BaseUri, ResponseType = "code" }, FederationTarget = "COGNITO_USER_POOLS", Aws_appsync_graphqlEndpoint = "https://pod5c66d6ze73b62evt7xqpn4q.appsync-api.eu-west-2.amazonaws.com/graphql", Aws_appsync_region = "eu-west-2", Aws_appsync_authenticationType = "AMAZON_COGNITO_USER_POOLS" }; await AwsJsInterop.ConfigureAsync(config); await AwsJsInterop.ListenAsync(); if (AwsHelper.IsConnected) { await BrowserJsInterop.NotificationOptIn(); var matches = new List <Match>(); GraphQlSubscriber.MatchUpdated += async(e, match) => { if (match.MatchTeams?.Items == null || match.Scores == null) { return; } var homeTeam = match.MatchTeams.Items.First(t => t.IsHome).Team; var awayTeam = match.MatchTeams.Items.First(t => !t.IsHome).Team; var homeScore = match.Scores.First(s => s.IsHome).Value; var awayScore = match.Scores.First(s => !s.IsHome).Value; if (!matches.Any(m => m.Id == match.Id)) { matches.Add(match); return; } var started = matches.First(m => m.Id == match.Id); var message = $"{homeTeam.LocalizedNames.GetLocalizedValue()} - {awayTeam.LocalizedNames.GetLocalizedValue()}\n{homeScore} - {awayScore}"; if (match.IsFinished != started.IsFinished) { started.IsFinished = match.IsFinished; await BrowserJsInterop.Notify(Resources["Finished"], message); return; } foreach (var score in match.Scores) { if (started.Scores.Any(s => s.IsHome == score.IsHome && s.Value != score.Value)) { started.Scores = match.Scores; await BrowserJsInterop.Notify("Gooooal!", message); return; } } }; await AwsJsInterop.GraphSubscribeAsync(Subscriptions.ON_UPDATE_MATCH, GraphQlSubscriber, nameof(GraphQlSubscriber.OnMatchUpdated)); } } await base.OnAfterRenderAsync(firstRender); }