public async Task ShouldGetEvents() { MockDiscoveryRequest(); MockLoginRequest(); var getEventsResponse = new GetEventsResponse { Events = _events }; _mockRestClient .Setup(x => x.GetAsync <GetEventsResponse>( It.IsAny <string>(), It.IsAny <Dictionary <string, string> >() )) .ReturnsAsync(getEventsResponse); var nubankClient = new Nubank(_mockRestClient.Object, "login", "password"); await nubankClient.LoginAsync(); var actualEvents = await nubankClient.GetEventsAsync(); Assert.Equal(_events, actualEvents); _mockRestClient.Verify(x => x.GetAsync <GetEventsResponse>( It.IsAny <string>(), It.IsAny <Dictionary <string, string> >() ), Times.Once()); }
public async Task ShouldAutenticateWithQrCode() { MockDiscoveryRequest(); MockDiscoveryAppRequest(); MockLoginRequestWithouEventsUrl(); var nubankClient = new Nubank(_mockRestClient.Object, "login", "password"); var loginResponse = await nubankClient.LoginAsync(); MockLiftRequest(loginResponse.Code); await nubankClient.AutenticateWithQrCodeAsync(loginResponse.Code); var expectedPayload = new { qr_code_id = loginResponse.Code, type = "login-webapp" }; _mockRestClient.Verify(x => x.PostAsync <Dictionary <string, object> >( "lift_url", It.Is <object>(o => o.GetHashCode() == expectedPayload.GetHashCode()), It.Is <Dictionary <string, string> >(dictionary => IsValidAuthorizationHeader(dictionary)) ), Times.Once()); }
private async Task <LoginResponse> LoginOrThrow(Nubank nubankClient) { try { return(await nubankClient.LoginAsync()); } catch (Exception e) { throw new UnauthorizedException(); } }
public async Task ShouldReturnLoginResponseWithNotNeedsDeviceAuthorizationWhenEventsPresentInLoginResponse() { MockDiscoveryRequest(); MockLoginRequest(); var nubankClient = new Nubank(_mockRestClient.Object, "login", "password"); var loginResponse = await nubankClient.LoginAsync(); Assert.False(loginResponse.NeedsDeviceAuthorization); Assert.Null(loginResponse.Code); }
static async Task Main() { Console.WriteLine("Nubank Client"); Console.WriteLine("Please, type your login (CPF):"); var login = Console.ReadLine().Trim(); Console.WriteLine("Type your password:"******"You must authenticate with your phone to be able to access your data."); Console.WriteLine("Scan the QRCode below with you Nubank application on the following menu:"); Console.WriteLine("Nu(Seu Nome) > Perfil > Acesso pelo site"); Console.WriteLine(); Console.WriteLine(result.GetQrCodeAsAscii()); Console.WriteLine($"Use your phone to scan and after this press any key to continue..."); Console.ReadKey(); await nubankClient.AutenticateWithQrCodeAsync(result.Code); } try { var savings = await nubankClient.GetSavingsAsync(); ConsoleTable .From(savings) .Write(Format.Alternative); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } var events = await nubankClient.GetEventsAsync(); ConsoleTable .From(events) .Write(Format.Alternative); Console.ReadKey(); }
public async Task ShouldThrowExceptionWithGenericMessageWhenLoginFailedAndErrorIsNotPresent() { MockDiscoveryRequest(); const string errorMessage = "Unknow error occurred on trying to do login on Nubank using the entered credentials"; var loginData = new Dictionary <string, object>(); _mockRestClient .Setup(x => x.PostAsync <Dictionary <string, object> >(It.IsAny <string>(), It.IsAny <object>())) .ReturnsAsync(loginData); var nubankClient = new Nubank(_mockRestClient.Object, "login", "password"); var exception = await Assert.ThrowsAsync <AuthenticationException>( async() => await nubankClient.LoginAsync() ); Assert.Equal(errorMessage, exception.Message); }
public async Task ShouldGetSavings() { MockDiscoveryRequest(); MockLoginRequest(); var getSavingsResponse = new GetSavingsResponse() { Data = new DataResponse() { Viewer = new ViewerResponse() { SavingsAccount = new SavingsAccount() { Feed = _savings } } } }; _mockRestClient .Setup(x => x.PostAsync <GetSavingsResponse>( It.IsAny <string>(), It.IsAny <object>(), It.IsAny <Dictionary <string, string> >() )) .ReturnsAsync(getSavingsResponse); var nubankClient = new Nubank(_mockRestClient.Object, "login", "password"); await nubankClient.LoginAsync(); var actualSavings = await nubankClient.GetSavingsAsync(); Assert.Equal(_savings, actualSavings); _mockRestClient.Verify(x => x.PostAsync <GetSavingsResponse>( It.IsAny <string>(), It.IsAny <object>(), It.IsAny <Dictionary <string, string> >() ), Times.Once()); }
public async Task ShouldThrowExceptionWithErrorProvidedWhenLoginFailed() { MockDiscoveryRequest(); const string errorMessage = "error message"; var loginData = new Dictionary <string, object> { { "error", errorMessage } }; _mockRestClient .Setup(x => x.PostAsync <Dictionary <string, object> >(It.IsAny <string>(), It.IsAny <object>())) .ReturnsAsync(loginData); var nubankClient = new Nubank(_mockRestClient.Object, "login", "password"); var exception = await Assert.ThrowsAsync <AuthenticationException>( async() => await nubankClient.LoginAsync() ); Assert.Equal(errorMessage, exception.Message); }