Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using Rhino.Mocks;
- namespace TestProject1
- {
- /// <summary>
- /// Summary description for UnitTest8
- /// </summary>
- [TestClass]
- public class UnitTest8
- {
- private const int ValidId = 4711;
- private const int InvalidId = 0;
- private MockRepository mockRepository;
- private ISessionFactory sessionFactory;
- private ISession session;
- private LockClassPanelController controller;
- /// <summary>
- ///Gets or sets the test context which provides
- ///information about and functionality for the current test run.
- ///</summary>
- public TestContext TestContext { get; set; }
- [TestInitialize]
- public void Setup()
- {
- mockRepository = new MockRepository();
- sessionFactory = mockRepository.StrictMock<ISessionFactory>();
- session = mockRepository.StrictMock<ISession>();
- }
- #region Additional test attributes
- //
- // You can use the following additional attributes as you write your tests:
- //
- // Use ClassInitialize to run code before running the first test in the class
- // [ClassInitialize()]
- // public static void MyClassInitialize(TestContext testContext) { }
- //
- // Use ClassCleanup to run code after all tests in a class have run
- // [ClassCleanup()]
- // public static void MyClassCleanup() { }
- //
- // Use TestInitialize to run code before running each test
- // [TestInitialize()]
- // public void MyTestInitialize() { }
- //
- // Use TestCleanup to run code after each test has run
- // [TestCleanup()]
- // public void MyTestCleanup() { }
- //
- #endregion
- [TestMethod]
- public void AddLockClassWithNullNameShouldCallInsertOnSessionWithEmptyString()
- {
- LockClass lockClass = new LockClass { Id = ValidId, Name = null };
- using (mockRepository.Record())
- {
- sessionFactory.CreateSession();
- LastCall.Return(session);
- session.InsertWithId(lockClass);
- LastCall.Return(lockClass);
- session.Commit();
- session.Dispose();
- }
- using (mockRepository.Playback())
- {
- controller = new LockClassPanelController(sessionFactory);
- controller.AddLockClass(lockClass.Id, string.Empty);
- }
- mockRepository.VerifyAll();
- }
- }
- internal class LockClassPanelController
- {
- private readonly ISessionFactory sessionFactory;
- public LockClassPanelController(ISessionFactory sessionFactory)
- {
- this.sessionFactory = sessionFactory;
- }
- public void AddLockClass(int id, string name)
- {
- if (id != 0)
- {
- using (var session = sessionFactory.CreateSession())
- {
- session.InsertWithId(new LockClass { Id = id, Name = name });
- session.Commit();
- }
- //LoadLockClasses();
- //view.Initialize();
- }
- }
- }
- public interface ISession : IDisposable
- {
- LockClass InsertWithId(LockClass lockClass);
- void Commit();
- void Dispose();
- }
- public interface ISessionFactory
- {
- ISession CreateSession();
- }
- public class LockClass
- {
- public int Id { get; set; }
- public string Name { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement