Files
ssh.net/test/Renci.SshNet.Tests/Classes/ClientAuthenticationTest.cs
mus65 c0a353a4de Cleanup formatting and style and enforce it in CI (#1380)
* Preparation to enforce formatting and style in CI

- enabled IDE0055 to enforce formatting on build
- disabled SA1137 and SA1025 because they are already
  covered by IDE0055
- disabled SA1021 because it conflicts with csharp_space_after_cast

* Cleanup formatting and style on codebase

This commit has no manual changes, it is the result
of running "dotnet format whitespace" and "dotnet format style"

* new formatting fixes after merge

* appveyor: set git autocrlf

as suggested by sharwell to hopefully fix Windows CI.

* use autocrlf input

to hopefully fix Linux tests

* fix formatting

* use autocrlf input for Linux only

* set csharp_space_after_cast to false

* Revert SA1021 suppression

---------

Co-authored-by: Robert Hague <rh@johnstreetcapital.com>
2024-05-17 22:34:27 +02:00

114 lines
3.4 KiB
C#

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Renci.SshNet.Tests.Common;
namespace Renci.SshNet.Tests.Classes
{
[TestClass]
public class ClientAuthenticationTest
{
private ClientAuthentication _clientAuthentication;
[TestInitialize]
public void Init()
{
_clientAuthentication = new ClientAuthentication(1);
}
[TestMethod]
public void Ctor_PartialSuccessLimit_Zero()
{
const int partialSuccessLimit = 0;
try
{
new ClientAuthentication(partialSuccessLimit);
Assert.Fail();
}
catch (ArgumentOutOfRangeException ex)
{
Assert.IsNull(ex.InnerException);
ArgumentExceptionAssert.MessageEquals("Cannot be less than one.", ex);
Assert.AreEqual("partialSuccessLimit", ex.ParamName);
}
}
[TestMethod]
public void Ctor_PartialSuccessLimit_Negative()
{
var partialSuccessLimit = new Random().Next(int.MinValue, -1);
try
{
new ClientAuthentication(partialSuccessLimit);
Assert.Fail();
}
catch (ArgumentOutOfRangeException ex)
{
Assert.IsNull(ex.InnerException);
ArgumentExceptionAssert.MessageEquals("Cannot be less than one.", ex);
Assert.AreEqual("partialSuccessLimit", ex.ParamName);
}
}
[TestMethod]
public void Ctor_PartialSuccessLimit_One()
{
const int partialSuccessLimit = 1;
var clientAuthentication = new ClientAuthentication(partialSuccessLimit);
Assert.AreEqual(partialSuccessLimit, clientAuthentication.PartialSuccessLimit);
}
[TestMethod]
public void Ctor_PartialSuccessLimit_MaxValue()
{
const int partialSuccessLimit = int.MaxValue;
var clientAuthentication = new ClientAuthentication(partialSuccessLimit);
Assert.AreEqual(partialSuccessLimit, clientAuthentication.PartialSuccessLimit);
}
[TestMethod]
public void AuthenticateShouldThrowArgumentNullExceptionWhenConnectionInfoIsNull()
{
const IConnectionInfoInternal connectionInfo = null;
var session = new Mock<ISession>(MockBehavior.Strict).Object;
try
{
_clientAuthentication.Authenticate(connectionInfo, session);
Assert.Fail();
}
catch (ArgumentNullException ex)
{
Assert.IsNull(ex.InnerException);
Assert.AreEqual("connectionInfo", ex.ParamName);
}
}
[TestMethod]
public void AuthenticateShouldThrowArgumentNullExceptionWhenSessionIsNull()
{
var connectionInfo = new Mock<IConnectionInfoInternal>(MockBehavior.Strict).Object;
const ISession session = null;
try
{
_clientAuthentication.Authenticate(connectionInfo, session);
Assert.Fail();
}
catch (ArgumentNullException ex)
{
Assert.IsNull(ex.InnerException);
Assert.AreEqual("session", ex.ParamName);
}
}
}
}