コード例 #1
0
        public void TestOrganizationWithNewValueDoesNotSave()
        {
            var thisFar = false;

            try
            {
                #region Arrange
                var record = GetValid(9);
                record.Organization = CreateValidEntities.Organization(99);
                thisFar             = true;
                #endregion Arrange

                #region Act
                ConditionalApprovalRepository.DbContext.BeginTransaction();
                ConditionalApprovalRepository.EnsurePersistent(record);
                ConditionalApprovalRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception ex)
            {
                Assert.IsTrue(thisFar);
                Assert.IsNotNull(ex);
                Assert.AreEqual("object references an unsaved transient instance - save the transient instance before flushing or set cascade action for the property to something that would make it autosave. Type: Purchasing.Core.Domain.Organization, Entity: Purchasing.Core.Domain.Organization", ex.Message);
                throw;
            }
        }
コード例 #2
0
        public void TestPrimaryApproverWithAValueOfNullDoesNotSave()
        {
            ConditionalApproval record = null;

            try
            {
                #region Arrange
                record = GetValid(9);
                record.PrimaryApprover = null;
                #endregion Arrange

                #region Act
                ConditionalApprovalRepository.DbContext.BeginTransaction();
                ConditionalApprovalRepository.EnsurePersistent(record);
                ConditionalApprovalRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception)
            {
                Assert.IsNotNull(record);
                Assert.AreEqual(record.PrimaryApprover, null);
                var results = record.ValidationResults().AsMessageList();
                results.AssertErrorsAre("The PrimaryApprover field is required.");
                Assert.IsTrue(record.IsTransient());
                Assert.IsFalse(record.IsValid());
                throw;
            }
        }
コード例 #3
0
        public void TestWorkgroupWithExistingValueSaves()
        {
            #region Arrange
            var workgroupRepository = new Repository <Workgroup>();
            workgroupRepository.DbContext.BeginTransaction();
            LoadOrganizations(3);
            LoadWorkgroups(3);
            workgroupRepository.DbContext.CommitTransaction();

            var record = GetValid(9);
            record.Workgroup = workgroupRepository.Queryable.Single(a => a.Id == 2);
            #endregion Arrange

            #region Act
            ConditionalApprovalRepository.DbContext.BeginTransaction();
            ConditionalApprovalRepository.EnsurePersistent(record);
            ConditionalApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual(2, record.Workgroup.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
コード例 #4
0
        public void TestQuestionWithSpacesOnlyDoesNotSave()
        {
            ConditionalApproval conditionalApproval = null;

            try
            {
                #region Arrange
                conditionalApproval          = GetValid(9);
                conditionalApproval.Question = " ";
                #endregion Arrange

                #region Act
                ConditionalApprovalRepository.DbContext.BeginTransaction();
                ConditionalApprovalRepository.EnsurePersistent(conditionalApproval);
                ConditionalApprovalRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception)
            {
                Assert.IsNotNull(conditionalApproval);
                var results = conditionalApproval.ValidationResults().AsMessageList();
                results.AssertErrorsAre(string.Format("The {0} field is required.", "Question"));
                Assert.IsTrue(conditionalApproval.IsTransient());
                Assert.IsFalse(conditionalApproval.IsValid());
                throw;
            }
        }
コード例 #5
0
        public void TestQuestionWithOneCharacterSaves()
        {
            #region Arrange
            var conditionalApproval = GetValid(9);
            conditionalApproval.Question = "x";
            #endregion Arrange

            #region Act
            ConditionalApprovalRepository.DbContext.BeginTransaction();
            ConditionalApprovalRepository.EnsurePersistent(conditionalApproval);
            ConditionalApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.IsFalse(conditionalApproval.IsTransient());
            Assert.IsTrue(conditionalApproval.IsValid());
            #endregion Assert
        }
コード例 #6
0
        public void TestOrganizationWithNullValueSaves()
        {
            #region Arrange
            var record = GetValid(9);
            record.Organization = null;
            #endregion Arrange

            #region Act
            ConditionalApprovalRepository.DbContext.BeginTransaction();
            ConditionalApprovalRepository.EnsurePersistent(record);
            ConditionalApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual(null, record.Organization);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
コード例 #7
0
        public void TestSecondaryApproverWithExistingUserSaves()
        {
            #region Arrange
            var record = GetValid(9);
            record.SecondaryApprover = UserRepository.Queryable.Single(a => a.Id == "1");
            #endregion Arrange

            #region Act
            ConditionalApprovalRepository.DbContext.BeginTransaction();
            ConditionalApprovalRepository.EnsurePersistent(record);
            ConditionalApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual("1", record.SecondaryApprover.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
コード例 #8
0
        public void TestQuestionWithLongValueSaves()
        {
            #region Arrange
            var conditionalApproval = GetValid(9);
            conditionalApproval.Question = "x".RepeatTimes(999);
            #endregion Arrange

            #region Act
            ConditionalApprovalRepository.DbContext.BeginTransaction();
            ConditionalApprovalRepository.EnsurePersistent(conditionalApproval);
            ConditionalApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual(999, conditionalApproval.Question.Length);
            Assert.IsFalse(conditionalApproval.IsTransient());
            Assert.IsTrue(conditionalApproval.IsValid());
            #endregion Assert
        }
コード例 #9
0
        public void TestOrganizationWithExistingValueSaves()
        {
            #region Arrange
            var organizationRepository = new RepositoryWithTypedId <Organization, string>();
            organizationRepository.DbContext.BeginTransaction();
            LoadOrganizations(3);
            organizationRepository.DbContext.CommitTransaction();

            var record = GetValid(9);
            record.Organization = organizationRepository.Queryable.Single(a => a.Id == "2");
            #endregion Arrange

            #region Act
            ConditionalApprovalRepository.DbContext.BeginTransaction();
            ConditionalApprovalRepository.EnsurePersistent(record);
            ConditionalApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual("2", record.Organization.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
コード例 #10
0
        public void TestWithNewSecondaryApproverUserDoesNotCascadeSave()
        {
            var thisFar = false;

            try
            {
                #region Arrange
                var record = GetValid(9);
                record.SecondaryApprover = new User("NoOne");
                #endregion Arrange

                #region Act
                ConditionalApprovalRepository.DbContext.BeginTransaction();
                thisFar = true;
                ConditionalApprovalRepository.EnsurePersistent(record);
                ConditionalApprovalRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception)
            {
                Assert.IsTrue(thisFar);
                throw;
            }
        }