1+ /* Copyright 2010-present MongoDB Inc.
2+ *
3+ * Licensed under the Apache License, Version 2.0 (the "License");
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an "AS IS" BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+
16+ using System ;
17+ using FluentAssertions ;
18+ using Xunit ;
19+
20+ namespace MongoDB . Driver . Core . Connections ;
21+
22+ public class Socks5AuthenticationSettingsTests
23+ {
24+ [ Fact ]
25+ public void Socks5AuthenticationSettings_None_should_return_NoAuthenticationSettings_instance ( )
26+ {
27+ var none = Socks5AuthenticationSettings . None ;
28+ none . Should ( ) . BeOfType < Socks5AuthenticationSettings . NoAuthenticationSettings > ( ) ;
29+ }
30+
31+ [ Fact ]
32+ public void Socks5AuthenticationSettings_UsernamePassword_should_return_UsernamePasswordAuthenticationSettings_instance_with_correct_values ( )
33+ {
34+ var up = Socks5AuthenticationSettings . UsernamePassword ( "user" , "pass" ) ;
35+ up . Should ( ) . BeOfType < Socks5AuthenticationSettings . UsernamePasswordAuthenticationSettings > ( ) ;
36+ var upcast = ( Socks5AuthenticationSettings . UsernamePasswordAuthenticationSettings ) up ;
37+ upcast . Username . Should ( ) . Be ( "user" ) ;
38+ upcast . Password . Should ( ) . Be ( "pass" ) ;
39+ }
40+
41+ [ Theory ]
42+ [ InlineData ( null , "pass" ) ]
43+ [ InlineData ( "user" , null ) ]
44+ [ InlineData ( "" , "pass" ) ]
45+ [ InlineData ( "user" , "" ) ]
46+ public void Socks5AuthenticationSettings_UsernamePassword_should_throw_when_username_or_password_is_null_or_empty ( string username , string password )
47+ {
48+ var ex = Record . Exception ( ( ) => Socks5AuthenticationSettings . UsernamePassword ( username , password ) ) ;
49+ ex . Should ( ) . BeAssignableTo < ArgumentException > ( ) ;
50+ }
51+
52+ [ Fact ]
53+ public void Socks5AuthenticationSettings_NoAuthenticationSettings_Equals_should_return_true_for_any_Socks5AuthenticationSettings ( )
54+ {
55+ var none = Socks5AuthenticationSettings . None ;
56+ none . Equals ( Socks5AuthenticationSettings . None ) . Should ( ) . BeTrue ( ) ;
57+ none . Equals ( Socks5AuthenticationSettings . UsernamePassword ( "a" , "b" ) ) . Should ( ) . BeFalse ( ) ;
58+ }
59+
60+ [ Fact ]
61+ public void Socks5AuthenticationSettings_UsernamePasswordAuthenticationSettings_Equals_and_GetHashCode_should_work ( )
62+ {
63+ var a = Socks5AuthenticationSettings . UsernamePassword ( "u" , "p" ) ;
64+ var b = Socks5AuthenticationSettings . UsernamePassword ( "u" , "p" ) ;
65+ a . Equals ( b ) . Should ( ) . BeTrue ( ) ;
66+ a . GetHashCode ( ) . Should ( ) . Be ( b . GetHashCode ( ) ) ;
67+ var c = Socks5AuthenticationSettings . UsernamePassword ( "u" , "x" ) ;
68+ a . Equals ( c ) . Should ( ) . BeFalse ( ) ;
69+ }
70+ }
0 commit comments