2 * Firebird ADO.NET Data provider for .NET and Mono
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
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.
15 * Copyright (c) 2002, 2004 Carlos Guzman Alvarez
16 * All Rights Reserved.
20 using System.Configuration;
25 using FirebirdSql.Data.Firebird;
26 using FirebirdSql.Data.Firebird.Services;
28 using NUnit.Framework;
30 namespace FirebirdSql.Data.Firebird.Tests
33 public class FbServicesTest : BaseTest
35 public FbServicesTest() : base(false)
40 public override void SetUp()
44 if (this.Connection != null && this.Connection.State == ConnectionState.Open)
46 this.Connection.Close();
51 public void BackupTest()
53 FbBackup backupSvc = new FbBackup();
55 backupSvc.ConnectionString = this.BuildServicesConnectionString();
56 backupSvc.BackupFiles.Add(new FbBackupFile(@"c:\testdb.gbk", 2048));
57 backupSvc.Verbose = true;
59 backupSvc.Options = FbBackupFlags.IgnoreLimbo;
61 backupSvc.ServiceOutput += new ServiceOutputEventHandler(ServiceOutput);
67 public void RestoreTest()
69 FbRestore restoreSvc = new FbRestore();
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;
77 restoreSvc.ServiceOutput += new ServiceOutputEventHandler(ServiceOutput);
83 public void ValidationTest()
85 FbValidation validationSvc = new FbValidation();
87 validationSvc.ConnectionString = this.BuildServicesConnectionString();
88 validationSvc.Options = FbValidationFlags.ValidateDatabase;
90 validationSvc.ServiceOutput += new ServiceOutputEventHandler(ServiceOutput);
92 validationSvc.Execute();
96 public void SweepTest()
98 FbValidation validationSvc = new FbValidation();
100 validationSvc.ConnectionString = this.BuildServicesConnectionString();
101 validationSvc.Options = FbValidationFlags.SweepDatabase;
103 validationSvc.ServiceOutput += new ServiceOutputEventHandler(ServiceOutput);
105 validationSvc.Execute();
109 public void SetPropertiesTest()
111 FbConfiguration configurationSvc = new FbConfiguration();
113 configurationSvc.ConnectionString = this.BuildServicesConnectionString();
115 configurationSvc.SetSweepInterval(1000);
116 configurationSvc.SetReserveSpace(true);
117 configurationSvc.SetForcedWrites(true);
118 configurationSvc.DatabaseShutdown(FbShutdownMode.Forced, 10);
119 configurationSvc.DatabaseOnline();
123 public void StatisticsTest()
125 FbStatistical statisticalSvc = new FbStatistical();
127 statisticalSvc.ConnectionString = this.BuildServicesConnectionString();
128 statisticalSvc.Options = FbStatisticalFlags.SystemTablesRelations;
130 statisticalSvc.ServiceOutput += new ServiceOutputEventHandler(ServiceOutput);
132 statisticalSvc.Execute();
136 public void FbLogTest()
138 FbLog logSvc = new FbLog();
140 logSvc.ConnectionString = this.BuildServicesConnectionString(false);
142 logSvc.ServiceOutput += new ServiceOutputEventHandler(ServiceOutput);
148 public void AddUserTest()
150 FbSecurity securitySvc = new FbSecurity();
152 securitySvc.ConnectionString = this.BuildServicesConnectionString(false);
154 FbUserData user = new FbUserData();
156 user.UserName = "new_user";
157 user.UserPassword = "1";
159 securitySvc.AddUser(user);
163 public void DeleteUser()
165 FbSecurity securitySvc = new FbSecurity();
167 securitySvc.ConnectionString = this.BuildServicesConnectionString(false);
169 FbUserData user = new FbUserData();
171 user.UserName = "new_user";
173 securitySvc.DeleteUser(user);
177 public void DisplayUser()
179 FbSecurity securitySvc = new FbSecurity();
181 securitySvc.ConnectionString = this.BuildServicesConnectionString(false);
183 FbUserData user = securitySvc.DisplayUser("SYSDBA");
185 Console.WriteLine("User name {0}", user.UserName);
189 public void DisplayUsers()
191 FbSecurity securitySvc = new FbSecurity();
193 securitySvc.ConnectionString = this.BuildServicesConnectionString(false);
195 FbUserData[] users = securitySvc.DisplayUsers();
197 Console.WriteLine("User List");
199 for (int i = 0; i < users.Length; i++)
201 Console.WriteLine("User {0} name {1}", i, users[i].UserName);
206 public void ServerPropertiesTest()
208 FbServerProperties serverProp = new FbServerProperties();
210 serverProp.ConnectionString = this.BuildServicesConnectionString(false);
212 FbServerConfig serverConfig = serverProp.ServerConfig;
213 FbDatabasesInfo databasesInfo = serverProp.DatabasesInfo;
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);
223 void ServiceOutput(object sender, ServiceOutputEventArgs e)
225 Console.WriteLine(e.Message);