public async Task EndToEndProcessing() { var config = TestHelper.GetApplicationConfiguration(Environment.CurrentDirectory); var retsSession = new RetsSession(config.LoginUrl); if (await retsSession.LoginAsync(config.Username, config.Password, config.UserAgent)) { var metadata = await retsSession.GetMetadataAsync(); foreach (var resource in metadata.Resources) { _output.WriteLine($"Resource: {resource.StandardName} [{resource.VisibleName}]"); foreach (var retsClass in resource.Classes) { _output.WriteLine($"Class: {retsClass.StandardName} [{retsClass.VisibleName}]"); _output.WriteLine($"Tables:"); foreach (var table in retsClass.Tables) { _output.WriteLine("====================================================================="); _output.WriteLine($"Table: Resource-{table.Resource} Class:{table.Class}"); _output.WriteLine("====================================================================="); foreach (var field in table.Fields) { _output.WriteLine($"{field.StandardName,40} ({field.DataType}:{field.Precision})"); } } } } // todo: call other session methods await retsSession.LogoutAsync(); } }
public async Task Logout_WithLogin_Succeeds() { // Arrange var mockRetsHttpClient = new Mock <IRetsHttpClient>(); mockRetsHttpClient .Setup(m => m.LoginAsync(It.IsAny <Uri>())) .ReturnsAsync(new LoginResponse()); mockRetsHttpClient .Setup(m => m.LogoutAsync()); var retsSession = new RetsSession("https://retsserver/login") { RetsHttpClient = mockRetsHttpClient.Object }; // Act var response = await retsSession.LoginAsync("username", "password", "useragent"); if (response == true) { await retsSession.LogoutAsync(); } // Assert Assert.True(response); Assert.Null(retsSession.LoginResponse); }
public async Task Login_WithInvalidCredentials_Unsuccessful() { // Arrange var config = TestHelper.GetApplicationConfiguration(Environment.CurrentDirectory); var retsSession = new RetsSession(config.LoginUrl); // Act var result = await retsSession.LoginAsync("invalid-username", "invalid-password", "invalid-useragent"); // Assert Assert.False(result); Assert.Null(retsSession.LoginResponse); }
public async Task Login_WithValidCredential_ReturnsTrue() { // Arrange var config = TestHelper.GetApplicationConfiguration(Environment.CurrentDirectory); var retsSession = new RetsSession(config.LoginUrl); // Act var result = await retsSession.LoginAsync(config.Username, config.Password, config.UserAgent); // Assert Assert.True(result); Assert.NotNull(retsSession.LoginResponse); }
public async Task Logout_WithLogin_Succeeds() { // Arrange var config = TestHelper.GetApplicationConfiguration(Environment.CurrentDirectory); var retsSession = new RetsSession(config.LoginUrl); // Act var response = await retsSession.LoginAsync(config.Username, config.Password, config.UserAgent); if (response == true) { await retsSession.LogoutAsync(); } // Assert Assert.True(response); Assert.Null(retsSession.LoginResponse); }
public async Task Login_WithInvalidCredentials_ReturnsFalse() { // Arrange var mockRetsHttpClient = new Mock <IRetsHttpClient>(); mockRetsHttpClient .Setup(m => m.LoginAsync(It.IsAny <Uri>())) .Returns(Task.FromResult <LoginResponse>(null)); var retsSession = new RetsSession("https://retsserver/login") { // Use this test seam to mock the HttpClient RetsHttpClient = mockRetsHttpClient.Object }; // Act var result = await retsSession.LoginAsync("invalidusername", "invalidpassword", "invaliduseragent"); // Assert Assert.False(result); Assert.Null(retsSession.LoginResponse); }
public async Task Login_WithValidCredentials_ReturnsTrue() { // Arrange var mockRetsHttpClient = new Mock <IRetsHttpClient>(); mockRetsHttpClient .Setup(m => m.LoginAsync(It.IsAny <Uri>())) .ReturnsAsync(new LoginResponse()); var retsSession = new RetsSession("http://retsserver/login") { // Use this test seam to mock the HttpClient RetsHttpClient = mockRetsHttpClient.Object }; // Act var result = await retsSession.LoginAsync("username", "password", "useragent"); // Assert Assert.True(result); Assert.NotNull(retsSession.LoginResponse); }