public void TestOrderCommentNewOrderDoesNotSave()
        {
            var thisFar = false;

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

                #region Act
                OrderCommentRepository.DbContext.BeginTransaction();
                OrderCommentRepository.EnsurePersistent(record);
                OrderCommentRepository.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.Order, Entity: Purchasing.Core.Domain.Order", ex.Message);
                throw;
            }
        }
        public void TestOrderCommentsFieldOrderWithAValueOfNullDoesNotSave()
        {
            OrderComment record = null;

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

                #region Act
                OrderCommentRepository.DbContext.BeginTransaction();
                OrderCommentRepository.EnsurePersistent(record);
                OrderCommentRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception)
            {
                Assert.IsNotNull(record);
                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;
            }
        }
        public void TestTextWithSpacesOnlyDoesNotSave()
        {
            OrderComment orderComment = null;

            try
            {
                #region Arrange
                orderComment      = GetValid(9);
                orderComment.Text = " ";
                #endregion Arrange

                #region Act
                OrderCommentRepository.DbContext.BeginTransaction();
                OrderCommentRepository.EnsurePersistent(orderComment);
                OrderCommentRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception)
            {
                Assert.IsNotNull(orderComment);
                var results = orderComment.ValidationResults().AsMessageList();
                results.AssertErrorsAre(string.Format("The {0} field is required.", "Text"));
                Assert.IsTrue(orderComment.IsTransient());
                Assert.IsFalse(orderComment.IsValid());
                throw;
            }
        }
        public void TestTextWithOneCharacterSaves()
        {
            #region Arrange
            var orderComment = GetValid(9);
            orderComment.Text = "x";
            #endregion Arrange

            #region Act
            OrderCommentRepository.DbContext.BeginTransaction();
            OrderCommentRepository.EnsurePersistent(orderComment);
            OrderCommentRepository.DbContext.CommitTransaction();
            #endregion Act

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

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

            #region Assert
            Assert.AreEqual(3, record.Order.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
        public void TestTextWithLongValueSaves()
        {
            #region Arrange
            var orderComment = GetValid(9);
            orderComment.Text = "x".RepeatTimes(999);
            #endregion Arrange

            #region Act
            OrderCommentRepository.DbContext.BeginTransaction();
            OrderCommentRepository.EnsurePersistent(orderComment);
            OrderCommentRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual(999, orderComment.Text.Length);
            Assert.IsFalse(orderComment.IsTransient());
            Assert.IsTrue(orderComment.IsValid());
            #endregion Assert
        }
        public void TestDateCreatedWithFutureDateDateWillSave()
        {
            #region Arrange
            var compareDate = DateTime.UtcNow.ToPacificTime().AddDays(15);
            var record      = GetValid(99);
            record.DateCreated = compareDate;
            #endregion Arrange

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

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