public void TestApplicationRoleDeleteDoesNotCascadeToRole()
        {
            #region Arrange
            RoleRepository.DbContext.BeginTransaction();
            LoadRoles(3);
            RoleRepository.DbContext.CommitTransaction();
            var applicationRole = GetValid(9);
            applicationRole.Role = RoleRepository.GetById(2);

            var applicationRoleCount = ApplicationRoleRepository.Queryable.Count();

            ApplicationRoleRepository.DbContext.BeginTransaction();
            ApplicationRoleRepository.EnsurePersistent(applicationRole);
            ApplicationRoleRepository.DbContext.CommitTransaction();

            Assert.IsNotNull(applicationRole.Role);
            Assert.IsFalse(applicationRole.IsTransient());
            Assert.IsTrue(applicationRole.IsValid());
            Assert.AreEqual(applicationRoleCount + 1, ApplicationRoleRepository.Queryable.Count());
            #endregion Arrange

            #region Act
            ApplicationRoleRepository.DbContext.BeginTransaction();
            ApplicationRoleRepository.Remove(applicationRole);
            ApplicationRoleRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual(applicationRoleCount, ApplicationRoleRepository.Queryable.Count());
            Assert.AreEqual(3, RoleRepository.Queryable.Count());
            #endregion Assert
        }
        public void TestApplicationRoleWithNewRoleDoesNotSave()
        {
            ApplicationRole applicationRole = null;

            try
            {
                #region Arrange
                applicationRole      = GetValid(9);
                applicationRole.Role = new Role();
                #endregion Arrange

                #region Act
                ApplicationRoleRepository.DbContext.BeginTransaction();
                ApplicationRoleRepository.EnsurePersistent(applicationRole);
                ApplicationRoleRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception ex)
            {
                Assert.IsNotNull(applicationRole);
                Assert.IsNotNull(ex);
                Assert.AreEqual("object references an unsaved transient instance - save the transient instance before flushing. Type: Catbert4.Core.Domain.Role, Entity: Catbert4.Core.Domain.Role", ex.Message);
                throw;
            }
        }
        public void TestApplicationRoleWithMinValueSaves()
        {
            #region Arrange
            var applicationRole = GetValid(9);
            applicationRole.Level = int.MinValue;
            #endregion Arrange

            #region Act
            ApplicationRoleRepository.DbContext.BeginTransaction();
            ApplicationRoleRepository.EnsurePersistent(applicationRole);
            ApplicationRoleRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual(int.MinValue, applicationRole.Level);
            Assert.IsFalse(applicationRole.IsTransient());
            Assert.IsTrue(applicationRole.IsValid());
            #endregion Assert
        }
        public void TestApplicationRoleWithNullRoleSaves()
        {
            #region Arrange
            var applicationRole = GetValid(9);
            applicationRole.Role = null;
            #endregion Arrange

            #region Act
            ApplicationRoleRepository.DbContext.BeginTransaction();
            ApplicationRoleRepository.EnsurePersistent(applicationRole);
            ApplicationRoleRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.IsNull(applicationRole.Role);
            Assert.IsFalse(applicationRole.IsTransient());
            Assert.IsTrue(applicationRole.IsValid());
            #endregion Assert
        }
        public void TestApplicationRoleWithExistingRoleSaves()
        {
            #region Arrange
            RoleRepository.DbContext.BeginTransaction();
            LoadRoles(1);
            RoleRepository.DbContext.CommitTransaction();
            var applicationRole = GetValid(9);
            applicationRole.Role = RoleRepository.GetById(1);
            #endregion Arrange

            #region Act
            ApplicationRoleRepository.DbContext.BeginTransaction();
            ApplicationRoleRepository.EnsurePersistent(applicationRole);
            ApplicationRoleRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.IsNotNull(applicationRole.Role);
            Assert.AreEqual("Name1", applicationRole.Role.Name);
            Assert.IsFalse(applicationRole.IsTransient());
            Assert.IsTrue(applicationRole.IsValid());
            #endregion Assert
        }