Пример #1
0
        public void TestAccountDataWithSpacesOnlyDoesNotSave()
        {
            OrderRequestSave orderRequestSave = null;

            try
            {
                #region Arrange
                orderRequestSave             = GetValid(9);
                orderRequestSave.AccountData = " ";
                #endregion Arrange

                #region Act
                OrderRequestSaveRepository.DbContext.BeginTransaction();
                OrderRequestSaveRepository.EnsurePersistent(orderRequestSave);
                OrderRequestSaveRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception)
            {
                Assert.IsNotNull(orderRequestSave);
                var results = orderRequestSave.ValidationResults().AsMessageList();
                results.AssertErrorsAre(string.Format("The {0} field is required.", "AccountData"));
                Assert.IsFalse(orderRequestSave.IsValid());
                throw;
            }
        }
Пример #2
0
        public void TestOrderRequestSaveNewWorkgroupDoesNotSave()
        {
            var thisFar = false;

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

                #region Act
                OrderRequestSaveRepository.DbContext.BeginTransaction();
                OrderRequestSaveRepository.EnsurePersistent(record);
                OrderRequestSaveRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception ex)
            {
                Assert.IsTrue(thisFar);
                Assert.IsNotNull(ex);
                Assert.IsTrue(ex.Message.Contains("Entity: Purchasing.Core.Domain.Workgroup"));
                Assert.IsTrue(ex.Message.Contains("Type: Purchasing.Core.Domain.Workgroup"));
                throw;
            }
        }
Пример #3
0
        public void TestOrderRequestSavesFieldWorkgroupWithAValueOfNullDoesNotSave()
        {
            OrderRequestSave record = null;

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

                #region Act
                OrderRequestSaveRepository.DbContext.BeginTransaction();
                OrderRequestSaveRepository.EnsurePersistent(record);
                OrderRequestSaveRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception)
            {
                Assert.IsNotNull(record);
                Assert.AreEqual(record.Workgroup, null);
                var results = record.ValidationResults().AsMessageList();
                results.AssertErrorsAre("The Workgroup field is required.");
                Assert.IsFalse(record.IsValid());
                throw;
            }
        }
Пример #4
0
        public void TestNameWithTooLongValueDoesNotSave()
        {
            OrderRequestSave orderRequestSave = null;

            try
            {
                #region Arrange
                orderRequestSave      = GetValid(9);
                orderRequestSave.Name = "x".RepeatTimes((150 + 1));
                #endregion Arrange

                #region Act
                OrderRequestSaveRepository.DbContext.BeginTransaction();
                OrderRequestSaveRepository.EnsurePersistent(orderRequestSave);
                OrderRequestSaveRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception)
            {
                Assert.IsNotNull(orderRequestSave);
                Assert.AreEqual(150 + 1, orderRequestSave.Name.Length);
                var results = orderRequestSave.ValidationResults().AsMessageList();
                results.AssertErrorsAre(string.Format("The field {0} must be a string with a maximum length of {1}.", "Name", "150"));
                Assert.IsFalse(orderRequestSave.IsValid());
                throw;
            }
        }
Пример #5
0
        public void TestAccountDataWithOneCharacterSaves()
        {
            #region Arrange
            var orderRequestSave = GetValid(9);
            orderRequestSave.AccountData = "x";
            #endregion Arrange

            #region Act
            OrderRequestSaveRepository.DbContext.BeginTransaction();
            OrderRequestSaveRepository.EnsurePersistent(orderRequestSave);
            OrderRequestSaveRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.IsFalse(orderRequestSave.IsTransient());
            Assert.IsTrue(orderRequestSave.IsValid());
            #endregion Assert
        }
Пример #6
0
        public void TestAccountDataWithLongValueSaves()
        {
            #region Arrange
            var orderRequestSave = GetValid(9);
            orderRequestSave.AccountData = "x".RepeatTimes(999);
            #endregion Arrange

            #region Act
            OrderRequestSaveRepository.DbContext.BeginTransaction();
            OrderRequestSaveRepository.EnsurePersistent(orderRequestSave);
            OrderRequestSaveRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual(999, orderRequestSave.AccountData.Length);
            Assert.IsFalse(orderRequestSave.IsTransient());
            Assert.IsTrue(orderRequestSave.IsValid());
            #endregion Assert
        }
Пример #7
0
        public void TestOrderRequestSaveWithExistingWorkgroupSaves()
        {
            #region Arrange
            var record = GetValid(9);
            record.Workgroup = WorkgroupRepository.Queryable.Single(a => a.Id == 3);
            #endregion Arrange

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

            #region Assert
            Assert.AreEqual(3, record.Workgroup.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
Пример #8
0
        public void TestOrderRequestSaveWithNullPreparedBySaves()
        {
            #region Arrange
            var record = GetValid(9);
            record.PreparedBy = null;
            #endregion Arrange

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

            #region Assert
            Assert.AreEqual(null, record.PreparedBy);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
Пример #9
0
        public void TestLastUpdateWithPastDateWillSave()
        {
            #region Arrange
            var compareDate         = DateTime.UtcNow.ToPacificTime().AddDays(-10);
            OrderRequestSave record = GetValid(99);
            record.LastUpdate = compareDate;
            #endregion Arrange

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

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