Ejemplo n.º 1
0
        public void TestTextWithSpacesOnlyDoesNotSave()
        {
            EmailQueueV2 emailQueue = null;

            try
            {
                #region Arrange
                emailQueue        = GetValid(9);
                emailQueue.Action = " ";
                #endregion Arrange

                #region Act
                EmailQueueRepository.DbContext.BeginTransaction();
                EmailQueueRepository.EnsurePersistent(emailQueue);
                EmailQueueRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception)
            {
                Assert.IsNotNull(emailQueue);
                var results = emailQueue.ValidationResults().AsMessageList();
                results.AssertErrorsAre(string.Format("The {0} field is required.", "Action"));
                Assert.IsTrue(emailQueue.IsTransient());
                Assert.IsFalse(emailQueue.IsValid());
                throw;
            }
        }
Ejemplo n.º 2
0
        public void TestEmailWithInvalidEmailDoesNotSave()
        {
            EmailQueueV2 emailQueue = null;

            try
            {
                #region Arrange
                emailQueue       = GetValid(9);
                emailQueue.Email = "x@@x.com";
                #endregion Arrange

                #region Act
                EmailQueueRepository.DbContext.BeginTransaction();
                EmailQueueRepository.EnsurePersistent(emailQueue);
                EmailQueueRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception)
            {
                Assert.IsNotNull(emailQueue);
                var results = emailQueue.ValidationResults().AsMessageList();
                results.AssertErrorsAre(string.Format("The {0} field is not a valid e-mail address.", "Email"));
                Assert.IsTrue(emailQueue.IsTransient());
                Assert.IsFalse(emailQueue.IsValid());
                throw;
            }
        }
Ejemplo n.º 3
0
        public void TestEmailWithTooLongValueDoesNotSave()
        {
            EmailQueueV2 emailQueue = null;

            try
            {
                #region Arrange
                emailQueue       = GetValid(9);
                emailQueue.Email = string.Format("x{0}@x.x", "x".RepeatTimes((96)));
                #endregion Arrange

                #region Act
                EmailQueueRepository.DbContext.BeginTransaction();
                EmailQueueRepository.EnsurePersistent(emailQueue);
                EmailQueueRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception)
            {
                Assert.IsNotNull(emailQueue);
                Assert.AreEqual(100 + 1, emailQueue.Email.Length);
                var results = emailQueue.ValidationResults().AsMessageList();
                results.AssertErrorsAre(string.Format("The field {0} must be a string with a maximum length of {1}.", "Email", "100"));
                Assert.IsTrue(emailQueue.IsTransient());
                Assert.IsFalse(emailQueue.IsValid());
                throw;
            }
        }
Ejemplo n.º 4
0
        public void TestEmailQueueNewUserDoesNotSave()
        {
            var thisFar = false;

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

                #region Act
                EmailQueueRepository.DbContext.BeginTransaction();
                EmailQueueRepository.EnsurePersistent(record);
                EmailQueueRepository.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;
            }
        }
        public void TestStatusWithOneCharacterSaves()
        {
            #region Arrange
            var emailQueue = GetValid(9);
            emailQueue.Status = "x";
            #endregion Arrange

            #region Act
            EmailQueueRepository.DbContext.BeginTransaction();
            EmailQueueRepository.EnsurePersistent(emailQueue);
            EmailQueueRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.IsFalse(emailQueue.IsTransient());
            Assert.IsTrue(emailQueue.IsValid());
            #endregion Assert
        }
        public void TestEmailWithNullValueSaves()
        {
            #region Arrange
            var emailQueue = GetValid(9);
            emailQueue.Email = null;
            #endregion Arrange

            #region Act
            EmailQueueRepository.DbContext.BeginTransaction();
            EmailQueueRepository.EnsurePersistent(emailQueue);
            EmailQueueRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.IsFalse(emailQueue.IsTransient());
            Assert.IsTrue(emailQueue.IsValid());
            #endregion Assert
        }
Ejemplo n.º 7
0
        public void TestDetailsWithOneSpaceSaves()
        {
            #region Arrange
            var emailQueueV2 = GetValid(9);
            emailQueueV2.Details = " ";
            #endregion Arrange

            #region Act
            EmailQueueRepository.DbContext.BeginTransaction();
            EmailQueueRepository.EnsurePersistent(emailQueueV2);
            EmailQueueRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.IsFalse(emailQueueV2.IsTransient());
            Assert.IsTrue(emailQueueV2.IsValid());
            #endregion Assert
        }
        public void TestDateTimeSentWithNullValueWillSave()
        {
            #region Arrange
            EmailQueue record = GetValid(99);
            record.DateTimeSent = null;
            #endregion Arrange

            #region Act
            EmailQueueRepository.DbContext.BeginTransaction();
            EmailQueueRepository.EnsurePersistent(record);
            EmailQueueRepository.DbContext.CommitChanges();
            #endregion Act

            #region Assert
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            Assert.AreEqual(null, record.DateTimeSent);
            #endregion Assert
        }
        public void TestStatusWithLongValueSaves()
        {
            #region Arrange
            var emailQueue = GetValid(9);
            emailQueue.Status = "x".RepeatTimes(999);
            #endregion Arrange

            #region Act
            EmailQueueRepository.DbContext.BeginTransaction();
            EmailQueueRepository.EnsurePersistent(emailQueue);
            EmailQueueRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual(999, emailQueue.Status.Length);
            Assert.IsFalse(emailQueue.IsTransient());
            Assert.IsTrue(emailQueue.IsValid());
            #endregion Assert
        }
        public void TestPendingIsFalseSaves()
        {
            #region Arrange
            EmailQueue emailQueue = GetValid(9);
            emailQueue.Pending = false;
            #endregion Arrange

            #region Act
            EmailQueueRepository.DbContext.BeginTransaction();
            EmailQueueRepository.EnsurePersistent(emailQueue);
            EmailQueueRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.IsFalse(emailQueue.Pending);
            Assert.IsFalse(emailQueue.IsTransient());
            Assert.IsTrue(emailQueue.IsValid());
            #endregion Assert
        }
        public void TestEmailQueueWithExistingOrderSaves()
        {
            #region Arrange
            var record = GetValid(9);
            record.Order = OrderRepository.Queryable.Single(a => a.Id == 3);
            #endregion Arrange

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

            #region Assert
            Assert.AreEqual(3, record.Order.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
        public void TestEmailWithLongValueSaves()
        {
            #region Arrange
            var emailQueue = GetValid(9);
            emailQueue.Email = emailQueue.Email = string.Format("x{0}@x.x", "x".RepeatTimes((95)));
            #endregion Arrange

            #region Act
            EmailQueueRepository.DbContext.BeginTransaction();
            EmailQueueRepository.EnsurePersistent(emailQueue);
            EmailQueueRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual(100, emailQueue.Email.Length);
            Assert.IsFalse(emailQueue.IsTransient());
            Assert.IsTrue(emailQueue.IsValid());
            #endregion Assert
        }
        public void TestEmailQueueWithNullUserSaves()
        {
            #region Arrange
            var record = GetValid(9);
            record.User = null;
            #endregion Arrange

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

            #region Assert
            Assert.AreEqual(null, record.User);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
        public void TestDateTimeSentWithFutureDateDateWillSave()
        {
            #region Arrange
            var compareDate = DateTime.UtcNow.ToPacificTime().AddDays(15);
            var record      = GetValid(99);
            record.DateTimeSent = compareDate;
            #endregion Arrange

            #region Act
            EmailQueueRepository.DbContext.BeginTransaction();
            EmailQueueRepository.EnsurePersistent(record);
            EmailQueueRepository.DbContext.CommitChanges();
            #endregion Act

            #region Assert
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            Assert.AreEqual(compareDate, record.DateTimeSent);
            #endregion Assert
        }