Example #1
0
        public void TestWorkgroupAccountsFieldAccountWithAValueOfNullDoesNotSave()
        {
            WorkgroupAccount record = null;

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

                #region Act
                WorkgroupAccountRepository.DbContext.BeginTransaction();
                WorkgroupAccountRepository.EnsurePersistent(record);
                WorkgroupAccountRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception)
            {
                Assert.IsNotNull(record);
                Assert.AreEqual(record.Account, null);
                var results = record.ValidationResults().AsMessageList();
                results.AssertErrorsAre("The Account field is required.");
                Assert.IsTrue(record.IsTransient());
                Assert.IsFalse(record.IsValid());
                throw;
            }
        }
Example #2
0
        public void TestWorkgroupAccountNewPurchaserDoesNotSave()
        {
            var thisFar = false;

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

                #region Act
                WorkgroupAccountRepository.DbContext.BeginTransaction();
                WorkgroupAccountRepository.EnsurePersistent(record);
                WorkgroupAccountRepository.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.User, Entity: Purchasing.Core.Domain.User", ex.Message);
                throw;
            }
        }
Example #3
0
        public void TestWorkgroupAccountWithNullPurchaserSaves()
        {
            #region Arrange
            var record = GetValid(9);
            record.Purchaser = null;
            #endregion Arrange

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

            #region Assert
            Assert.AreEqual(null, record.Purchaser);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
Example #4
0
        public void TestWorkgroupAccountWithExistingPurchaserSaves()
        {
            #region Arrange
            var record = GetValid(9);
            record.Purchaser = UserRepository.Queryable.Single(a => a.Id == "3");
            #endregion Arrange

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

            #region Assert
            Assert.AreEqual("3", record.Purchaser.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
Example #5
0
        public void TestWorkgroupAccountWithExistingWorkgroupSaves()
        {
            #region Arrange
            var record = GetValid(9);
            record.Workgroup = Repository.OfType <Workgroup>().Queryable.Single(a => a.Id == 3);
            #endregion Arrange

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

            #region Assert
            Assert.AreEqual(3, record.Workgroup.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }