public void Test_CommitTransaction_WithAutoIncrementBo_ShouldUseNumberGeneratorsInDatastore() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); IClassDef classDef = TestAutoInc.LoadClassDefWithAutoIncrementingID(); DataStoreInMemory dataStore = MockRepository.GeneratePartialMock <DataStoreInMemory>(); dataStore.Replay(); int nextAutoIncNumber = TestUtil.GetRandomInt(); dataStore.Stub(t => t.GetNextAutoIncrementingNumber(classDef)).Return(nextAutoIncNumber); ITransactionCommitter transactionCommitter = new TransactionCommitterInMemory(dataStore); TestAutoInc bo = new TestAutoInc(); bo.SetPropertyValue("testfield", "testing 123"); transactionCommitter.AddBusinessObject(bo); //---------------Assert Precondition---------------- Assert.IsFalse(bo.TestAutoIncID.HasValue); Assert.AreSame(classDef, bo.ClassDef); Assert.IsTrue(bo.Props.HasAutoIncrementingField); //---------------Execute Test ---------------------- transactionCommitter.CommitTransaction(); //---------------Test Result ----------------------- dataStore.AssertWasCalled(memory => memory.GetNextAutoIncrementingNumber(classDef)); Assert.IsNotNull(bo.TestAutoIncID); Assert.AreEqual(nextAutoIncNumber, bo.TestAutoIncID); Assert.IsFalse(bo.Status.IsDirty); }
public void Test_InitialiseProp_InvalidBusinessObject_IDNotGuid() { //---------------Set up test pack------------------- TestAutoInc.LoadClassDefWithAutoIncrementingID(); BOProp boProp = new BOProp(_propDef); //Use auto incrementing because it is the only bo prop that has TestAutoInc bo = new TestAutoInc(); bo.SetPropertyValue("testautoincid", 1); //---------------Assert Precondition---------------- Assert.IsNull(boProp.Value); //---------------Execute Test ---------------------- try { boProp.InitialiseProp(bo); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { StringAssert.Contains(boProp.PropertyName + " cannot be set to " + bo.ToString(), ex.Message); StringAssert.Contains("It is not a type of ", ex.Message); StringAssert.Contains("Guid", ex.Message); Assert.AreEqual(null, boProp.Value); Assert.IsTrue(boProp.IsValid); } }
public void Test_CommitTransaction_WithAutoIncrementBo_ShouldAutoIncrementAfterInsert() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); TestAutoInc.LoadClassDefWithAutoIncrementingID(); DataStoreInMemory dataStore = new DataStoreInMemory(); ITransactionCommitter transactionCommitter = new TransactionCommitterInMemory(dataStore); TestAutoInc bo = new TestAutoInc(); bo.SetPropertyValue("testfield", "testing 123"); transactionCommitter.AddBusinessObject(bo); //---------------Assert Precondition---------------- Assert.IsFalse(bo.TestAutoIncID.HasValue); //---------------Execute Test ---------------------- transactionCommitter.CommitTransaction(); //---------------Test Result ----------------------- Assert.IsNotNull(bo.TestAutoIncID); Assert.AreNotEqual(0, bo.TestAutoIncID); Assert.IsFalse(bo.Status.IsDirty); }
public void TestSaveUpdatesAutoIncrementingField() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); TestAutoInc.LoadClassDefWithAutoIncrementingID(); var newIds = new ConcurrentBag<int?>(); //---------------Execute Test ---------------------- Parallel.For(0, 1000, i => { //---------------Set up test pack------------------- var bo = new TestAutoInc(); bo.SetPropertyValue("testfield", "testing 123"); //---------------Assert Precondition---------------- Assert.IsFalse(bo.TestAutoIncID.HasValue); //---------------Execute Test ---------------------- bo.Save(); //---------------Test Result ----------------------- newIds.Add(bo.TestAutoIncID); }); //---------------Test Result ----------------------- Assert.IsTrue(newIds.All(i => i.HasValue)); Assert.IsTrue(newIds.All(i => i > 0)); Assert.That(newIds.Distinct().Count(), Is.EqualTo(1000), "Every generated ID must be unique"); }
public void TestSaveUpdatesAutoIncrementingField() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); TestAutoInc.LoadClassDefWithAutoIncrementingID(); var newIds = new ConcurrentBag <int?>(); //---------------Execute Test ---------------------- Parallel.For(0, 1000, i => { //---------------Set up test pack------------------- var bo = new TestAutoInc(); bo.SetPropertyValue("testfield", "testing 123"); //---------------Assert Precondition---------------- Assert.IsFalse(bo.TestAutoIncID.HasValue); //---------------Execute Test ---------------------- bo.Save(); //---------------Test Result ----------------------- newIds.Add(bo.TestAutoIncID); }); //---------------Test Result ----------------------- Assert.IsTrue(newIds.All(i => i.HasValue)); Assert.IsTrue(newIds.All(i => i > 0)); Assert.That(newIds.Distinct().Count(), Is.EqualTo(1000), "Every generated ID must be unique"); }
public void TestSetPropertyValueFieldDoesNotExist() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); TestAutoInc.LoadClassDefWithAutoIncrementingID(); TestAutoInc bo = new TestAutoInc(); //---------------Execute Test ---------------------- const string nonexistentPropName = "nonExistent"; try { bo.SetPropertyValue(nonexistentPropName, "testing 123"); Assert.Fail("expected Err"); } //---------------Test Result ----------------------- catch (InvalidPropertyNameException ex) { string errMessage = String.Format ("The given property name '{0}' does not exist in the " + "collection of properties for the class '{1}'.", nonexistentPropName, "TestAutoInc"); StringAssert.Contains(errMessage, ex.Message); } }
public void TestSaveUpdatesAutoIncrementingField() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); TestAutoInc.LoadClassDefWithAutoIncrementingID(); TestAutoInc bo = new TestAutoInc(); bo.SetPropertyValue("testfield", "testing 123"); //---------------Assert Precondition---------------- Assert.IsFalse(bo.TestAutoIncID.HasValue); //---------------Execute Test ---------------------- bo.Save(); //---------------Test Result ----------------------- Assert.IsNotNull(bo.TestAutoIncID); Assert.AreNotEqual(0, bo.TestAutoIncID); Assert.IsFalse(bo.Status.IsDirty); }
public void Test_CommitTransaction_WithAutoIncrementBo_ShouldUseNumberGeneratorsInDatastore() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); IClassDef classDef = TestAutoInc.LoadClassDefWithAutoIncrementingID(); DataStoreInMemory dataStore = MockRepository.GeneratePartialMock<DataStoreInMemory>(); dataStore.Replay(); int nextAutoIncNumber = TestUtil.GetRandomInt(); dataStore.Stub(t => t.GetNextAutoIncrementingNumber(classDef)).Return(nextAutoIncNumber); ITransactionCommitter transactionCommitter = new TransactionCommitterInMemory(dataStore); TestAutoInc bo = new TestAutoInc(); bo.SetPropertyValue("testfield", "testing 123"); transactionCommitter.AddBusinessObject(bo); //---------------Assert Precondition---------------- Assert.IsFalse(bo.TestAutoIncID.HasValue); Assert.AreSame(classDef, bo.ClassDef); Assert.IsTrue(bo.Props.HasAutoIncrementingField); //---------------Execute Test ---------------------- transactionCommitter.CommitTransaction(); //---------------Test Result ----------------------- dataStore.AssertWasCalled(memory => memory.GetNextAutoIncrementingNumber(classDef)); Assert.IsNotNull(bo.TestAutoIncID); Assert.AreEqual(nextAutoIncNumber, bo.TestAutoIncID); Assert.IsFalse(bo.Status.IsDirty); }
public void TestSaveUpdatesAutoIncrementingField() { ClassDef.ClassDefs.Clear(); TestAutoInc.LoadClassDefWithAutoIncrementingID(); TestAutoInc bo = new TestAutoInc(); bo.SetPropertyValue("testfield", "testing 123"); Assert.IsFalse(bo.TestAutoIncID.HasValue); bo.Save(); Assert.IsNotNull(bo.TestAutoIncID); Assert.AreNotEqual(0, bo.TestAutoIncID); Assert.IsFalse(bo.Status.IsDirty); }
public void TestAutoIncrementingFieldInNewPrimaryKeyDoesntCheckDuplicates() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); TestAutoInc.LoadClassDefWithAutoIncrementingID(); TestAutoInc bo = new TestAutoInc(); bo.SetPropertyValue("testfield", "testing 123"); MockRepository mockRepos = new MockRepository(); IBusinessObjectLoader mockBusinessObjectLoader = mockRepos.DynamicMock<IBusinessObjectLoader>(); Expect.Call( mockBusinessObjectLoader.GetBusinessObjectCollection(null, new Criteria("", Criteria.ComparisonOp.Equals, ""))) .IgnoreArguments() .Repeat.Never(); DataAccessorStub dataAccessor = new DataAccessorStub(); dataAccessor.BusinessObjectLoader = mockBusinessObjectLoader; BORegistry.DataAccessor = dataAccessor; mockRepos.ReplayAll(); TransactionCommitterDB transactionCommitterDB = new TransactionCommitterDB(DatabaseConnection.CurrentConnection); transactionCommitterDB.AddBusinessObject(bo); //---------------Execute Test ---------------------- transactionCommitterDB.CommitTransaction(); //---------------Test Result ----------------------- mockRepos.VerifyAll(); }