Esempio n. 1
0
        public void TestApprovalNewSplitDoesNotSave()
        {
            var thisFar = false;

            try
            {
                #region Arrange
                var record = GetValid(9);
                record.Split = new Split();
                thisFar      = true;
                #endregion Arrange

                #region Act
                ApprovalRepository.DbContext.BeginTransaction();
                ApprovalRepository.EnsurePersistent(record);
                ApprovalRepository.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.Split, Entity: Purchasing.Core.Domain.Split", ex.Message);
                throw;
            }
        }
Esempio n. 2
0
        public void TestApprovalWithNullOrderDoesNotSave()
        {
            var      thisFar = false;
            Approval record  = null;

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

                thisFar = true;
                #endregion Arrange

                #region Act
                ApprovalRepository.DbContext.BeginTransaction();
                ApprovalRepository.EnsurePersistent(record);
                ApprovalRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception)
            {
                Assert.IsTrue(thisFar);
                Assert.AreEqual(record.Order, null);
                var results = record.ValidationResults().AsMessageList();
                results.AssertErrorsAre("The Order field is required.");
                Assert.IsTrue(record.IsTransient());
                Assert.IsFalse(record.IsValid());
                throw;
            }
        }
Esempio n. 3
0
        public void TestIsExternalIsTrueSaves()
        {
            #region Arrange
            var approval = GetValid(9);
            approval.IsExternal = true;
            #endregion Arrange

            #region Act
            ApprovalRepository.DbContext.BeginTransaction();
            ApprovalRepository.EnsurePersistent(approval);
            ApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.IsTrue(approval.IsExternal);
            Assert.IsFalse(approval.IsTransient());
            Assert.IsTrue(approval.IsValid());
            #endregion Assert
        }
Esempio n. 4
0
        public void TestApprovalWithNullSplitSaves()
        {
            #region Arrange
            var record = GetValid(9);
            record.Split = null;
            #endregion Arrange

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

            #region Assert
            Assert.AreEqual(null, record.Split);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
Esempio n. 5
0
        public void TestApprovalWithExistingOrderSaves()
        {
            #region Arrange
            var record = GetValid(9);
            record.Order = Repository.OfType <Order>().Queryable.Single(a => a.Id == 2);
            #endregion Arrange

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

            #region Assert
            Assert.AreEqual(2, record.Order.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
Esempio n. 6
0
        public void TestCompletedIsFalseSaves()
        {
            #region Arrange
            Approval approval = GetValid(9);
            approval.Completed = false;
            #endregion Arrange

            #region Act
            ApprovalRepository.DbContext.BeginTransaction();
            ApprovalRepository.EnsurePersistent(approval);
            ApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.IsFalse(approval.Completed);
            Assert.IsFalse(approval.IsTransient());
            Assert.IsTrue(approval.IsValid());
            #endregion Assert
        }
Esempio n. 7
0
        public void TestApprovalWithExistingStatusCodeSaves()
        {
            #region Arrange
            var orderStatusCodeRepository = new RepositoryWithTypedId <OrderStatusCode, string>();
            var record = GetValid(9);
            record.StatusCode = orderStatusCodeRepository.Queryable.Single(a => a.Id == "2");
            #endregion Arrange

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

            #region Assert
            Assert.AreEqual("2", record.StatusCode.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
Esempio n. 8
0
        public void TestApprovalWithExistingSplitSaves()
        {
            #region Arrange
            SplitRepository.DbContext.BeginTransaction();
            LoadSplits(3);
            SplitRepository.DbContext.CommitTransaction();
            var record = GetValid(9);
            record.Split = SplitRepository.Queryable.Single(a => a.Id == 3);
            #endregion Arrange

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

            #region Assert
            Assert.AreEqual(3, record.Split.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
Esempio n. 9
0
        public void TestApprovalWithExistingSecondaryUserSaves()
        {
            #region Arrange
            var userRepository = new RepositoryWithTypedId <User, string>();
            userRepository.DbContext.BeginTransaction();
            LoadUsers(3);
            userRepository.DbContext.CommitTransaction();
            var record = GetValid(9);
            record.SecondaryUser = userRepository.Queryable.Single(a => a.Id == "2");
            #endregion Arrange

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

            #region Assert
            Assert.AreEqual("2", record.SecondaryUser.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }