2006-11-27 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / FirebirdSql.Data.Firebird / Test / FbServicesTests.cs
1 /*
2  *  Firebird ADO.NET Data provider for .NET and Mono 
3  * 
4  *     The contents of this file are subject to the Initial 
5  *     Developer's Public License Version 1.0 (the "License"); 
6  *     you may not use this file except in compliance with the 
7  *     License. You may obtain a copy of the License at 
8  *     http://www.firebirdsql.org/index.php?op=doc&id=idpl
9  *
10  *     Software distributed under the License is distributed on 
11  *     an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either 
12  *     express or implied.  See the License for the specific 
13  *     language governing rights and limitations under the License.
14  * 
15  *  Copyright (c) 2002, 2004 Carlos Guzman Alvarez
16  *  All Rights Reserved.
17  */
18
19 using System;
20 using System.Configuration;
21 using System.IO;
22 using System.Data;
23 using System.Text;
24
25 using FirebirdSql.Data.Firebird;
26 using FirebirdSql.Data.Firebird.Services;
27
28 using NUnit.Framework;
29
30 namespace FirebirdSql.Data.Firebird.Tests
31 {
32         [TestFixture]
33         public class FbServicesTest : BaseTest 
34         {       
35                 public FbServicesTest() : base(false)
36                 {
37                 }
38
39                 [SetUp]
40                 public override void SetUp()
41                 {
42                         base.SetUp();
43
44                         if (this.Connection != null && this.Connection.State == ConnectionState.Open)
45                         {
46                                 this.Connection.Close();
47                         }
48                 }
49
50                 [Test]
51                 public void BackupTest()
52                 {
53                         FbBackup backupSvc = new FbBackup();
54                                                 
55                         backupSvc.ConnectionString = this.BuildServicesConnectionString();
56                         backupSvc.BackupFiles.Add(new FbBackupFile(@"c:\testdb.gbk", 2048));
57                         backupSvc.Verbose = true;
58                         
59                         backupSvc.Options = FbBackupFlags.IgnoreLimbo;
60
61                         backupSvc.ServiceOutput += new ServiceOutputEventHandler(ServiceOutput);
62                         
63                         backupSvc.Execute();
64                 }
65                 
66                 [Test]
67                 public void RestoreTest()
68                 {
69                         FbRestore restoreSvc = new FbRestore();
70
71                         restoreSvc.ConnectionString = this.BuildServicesConnectionString();
72                         restoreSvc.BackupFiles.Add(new FbBackupFile(@"c:\testdb.gbk", 2048));
73                         restoreSvc.Verbose      = true;
74                         restoreSvc.PageSize = 4096;
75                         restoreSvc.Options      = FbRestoreFlags.Create | FbRestoreFlags.Replace; 
76
77                         restoreSvc.ServiceOutput += new ServiceOutputEventHandler(ServiceOutput);
78
79                         restoreSvc.Execute();
80                 }
81
82                 [Test]
83                 public void ValidationTest()
84                 {
85                         FbValidation validationSvc = new FbValidation();
86
87                         validationSvc.ConnectionString = this.BuildServicesConnectionString();
88                         validationSvc.Options = FbValidationFlags.ValidateDatabase; 
89
90                         validationSvc.ServiceOutput += new ServiceOutputEventHandler(ServiceOutput);
91
92                         validationSvc.Execute();
93                 }
94
95                 [Test]
96                 public void SweepTest()
97                 {
98                         FbValidation validationSvc = new FbValidation();
99
100                         validationSvc.ConnectionString = this.BuildServicesConnectionString();
101                         validationSvc.Options = FbValidationFlags.SweepDatabase;
102
103                         validationSvc.ServiceOutput += new ServiceOutputEventHandler(ServiceOutput);
104
105                         validationSvc.Execute();
106                 }
107
108                 [Test]
109                 public void SetPropertiesTest()
110                 {
111                         FbConfiguration configurationSvc = new FbConfiguration();
112
113                         configurationSvc.ConnectionString = this.BuildServicesConnectionString();
114
115                         configurationSvc.SetSweepInterval(1000);
116                         configurationSvc.SetReserveSpace(true);
117                         configurationSvc.SetForcedWrites(true);
118                         configurationSvc.DatabaseShutdown(FbShutdownMode.Forced, 10);
119                         configurationSvc.DatabaseOnline();
120                 }
121
122                 [Test]
123                 public void StatisticsTest()
124                 {
125                         FbStatistical statisticalSvc = new FbStatistical();
126
127                         statisticalSvc.ConnectionString = this.BuildServicesConnectionString();
128                         statisticalSvc.Options                  = FbStatisticalFlags.SystemTablesRelations;
129                                                 
130                         statisticalSvc.ServiceOutput += new ServiceOutputEventHandler(ServiceOutput);
131
132                         statisticalSvc.Execute();
133                 }
134                 
135                 [Test]
136                 public void FbLogTest()
137                 {
138                         FbLog logSvc = new FbLog();
139
140                         logSvc.ConnectionString = this.BuildServicesConnectionString(false);
141
142                         logSvc.ServiceOutput += new ServiceOutputEventHandler(ServiceOutput);
143                                                 
144                         logSvc.Execute();
145                 }
146
147                 [Test]
148                 public void AddUserTest()
149                 {
150                         FbSecurity securitySvc = new FbSecurity();
151
152                         securitySvc.ConnectionString = this.BuildServicesConnectionString(false);
153
154                         FbUserData user = new FbUserData();
155                         
156                         user.UserName           = "new_user";
157                         user.UserPassword       = "1";
158                         
159                         securitySvc.AddUser(user);
160                 }
161                 
162                 [Test]
163                 public void DeleteUser()
164                 {
165                         FbSecurity securitySvc = new FbSecurity();
166
167                         securitySvc.ConnectionString = this.BuildServicesConnectionString(false);
168
169                         FbUserData user = new FbUserData();
170                         
171                         user.UserName = "new_user";
172                                                 
173                         securitySvc.DeleteUser(user);
174                 }
175
176                 [Test]
177                 public void DisplayUser()
178                 {
179                         FbSecurity securitySvc = new FbSecurity();
180
181                         securitySvc.ConnectionString = this.BuildServicesConnectionString(false);
182
183                         FbUserData user = securitySvc.DisplayUser("SYSDBA");
184
185                         Console.WriteLine("User name {0}", user.UserName);
186                 }
187
188                 [Test]
189                 public void DisplayUsers()
190                 {
191                         FbSecurity securitySvc = new FbSecurity();
192
193                         securitySvc.ConnectionString = this.BuildServicesConnectionString(false);
194
195                         FbUserData[] users = securitySvc.DisplayUsers();
196
197                         Console.WriteLine("User List");
198
199                         for (int i = 0; i < users.Length; i++)
200                         {
201                                 Console.WriteLine("User {0} name {1}", i, users[i].UserName);
202                         }
203                 }
204                 
205                 [Test]
206                 public void ServerPropertiesTest()
207                 {
208                         FbServerProperties serverProp = new FbServerProperties();
209
210                         serverProp.ConnectionString = this.BuildServicesConnectionString(false);
211
212                         FbServerConfig  serverConfig    = serverProp.ServerConfig;
213                         FbDatabasesInfo databasesInfo   = serverProp.DatabasesInfo;
214                         
215                         Console.WriteLine(serverProp.MessageFile);
216                         Console.WriteLine(serverProp.LockManager);
217                         Console.WriteLine(serverProp.RootDirectory);
218                         Console.WriteLine(serverProp.Implementation);
219                         Console.WriteLine(serverProp.ServerVersion);
220                         Console.WriteLine(serverProp.Version);
221                 }
222
223                 void ServiceOutput(object sender, ServiceOutputEventArgs e)
224                 {
225                         Console.WriteLine(e.Message);
226                 }
227         }
228 }