예제 #1
0
        public void CreateNewGroup_DBException_ReturnsException()
        {
            var userId = 10;
            var groupName = "brandnewgroup";

            
            var cache = GetGroupsCache(_mocks);

            var reader = _mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.Execute()).Throw(new Exception("createnewusergroup"));
            var creator = _mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("createnewusergroup")).Return(reader);
            var diag = _mocks.DynamicMock<IDnaDiagnostics>();
            _mocks.ReplayAll();

            var obj = new UserGroups(creator, diag, cache, null, null);

            bool exceptionThrown = false;
            try
            {
            
                obj.CreateNewGroup(groupName, userId);
            }
            catch(Exception e)
            {
                exceptionThrown = true;
                Assert.AreEqual("createnewusergroup", e.Message);
            }
            Assert.IsTrue(exceptionThrown);

        }
예제 #2
0
        public void CreateNewGroup_NewGroup_GroupAdded()
        {
            var userId = 6;
            var groupName = "neweditor";
            var groupId = 10;


            var cache = GetGroupsCache(_mocks);

            var reader = _mocks.DynamicMock<IDnaDataReader>();
            reader.Stub(x => x.Read()).Return(true);
            reader.Stub(x => x.GetInt32("newid")).Return(groupId);
            var creator = _mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("createnewusergroup")).Return(reader);
            var diag = _mocks.DynamicMock<IDnaDiagnostics>();
            _mocks.ReplayAll();

            var obj = new UserGroups(creator, diag, cache, null, null);

            Assert.IsTrue(obj.CreateNewGroup(groupName, userId));
            Assert.IsTrue(obj.GetAllGroups().Exists(x => x.Name == groupName));

            creator.AssertWasCalled(x => x.CreateDnaDataReader("createnewusergroup"));
        }
예제 #3
0
        public void CreateNewGroup_NewGroup_CorrectlyAddsGroup()
        {
            var userId = 10;
            var groupName = "newgroup";

            var cache = GetGroupsCache(_mocks);

            var reader = _mocks.DynamicMock<IDnaDataReader>();
            var creator = _mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("createnewusergroup")).Return(reader);
            var diag = _mocks.DynamicMock<IDnaDiagnostics>();
            _mocks.ReplayAll();

            var obj = new UserGroups(creator, diag, cache, null, null);

            Assert.IsTrue(obj.CreateNewGroup(groupName, userId));
            Assert.IsTrue(obj.GetAllGroups().Exists(x => x.Name == groupName));

        }