public async void TestAuthenticateFailure_EmptyPassword() { var serverConnectionMock = CreateServerConnectionMockWithContext(); var pAuth = new PasswordAuthentication(serverConnectionMock.Object) { Username = "******", }; await AssertEx.ThrowsAsync <InvalidOperationException>(async() => await pAuth.Authenticate()); }
public async void TestAuthenticateFailure_EmptyPassword() { var serverConnectionMock = CreateServerConnectionMockWithContext(); var pAuth = new PasswordAuthentication(serverConnectionMock.Object) { Username = "******", }; await AssertEx.ThrowsAsync<InvalidOperationException>(async () => await pAuth.Authenticate()); }
public async void TestLogOnSuccess_Username() { var authentication = new PasswordAuthentication(Generator.ServerConnection) { Username = Generator.Username, Password = Generator.Password }; var userInfo = await authentication.Authenticate(); ValidateUserInfo(userInfo); }
public async void TestAuthenticateFailure_InvalidJson() { var serverConnectionMock = CreateServerConnectionMockWithContext(); var expectedPostUri = new Uri("https://www.douban.com/service/auth2/token"); serverConnectionMock.Setup(s => s.Post(It.Is<Uri>(u => u == expectedPostUri), It.Is<byte[]>(d => d.Length > 0))).ReturnsAsync("###").Verifiable(); var pAuth = new PasswordAuthentication(serverConnectionMock.Object) { Username = "******", Password = "******", }; await AssertEx.ThrowsAsync<JsonReaderException>(async () => await pAuth.Authenticate()); serverConnectionMock.Verify(); }
public async void TestAuthenticateFailure_Exception() { var serverConnectionMock = CreateServerConnectionMockWithContext(); var expectedPostUri = new Uri("https://www.douban.com/service/auth2/token"); serverConnectionMock.Setup(s => s.Post(It.Is<Uri>(u => u == expectedPostUri), It.Is<byte[]>(d => d.Length > 0))).ThrowsAsync(new Exception("Test message.")).Verifiable(); var pAuth = new PasswordAuthentication(serverConnectionMock.Object) { Username = "******", Password = "******", }; var ex = await AssertEx.ThrowsAsync<Exception>(async () => await pAuth.Authenticate()); Assert.AreEqual("Test message.", ex.Message); serverConnectionMock.Verify(); }
public async void TestAuthenticateFailure_InvalidJson() { var serverConnectionMock = CreateServerConnectionMockWithContext(); var expectedPostUri = new Uri("https://www.douban.com/service/auth2/token"); serverConnectionMock.Setup(s => s.Post(It.Is <Uri>(u => u == expectedPostUri), It.Is <byte[]>(d => d.Length > 0))).ReturnsAsync("###").Verifiable(); var pAuth = new PasswordAuthentication(serverConnectionMock.Object) { Username = "******", Password = "******", }; await AssertEx.ThrowsAsync <JsonReaderException>(async() => await pAuth.Authenticate()); serverConnectionMock.Verify(); }
public async void TestAuthenticateFailure_Exception() { var serverConnectionMock = CreateServerConnectionMockWithContext(); var expectedPostUri = new Uri("https://www.douban.com/service/auth2/token"); serverConnectionMock.Setup(s => s.Post(It.Is <Uri>(u => u == expectedPostUri), It.Is <byte[]>(d => d.Length > 0))).ThrowsAsync(new Exception("Test message.")).Verifiable(); var pAuth = new PasswordAuthentication(serverConnectionMock.Object) { Username = "******", Password = "******", }; var ex = await AssertEx.ThrowsAsync <Exception>(async() => await pAuth.Authenticate()); Assert.AreEqual("Test message.", ex.Message); serverConnectionMock.Verify(); }
public async void TestAuthenticateSuccess() { var serverConnectionMock = CreateServerConnectionMockWithContext(); var expectedPostUri = new Uri("https://www.douban.com/service/auth2/token"); serverConnectionMock.Setup(s => s.Post(It.Is<Uri>(u => u == expectedPostUri), It.Is<byte[]>(d => d.Length > 0))).ReturnsAsync(Resource.TestOAuthResponse).Verifiable(); var pAuth = new PasswordAuthentication(serverConnectionMock.Object) { Username = "******", Password = "******", }; var result = await pAuth.Authenticate(); Assert.IsNotNull(result); Assert.IsNotNull(result.AccessToken); Assert.IsNotNull(result.RefreshToken); Assert.IsNotNull(result.Username); Assert.AreNotEqual(0, result.UserId); Assert.AreNotEqual(0, result.ExpiresIn); serverConnectionMock.Verify(); }
public async void TestAuthenticateSuccess() { var serverConnectionMock = CreateServerConnectionMockWithContext(); var expectedPostUri = new Uri("https://www.douban.com/service/auth2/token"); serverConnectionMock.Setup(s => s.Post(It.Is <Uri>(u => u == expectedPostUri), It.Is <byte[]>(d => d.Length > 0))).ReturnsAsync(Resource.TestOAuthResponse).Verifiable(); var pAuth = new PasswordAuthentication(serverConnectionMock.Object) { Username = "******", Password = "******", }; var result = await pAuth.Authenticate(); Assert.IsNotNull(result); Assert.IsNotNull(result.AccessToken); Assert.IsNotNull(result.RefreshToken); Assert.IsNotNull(result.Username); Assert.AreNotEqual(0, result.UserId); Assert.AreNotEqual(0, result.ExpiresIn); serverConnectionMock.Verify(); }