public async Task AuthenticateFailureTest() { // Arrange var deviceIdentity = Mock.Of <IDeviceIdentity>(d => d.Id == "d1" && d.DeviceId == "d1"); IClientCredentials credentials = new TokenCredentials(deviceIdentity, Guid.NewGuid().ToString(), string.Empty, Option.None <string>(), Option.None <string>(), false); var connectionManager = Mock.Of <IConnectionManager>(c => c.CreateCloudConnectionAsync(credentials) == Task.FromResult(Try <ICloudProxy> .Failure(new TimeoutException()))); IAuthenticator cloudAuthenticator = new CloudTokenAuthenticator(connectionManager, IotHubHostName); // Act bool isAuthenticated = await cloudAuthenticator.AuthenticateAsync(credentials); // Assert Assert.False(isAuthenticated); }
public async Task AuthenticateTest() { // Arrange var deviceIdentity = Mock.Of <IDeviceIdentity>(d => d.Id == "d1" && d.DeviceId == "d1"); IClientCredentials credentials = new TokenCredentials(deviceIdentity, Guid.NewGuid().ToString(), string.Empty); var cloudProxy = Mock.Of <ICloudProxy>(c => c.OpenAsync() == Task.FromResult(true)); var connectionManager = Mock.Of <IConnectionManager>(c => c.CreateCloudConnectionAsync(credentials) == Task.FromResult(Try.Success(cloudProxy))); IAuthenticator cloudAuthenticator = new CloudTokenAuthenticator(connectionManager, IotHubHostName); // Act bool isAuthenticated = await cloudAuthenticator.AuthenticateAsync(credentials); // Assert Assert.True(isAuthenticated); }
public async Task AuthenticateFailureTest() { // Arrange var deviceIdentity = Mock.Of <IDeviceIdentity>(d => d.Id == "d1" && d.DeviceId == "d1"); IClientCredentials credentials = new TokenCredentials(deviceIdentity, Guid.NewGuid().ToString(), string.Empty); var cloudProxy = Mock.Of <ICloudProxy>(); Mock.Get(cloudProxy).Setup(c => c.OpenAsync()).ThrowsAsync(new Exception("Unauthorized")); var connectionManager = Mock.Of <IConnectionManager>(c => c.CreateCloudConnectionAsync(credentials) == Task.FromResult(Try.Success(cloudProxy))); IAuthenticator cloudAuthenticator = new CloudTokenAuthenticator(connectionManager); // Act bool isAuthenticated = await cloudAuthenticator.AuthenticateAsync(credentials); // Assert Assert.False(isAuthenticated); }