1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using NUnit.Framework;
6 using DotNetMock.Framework.Data;
7
8 namespace clsLibTest2.TestAccessController
9 {
10 [TestFixture, Category("TestAccessController1")]
11 public class TestAccessController1
12 {
13 [Test]
14 public void TestValidUser()
15 {
16 MockLogger3 mocklogger3 = new MockLogger3();
17 mocklogger3.ExpectedName = "AccessControl";
18 mocklogger3.AddExpectedMsg("Checking access for dave to secrets");
19 mocklogger3.AddExpectedMsg("Access granted");
20
21 // set up the mock database
22 MockDbConnection mockconn = new MockDbConnection();
23 MockCommand mockcmd = new MockCommand();
24 MockDataReader mockdrd = new MockDataReader();
25
26 mockconn.SetExpectedCommand(mockcmd);
27 mockcmd.SetExpectedCommandText(AccessController1.CHECK_SQL);
28 mockcmd.SetExpectedExecuteCalls(1);
29 mockcmd.SetExpectedParameter(new MockDataParameter("@Name", "admin"));
30 mockcmd.SetExpectedParameter(new MockDataParameter("@Password", "admin"));
31 mockcmd.SetExpectedParameter(new MockDataParameter("@Power", "0"));
32
33 mockcmd.SetExpectedReader(mockdrd);
34 object[,] rows = new object[1, 1];
35 rows[0, 0] = 1;
36 mockdrd.SetRows(rows);
37
38 AccessController1 accessController1 = new AccessController1("0", mocklogger3, mockconn);
39 Assert.IsTrue(accessController1.CanAccess("admin", "admin"));
40 mocklogger3.Verify();
41 mockconn.Verify();
42 mockcmd.Verify();
43
44
45 }
46 }
47 }