1+ /*
2+ * MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2017 MinIO, Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ using System . Net ;
18+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
19+ using Minio . Exceptions ;
20+
21+ namespace Minio . Tests ;
22+
23+ /// <summary>
24+ /// Summary description for UnitTest2
25+ /// </summary>
26+ [ TestClass ]
27+ public class UnitTest2
28+ {
29+ public UnitTest2 ( )
30+ {
31+ ServicePointManager . SecurityProtocol = SecurityProtocolType . Tls12
32+ | SecurityProtocolType . Tls11
33+ | SecurityProtocolType . Tls12 ;
34+ using var minio = new MinioClient ( )
35+ . WithEndpoint ( TestHelper . Endpoint )
36+ . WithCredentials ( TestHelper . AccessKey , TestHelper . SecretKey )
37+ . WithSSL ( )
38+ . Build ( ) ;
39+ }
40+
41+ /// <summary>
42+ /// Gets or sets the test context which provides
43+ /// information about and functionality for the current test run.
44+ /// </summary>
45+ public TestContext TestContext { get ; set ; }
46+
47+ [ TestMethod ]
48+ public void TestWithUrl ( )
49+ {
50+ using var client = new MinioClient ( )
51+ . WithEndpoint ( "localhost" , 9000 )
52+ . WithCredentials ( "minio" , "minio" )
53+ . Build ( ) ;
54+ }
55+
56+ [ TestMethod ]
57+ public void TestWithoutPort ( )
58+ {
59+ using var client = new MinioClient ( )
60+ . WithEndpoint ( "localhost" )
61+ . WithCredentials ( "minio" , "minio" )
62+ . Build ( ) ;
63+ }
64+
65+ [ TestMethod ]
66+ public void TestWithTrailingSlash ( )
67+ {
68+ using var client = new MinioClient ( )
69+ . WithEndpoint ( "localhost" , 9000 )
70+ . WithCredentials ( "minio" , "minio" )
71+ . Build ( ) ;
72+ }
73+
74+ [ TestMethod ]
75+ [ ExpectedException ( typeof ( InvalidEndpointException ) ) ]
76+ public void TestUrlFailsWithMalformedScheme ( )
77+ {
78+ using var client = new MinioClient ( )
79+ . WithEndpoint ( "htp://localhost" , 9000 )
80+ . WithCredentials ( "minio" , "minio" )
81+ . Build ( ) ;
82+ }
83+
84+ [ TestMethod ]
85+ [ ExpectedException ( typeof ( InvalidEndpointException ) ) ]
86+ public void TestUrlFailsWithPath ( )
87+ {
88+ using var client = new MinioClient ( ) . WithEndpoint ( "localhost:9000/foo" ) . WithCredentials ( "minio" , "minio" )
89+ . Build ( ) ;
90+ }
91+
92+ [ TestMethod ]
93+ [ ExpectedException ( typeof ( InvalidEndpointException ) ) ]
94+ public void TestUrlFailsWithQuery ( )
95+ {
96+ using var client = new MinioClient ( )
97+ . WithEndpoint ( "localhost:9000/?foo=bar" )
98+ . WithCredentials ( "minio" , "minio" )
99+ . Build ( ) ;
100+ }
101+
102+ [ TestMethod ]
103+ [ ExpectedException ( typeof ( ArgumentException ) ) ]
104+ public void TestSetAppInfoFailsNullApp ( )
105+ {
106+ using var client = new MinioClient ( )
107+ . WithEndpoint ( "localhost" , 9000 )
108+ . WithCredentials ( "minio" , "minio" )
109+ . Build ( ) ;
110+ client . SetAppInfo ( null , "1.2.2" ) ;
111+ }
112+
113+ [ TestMethod ]
114+ [ ExpectedException ( typeof ( ArgumentException ) ) ]
115+ public void TestSetAppInfoFailsNullVersion ( )
116+ {
117+ using var client = new MinioClient ( )
118+ . WithEndpoint ( "localhost" , 9000 )
119+ . WithCredentials ( "minio" , "minio" )
120+ . Build ( ) ;
121+ client . SetAppInfo ( "Hello-App" , null ) ;
122+ }
123+
124+ [ TestMethod ]
125+ public void TestSetAppInfoSuccess ( )
126+ {
127+ using var client = new MinioClient ( )
128+ . WithEndpoint ( "localhost" , 9000 )
129+ . WithCredentials ( "minio" , "minio" )
130+ . Build ( ) ;
131+ client . SetAppInfo ( "Hello-App" , "1.2.1" ) ;
132+ }
133+
134+ [ TestMethod ]
135+ public void TestEndpointSuccess ( )
136+ {
137+ using var client = new MinioClient ( )
138+ . WithEndpoint ( "s3.amazonaws.com" )
139+ . WithCredentials ( "minio" , "minio" )
140+ . Build ( ) ;
141+ }
142+ }
0 commit comments