public void GetNextNumber_WhenWasOne_ShouldReturnTwo() { //---------------Set up test pack------------------- var numberType = RandomValueGen.GetRandomString(); //Create an instance of the number for a specific type of number (e.g. Invoice number) IDBNumberGenerator numGen = new DatabaseNumberGenerator(numberType, "numbergenerator", 0, "NumberType", "SequenceNumber"); //---------------Assert Precondition---------------- Assert.AreEqual(1, numGen.GetNextNumberInt()); //---------------Execute Test ---------------------- var nextNumberInt = numGen.GetNextNumberInt(); //---------------Test Result ----------------------- Assert.AreEqual(2, nextNumberInt); }
public void TestIntegration_Commit_ThenRollBack_ThenGetNextNumber_ShouldGenerateNextNumber() { //See GetNextNumber_WhenWasOne_ShouldReturnTwo Test for what would happen if the UpdateAsRolledBack Did not happen //See TestAcceptance_UpdateAsRolledBack_ThenGetNextNumber_ShouldResetNumberToOriginalNumber to see what would happen if RollBackWasCalled //---------------Set up test pack------------------- var numberType = RandomValueGen.GetRandomString(); //Create an instance of the number for a specific type of number (e.g. Invoice number) IDBNumberGenerator numGen = new DatabaseNumberGenerator(numberType, "numbergenerator", 0, "NumberType", "SequenceNumber"); var updateTransaction = numGen.GetUpdateTransaction(); //---------------Assert Precondition---------------- Assert.AreEqual(1, numGen.GetNextNumberInt()); //---------------Execute Test ---------------------- updateTransaction.UpdateStateAsCommitted(); updateTransaction.UpdateAsRolledBack(); var nextNumberInt = numGen.GetNextNumberInt(); //---------------Test Result ----------------------- Assert.AreEqual(2, nextNumberInt); }
public void TestIntegration_UpdateDB_WhenCurrentNumberIs2_ShouldUpdateDB() { //---------------Set up test pack------------------- var numberType = RandomValueGen.GetRandomString(); //Create an instance of the number for a specific type of number (e.g. Invoice number) var dbTransactionCommitter = BORegistry.DataAccessor.CreateTransactionCommitter(); IDBNumberGenerator numGen = new DatabaseNumberGenerator(numberType, "numbergenerator", 1, "NumberType", "SequenceNumber"); var updateTransaction = numGen.GetUpdateTransaction() as ITransactionalDB; var currentNumber = numGen.GetNextNumberInt(); //---------------Assert Precondition---------------- Assert.IsInstanceOf<TransactionCommitterDB>(dbTransactionCommitter); Assert.IsNotNull(updateTransaction); Assert.AreEqual(2, currentNumber); //---------------Execute Test ---------------------- dbTransactionCommitter.AddTransaction(updateTransaction); dbTransactionCommitter.CommitTransaction(); //---------------Test Result ----------------------- IDBNumberGenerator numGen2 = new DatabaseNumberGenerator(numberType, "numbergenerator", 1, "NumberType", "SequenceNumber"); var nextNumberInt = numGen2.GetNextNumberInt(); Assert.AreEqual(3, nextNumberInt); }
public void TestIntegration_GetPersistSql_WhenNumberEQ2_ShouldReturnCorrectSQL() { //---------------Set up test pack------------------- var numberType = RandomValueGen.GetRandomString(); //Create an instance of the number for a specific type of number (e.g. Invoice number) IDBNumberGenerator numGen = new DatabaseNumberGenerator(numberType, "numbergenerator", 0, "NumberType", "SequenceNumber"); var updateTransaction = numGen.GetUpdateTransaction() as ITransactionalDB; numGen.GetNextNumberInt(); var currentNumber = numGen.GetNextNumberInt(); //---------------Assert Precondition---------------- Assert.IsNotNull(updateTransaction); Assert.AreEqual(2, currentNumber); //---------------Execute Test ---------------------- var sqlStatements = updateTransaction.GetPersistSql(); //---------------Test Result ----------------------- var sqlStatement = sqlStatements.FirstOrDefault(); Assert.IsNotNull(sqlStatement); var stringStatement = sqlStatement.Statement.ToString(); StringAssert.StartsWith(" update numbergenerator", stringStatement); }