Subversion Repository Public Repository

ConnectionOdbcSdk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
´╗┐using System;
using System.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Cisco.UnityConnection.OdbcSdk;

namespace ConnectionServerOdbcIntegrationTests.IntegrationTests
{
    [TestClass]
    public class ConnectionInformixAdoNetDatabaseFunctionIntegrationTests : BaseIntegrationTests
    {
        #region Fields and Properties

        private bool _debugEventCalled;
        private bool _errorEventCalled;

        #endregion


        #region Additional test attributes

        //Use ClassInitialize to run code before running the first test in the class
        [ClassInitialize]
        public new static void MyClassInitialize(TestContext testContext)
        {
            BaseIntegrationTests.MyClassInitialize(testContext);
        }

        #endregion


        #region Constructor Tests

        [TestMethod]
        public void ConstructorDesctructorTest()
        {
            ConnectionInformixAdoNetDatabaseFunctions oTest = new ConnectionInformixAdoNetDatabaseFunctions("test");
            oTest.Dispose();
        }

        #endregion


        #region Event Trigger Tests

        [TestMethod]
        public void DebugEventTest_DebugOn()
        {
            _debugEventCalled = false;
            
            Server.DatabaseFunctions.DebugMode = true;
            Server.DatabaseFunctions.DebugEvents += ServerOnDebugEvents;
            Server.DatabaseFunctions.ClearProcMonitor();
            Assert.IsTrue(_debugEventCalled, "Debug event not fired for GetDefaultLanguage");
        }

        [TestMethod]
        public void DebugEventTest_DebugOff()
        {
            _debugEventCalled = false;
            Server.DatabaseFunctions.DebugMode = false;
            Server.DatabaseFunctions.DebugEvents += ServerOnDebugEvents;
            Server.DatabaseFunctions.ClearProcMonitor();
            Assert.IsFalse(_debugEventCalled, "Debug event fired when debug is off for GetDefaultLanguage");
        }

        private void ServerOnDebugEvents(object sender, LogEventArgs logEventArgs)
        {
            _debugEventCalled = true;
            Console.WriteLine(logEventArgs.Line);
            Console.WriteLine(logEventArgs.ToString());
        }

        [TestMethod]
        public void ErrorEventTest()
        {
            _errorEventCalled = false;
            Server.DatabaseFunctions.DebugMode = false;
            Server.DatabaseFunctions.ErrorEvents += TestOnErrorEvents;
            Server.DatabaseFunctions.ExecuteNonQuery(""); 
            Assert.IsTrue(_errorEventCalled, "Error event did not fire when error issued for dbfetch");
        }

        private void TestOnErrorEvents(object sender, LogEventArgs logEventArgs)
        {
            _errorEventCalled = true;
            Console.WriteLine("[ERROR] " + logEventArgs.Line);
        }

        #endregion


        #region Property Tests

        [TestMethod]
        public void GreetingsAdministratorRoleObjectIdTest()
        {
            string strObjectId = Server.DatabaseFunctions.GreetingsAdministratorRoleObjectId;
            Assert.IsTrue(!string.IsNullOrEmpty(strObjectId),"GreetingsAdministratorRole objectId returned empty string");
        }

        [TestMethod]
        public void GetIfxConnectionStatusTest_Open()
        {
            var iStatus = Server.DatabaseFunctions.DatabaseConnectionStatus;
            Assert.IsTrue(iStatus == ConnectionState.Open,"Current connection status not reporting open:"+iStatus);
        }

        [TestMethod]
        public void GetIfxConnectionStatusTest_Closed()
        {
            ConnectionInformixAdoNetDatabaseFunctions oTemp = new ConnectionInformixAdoNetDatabaseFunctions("test");
            var iStatus = oTemp.DatabaseConnectionStatus;
            Assert.IsTrue(iStatus != ConnectionState.Open, "Current connection status reporting open:" + iStatus);
        }

        #endregion


        #region Login Tests

        [TestMethod]
        public void AttachToDatabase_InvalidServerName()
        {
            ConnectionServerOdbc oServer = new ConnectionServerOdbc(new ConnectionInformixAdoNetDatabaseFunctions("Test"));
            var ret = oServer.LoginDatabaseBlocking("loginname", "password", "bogus server name");
            Assert.IsFalse(ret.Successful,"Logging in with invalid server name should fail:"+ret);
        }

        [TestMethod]
        public void UpdateDatabaseName_ValidNames()
        {
            
            var res = Server.DatabaseFunctions.UpdateDatabaseName("UnityDynDb");
            Assert.IsTrue(res.Successful, "Failed to attach to UnityDynDb" + res);
            Console.WriteLine("Current Database Name="+ Server.CurrentDatabaseName);
            
            res = Server.DatabaseFunctions.UpdateDatabaseName("UnityRptDb");
            Assert.IsTrue(res.Successful, "Failed to attach to UnityRptDb" + res);
            Console.WriteLine("Current Database Name="+ Server.CurrentDatabaseName);

            res = Server.DatabaseFunctions.UpdateDatabaseName("UnityMbxDb1");
            Assert.IsTrue(res.Successful, "Failed to attach to UnityMbxDb1" + res);
            Console.WriteLine("Current Database Name="+ Server.CurrentDatabaseName);
            
            res = Server.DatabaseFunctions.UpdateDatabaseName("UnityDirDb");
            Assert.IsTrue(res.Successful, "Failed to attach to UnityDirDb" + res);
            Console.WriteLine("Current Database Name=" + Server.CurrentDatabaseName);
        }

        [TestMethod]
        public void UpdateDatabaseName_InvalidName()
        {
            var res = Server.DatabaseFunctions.UpdateDatabaseName("Junk");
            Assert.IsFalse(res.Successful, "Changing to invalid database name did not fail:" + res);
        }

        [TestMethod]
        public void UpdateDatabaseName_NullConnection()
        {
            ConnectionServerOdbc oTest = new ConnectionServerOdbc(new ConnectionInformixAdoNetDatabaseFunctions("test"));
            var res = oTest.DatabaseFunctions.UpdateDatabaseName("UnityDirDb");
            Assert.IsFalse(res.Successful,"Changing database name for a server not logged in did not fail:"+res);
        }


        #endregion


        #region Data Fetch Method Tests

        [TestMethod]
        public void GetConfigurationString_EmptyStringFailure()
        {
            string res = Server.DatabaseFunctions.GetConfigurationString("");
            Assert.IsTrue(string.IsNullOrEmpty(res),"Empty configuration string did not return empty string");
        }

        [TestMethod]
        public void GetRemoteFileName()
        {
            string strName = Server.DatabaseFunctions.GetRemoteFileName();
            Assert.IsTrue(!string.IsNullOrEmpty(strName),"Remote file name generation failed to return a valid name");

            bool ret = Server.DatabaseFunctions.IsStreamFileMarkedDeleted(strName);
            Assert.IsFalse(ret,"Newly created file should not be marked for deletion");

        }



        #endregion

        [TestMethod]
        public void UpdateDatabaseName_Null()
        {
            var res = DbFunctions.UpdateDatabaseName(null);
            Assert.IsFalse(res.Successful, "Calling UpdateDatabaseName with null parameter should fail:" + res);
        }

        [TestMethod]
        public void UpdateDatabaseName_UnityMbxDb6()
        {
            var res = DbFunctions.UpdateDatabaseName("UNITYMBXDB6");
            Assert.IsFalse(res.Successful, "Calling UpdateDatabaseName with null parameter should fail:" + res);
            Assert.IsFalse(DbFunctions.CycleDatabaseConnection(),"Cycling database connection after setting invalid DB name should fail");
        }



        [TestMethod]
        public void CycleDatabaseConnection_Success()
        {
            var res=DbFunctions.UpdateDatabaseName("UnityDirDb");
            Assert.IsTrue(res.Successful,"Failed to attach to UnityDirDb:"+res);
            Assert.IsTrue(DbFunctions.CycleDatabaseConnection(), "Cycling database failed");
        }

        [TestMethod]
        public void CycleDatabaseConnection_Failure()
        {
            ConnectionInformixAdoNetDatabaseFunctions oTest = new ConnectionInformixAdoNetDatabaseFunctions("test");
            Assert.IsFalse(oTest.CycleDatabaseConnection(), "Cycling database without logging in first did not fail");
        }

    }
}

Commits for ConnectionOdbcSdk/trunk/ConnectionServerOdbcIntegrationTests/IntegrationTests/ConnectionInformixAdoNetDatabaseFunctionIntegrationTests.cs

Diff revisions: vs.
Revision Author Commited Message
12 Diff Diff jlindborg picture jlindborg Thu 05 Sep, 2013 01:56:48 +0000

more unit test work.

10 jlindborg picture jlindborg Mon 02 Sep, 2013 18:54:54 +0000

More unit and integration test work