public void TestKfsDocumentNewOrderDoesNotSave() { var thisFar = false; try { #region Arrange var record = GetValid(9); record.Order = new Order(); thisFar = true; #endregion Arrange #region Act KfsDocumentRepository.DbContext.BeginTransaction(); KfsDocumentRepository.EnsurePersistent(record); KfsDocumentRepository.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 TestKfsDocumentsFieldOrderWithAValueOfNullDoesNotSave() { KfsDocument record = null; try { #region Arrange record = GetValid(9); record.Order = null; #endregion Arrange #region Act KfsDocumentRepository.DbContext.BeginTransaction(); KfsDocumentRepository.EnsurePersistent(record); KfsDocumentRepository.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 TestDocNumberWithTooLongValueDoesNotSave() { KfsDocument kfsDocument = null; try { #region Arrange kfsDocument = GetValid(9); kfsDocument.DocNumber = "x".RepeatTimes((50 + 1)); #endregion Arrange #region Act KfsDocumentRepository.DbContext.BeginTransaction(); KfsDocumentRepository.EnsurePersistent(kfsDocument); KfsDocumentRepository.DbContext.CommitTransaction(); #endregion Act } catch (Exception) { Assert.IsNotNull(kfsDocument); Assert.AreEqual(50 + 1, kfsDocument.DocNumber.Length); var results = kfsDocument.ValidationResults().AsMessageList(); results.AssertErrorsAre(string.Format("The field {0} must be a string with a maximum length of {1}.", "DocNumber", "50")); Assert.IsTrue(kfsDocument.IsTransient()); Assert.IsFalse(kfsDocument.IsValid()); throw; } }
public void TestDocNumberWithSpacesOnlyDoesNotSave() { KfsDocument kfsDocument = null; try { #region Arrange kfsDocument = GetValid(9); kfsDocument.DocNumber = " "; #endregion Arrange #region Act KfsDocumentRepository.DbContext.BeginTransaction(); KfsDocumentRepository.EnsurePersistent(kfsDocument); KfsDocumentRepository.DbContext.CommitTransaction(); #endregion Act } catch (Exception) { Assert.IsNotNull(kfsDocument); var results = kfsDocument.ValidationResults().AsMessageList(); results.AssertErrorsAre(string.Format("The {0} field is required.", "DocNumber")); Assert.IsTrue(kfsDocument.IsTransient()); Assert.IsFalse(kfsDocument.IsValid()); throw; } }
public void TestDocNumberWithOneCharacterSaves() { #region Arrange var kfsDocument = GetValid(9); kfsDocument.DocNumber = "x"; #endregion Arrange #region Act KfsDocumentRepository.DbContext.BeginTransaction(); KfsDocumentRepository.EnsurePersistent(kfsDocument); KfsDocumentRepository.DbContext.CommitTransaction(); #endregion Act #region Assert Assert.IsFalse(kfsDocument.IsTransient()); Assert.IsTrue(kfsDocument.IsValid()); #endregion Assert }
public void TestKfsDocumentWithExistingOrderSaves() { #region Arrange var record = GetValid(9); record.Order = OrderRepository.Queryable.Single(a => a.Id == 3); #endregion Arrange #region Act KfsDocumentRepository.DbContext.BeginTransaction(); KfsDocumentRepository.EnsurePersistent(record); KfsDocumentRepository.DbContext.CommitTransaction(); #endregion Act #region Assert Assert.AreEqual(3, record.Order.Id); Assert.IsFalse(record.IsTransient()); Assert.IsTrue(record.IsValid()); #endregion Assert }
public void TestDocNumberWithLongValueSaves() { #region Arrange var kfsDocument = GetValid(9); kfsDocument.DocNumber = "x".RepeatTimes(50); #endregion Arrange #region Act KfsDocumentRepository.DbContext.BeginTransaction(); KfsDocumentRepository.EnsurePersistent(kfsDocument); KfsDocumentRepository.DbContext.CommitTransaction(); #endregion Act #region Assert Assert.AreEqual(50, kfsDocument.DocNumber.Length); Assert.IsFalse(kfsDocument.IsTransient()); Assert.IsTrue(kfsDocument.IsValid()); #endregion Assert }