public void Create_HasType_RepositoryCreated()
        {
            var applicationContextProvider = GetApplicationContextProvider();

            var sessionManagerProvider = GetSessionManagerProvider(new Mock <ISession>());

            var entityFactoryService = new EntityFactoryService(sessionManagerProvider.Object, new Mock <ISessionFactoryManager>().Object,
                                                                applicationContextProvider.Object);

            var repository = entityFactoryService.Create <object>();

            Assert.Pass();
        }
        public void CreateUnitOfWork_NoExceptions_UnitOfWorkCreated()
        {
            var applicationContextProvider = GetApplicationContextProvider();

            var sessionManagerProvider = GetSessionManagerProvider(new Mock <ISession>());

            var entityFactoryService = new EntityFactoryService(sessionManagerProvider.Object, new Mock <ISessionFactoryManager>().Object,
                                                                applicationContextProvider.Object);

            var uow = entityFactoryService.Create();

            Assert.Pass();
        }
        public void Create_NoHasType_Exception()
        {
            const string message = "No nick for the type";

            var applicationContextProvider = new Mock <IApplicationContextProvider>();

            applicationContextProvider.Setup(x => x.GetNick(It.IsAny <Type>()))
            .Throws(new ArgumentException(message));

            var sessionManagerProvider = GetSessionManagerProvider(new Mock <ISession>());

            var entityFactoryService = new EntityFactoryService(sessionManagerProvider.Object, new Mock <ISessionFactoryManager>().Object,
                                                                applicationContextProvider.Object);

            Assert.Throws <ArgumentException>(() => entityFactoryService.Create <object>(), message);
        }
        public void GetScopedSession_CreateRepository_SessionManagerGotFromScope()
        {
            var applicationContextProvider = GetApplicationContextProvider();

            var sessionManagerProvider = new Mock <ISessionManagerProvider>();

            var sessionFactoryManager = new Mock <ISessionFactoryManager>();
            var sessionFactory        = new Mock <ISessionFactory>();

            sessionFactory.Setup(x => x.OpenSession())
            .Returns(new Mock <ISession>().Object);
            sessionFactoryManager.Setup(x => x.GetSessionFactory(It.IsAny <string>()))
            .Returns(sessionFactory.Object);

            var entityFactoryService = new EntityFactoryService(sessionManagerProvider.Object, sessionFactoryManager.Object,
                                                                applicationContextProvider.Object);

            using (entityFactoryService.GetScopedSession())
            {
                var repository = entityFactoryService.Create <object>();
            }

            sessionManagerProvider.Verify(x => x.GetSessionManager(), Times.Never);
        }