public void AddRange_Success() { var newAccounts = new List <Account>() { new Account { EmailAddress = "*****@*****.**", Username = "******", Password = "******", Salt = "123456", EmailWasVerified = true, ActivationToken = null, RecoveryToken = null, Player = null }, new Account { EmailAddress = "*****@*****.**", Username = "******", Password = "******", Salt = "123456", EmailWasVerified = true, ActivationToken = null, RecoveryToken = null, Player = null }, }; _repository.AddRange(newAccounts); int expected = 5; int actual = _mockSet.Count(); Assert.AreEqual(expected, actual); }
public void GetAllSuccessTest() { //Given var databseFactory = new DatabaseFactoryBase <SharedCommonDatabaseContext>("SharedCommonDatabaseContext"); using (var unitOfWork = new UnitOfWork <SharedCommonDatabaseContext>(databseFactory)) { var repository = new AccountRepository(databseFactory); var listOfItems = AccountEntityHelper.CreateTestAccounts(3); listOfItems[0].CompanyName = "1"; listOfItems[1].CompanyName = "2"; listOfItems[2].CompanyName = "3"; repository.AddRange(listOfItems); unitOfWork.Commit(); //When var allItems = repository.GetAll(); //Then EqualityHelper.AssertListsAreEqual(allItems.OrderBy(x => x.CompanyName).ToList(), listOfItems.OrderBy(x => x.CompanyName).ToList(), new[] { "AccountID", "LastModified", "LastModifiedBy", "Contacts" }); } }
public void GetItemsViaStoredProcedureWithParameterNotParameterisedTest() { //Given var databseFactory = new DatabaseFactoryBase <SharedCommonDatabaseContext>("SharedCommonDatabaseContext"); using (var unitOfWork = new UnitOfWork <SharedCommonDatabaseContext>(databseFactory)) { var repository = new AccountRepository(databseFactory); var reference = "TestReference"; var listOfItems = GetItemsWithTwoItemsContainingTestReference(reference); repository.AddRange(listOfItems); unitOfWork.Commit(); //When var filter = new SqlParameter("@CompanyName", SqlDbType.VarChar) { Value = $"%{reference}%" }; var items = repository.ExecuteQuery <Account>("exec GetAccounts @CompanyName", filter).ToList(); //Then EqualityHelper.AssertListsAreEqual(items.OrderBy(x => x.CompanyName).ToList(), listOfItems.OrderBy(x => x.CompanyName).Take(2).ToList(), new[] { "AccountID", "LastModified", "LastModifiedBy", "Contacts" }); } }
public void AddListOfItemsFailsValidationTest() { //Given var databseFactory = new DatabaseFactoryBase <SharedCommonDatabaseContext>("SharedCommonDatabaseContext"); var repository = new AccountRepository(databseFactory); var listOfItems = AccountEntityHelper.CreateTestAccounts(3); listOfItems[1].CompanyName = null; //When TestDelegate testDelegate = () => repository.AddRange(listOfItems); //Then Assert.Throws <InvalidOperationException>(testDelegate); }
public static void Init() { using (var clientrepo = new ClientRepository()) { clientrepo.AddRange( new[] { new Client("Client1", DateTime.Now, "client1", "client1"), new Client("Client2", DateTime.Now, "client2", "client2"), new Client("Client3", DateTime.Now, "client3", "client3") }); } using (var accountrepo = new AccountRepository()) { accountrepo.AddRange( new[] { new Account(1, 100d), new Account(2, 100d), new Account(3, 100d) }); } using (var depositrepo = new DepositRepository()) { depositrepo.AddRange( new[] { new Deposit(1, DepositType.WithCapitalization, DateTime.Now.AddMonths(1)), new Deposit(2, DepositType.WithCapitalization, DateTime.Now.AddMonths(5)) { CreationTime = DateTime.Now.AddMonths(-2), Amount = 1000 }, new Deposit(3, DepositType.WithoutCapitalization, DateTime.Now.AddMonths(15)) { CreationTime = DateTime.Now.AddMonths(-8), Amount = 1000 } }); } var result = new Transfer(new Transaction(50d, 1, 2)).Execute(); result = new Withdrawal(new Transaction(25d, 1, 0)).Execute(); result = new Crediting(new Transaction(25d, 0, 3)).Execute(); }
public void ExecuteStoredProcedureAsActionTest() { //Given var databseFactory = new DatabaseFactoryBase <SharedCommonDatabaseContext>("SharedCommonDatabaseContext"); using (var unitOfWork = new UnitOfWork <SharedCommonDatabaseContext>(databseFactory)) { var repository = new AccountRepository(databseFactory); var listOfItems = AccountEntityHelper.CreateTestAccounts(3); repository.AddRange(listOfItems); unitOfWork.Commit(); //When repository.ExecuteQueryAsAction("exec DeleteAllAccounts"); //Then Assert.AreEqual(0, repository.GetAll().Count(), "There are still items in the database."); } }
public void GetItemsViaStoredProcedureWithNoParameterNotParameterisedTest() { //Given var databseFactory = new DatabaseFactoryBase <SharedCommonDatabaseContext>("SharedCommonDatabaseContext"); using (var unitOfWork = new UnitOfWork <SharedCommonDatabaseContext>(databseFactory)) { var repository = new AccountRepository(databseFactory); var listOfItems = AccountEntityHelper.CreateTestAccounts(3); repository.AddRange(listOfItems); unitOfWork.Commit(); //When var items = repository.ExecuteQuery <Account>("exec GetAccounts").ToList(); //Then EqualityHelper.AssertListsAreEqual(items.OrderBy(x => x.CompanyName).ToList(), listOfItems.OrderBy(x => x.CompanyName).ToList(), new[] { "AccountID", "LastModified", "LastModifiedBy", "Contacts" }); } }
public void AddListOfItemsTest() { //Given var databseFactory = new DatabaseFactoryBase <SharedCommonDatabaseContext>("SharedCommonDatabaseContext"); var repository = new AccountRepository(databseFactory); var listOfItems = AccountEntityHelper.CreateTestAccounts(3); var originalItems = repository.GetAll(); using (var unitOfWork = new UnitOfWork <SharedCommonDatabaseContext>(databseFactory)) { //When repository.AddRange(listOfItems); //Then var allNewItems = repository.GetAll(); var itemsAdded = allNewItems.Except(originalItems).ToList(); EqualityHelper.AssertListsAreEqual(itemsAdded, listOfItems, new[] { "AccountID", "LastModified", "Contacts" }); } }
public void GetAutoCompleteItemsTest() { //Given var databseFactory = new DatabaseFactoryBase <SharedCommonDatabaseContext>("SharedCommonDatabaseContext"); using (var unitOfWork = new UnitOfWork <SharedCommonDatabaseContext>(databseFactory)) { var repository = new AccountRepository(databseFactory); var reference = "TestReference"; var listOfItems = GetItemsWithTwoItemsContainingTestReference(reference); repository.AddRange(listOfItems); unitOfWork.Commit(); //When var item = repository.GetAutoCompleteItems(x => x.CompanyName.Contains(reference), 1); //Then EqualityHelper.PropertyValuesAreEqual(item.First(), listOfItems[0], new[] { "AccountID", "LastModified", "LastModifiedBy", "Contacts" }); } }
public void GetManyWithWhereClauseSuccessTest() { //Given var databseFactory = new DatabaseFactoryBase <SharedCommonDatabaseContext>("SharedCommonDatabaseContext"); using (var unitOfWork = new UnitOfWork <SharedCommonDatabaseContext>(databseFactory)) { var repository = new AccountRepository(databseFactory); var reference = "TestReference"; var listOfItems = GetItemsWithTwoItemsContainingTestReference(reference); repository.AddRange(listOfItems); unitOfWork.Commit(); //When var items = repository.GetMany(x => x.CompanyName.Contains(reference)); //Then EqualityHelper.AssertListsAreEqual(items.OrderBy(x => x.CompanyName).ToList(), listOfItems.OrderBy(x => x.CompanyName).Take(2).ToList(), new[] { "AccountID", "LastModified", "LastModifiedBy", "Contacts" }); } }
public void GetNoneButSomeExistTest() { //Given var databseFactory = new DatabaseFactoryBase <SharedCommonDatabaseContext>("SharedCommonDatabaseContext"); using (var unitOfWork = new UnitOfWork <SharedCommonDatabaseContext>(databseFactory)) { var repository = new AccountRepository(databseFactory); var listOfItems = AccountEntityHelper.CreateTestAccounts(3); listOfItems[2].CompanyName = "TestReferenceOtherValue"; repository.AddRange(listOfItems); unitOfWork.Commit(); //When var hasNone = repository.None(x => x.CompanyName.Contains("TestReference")); //Then Assert.IsFalse(hasNone, "None were found when there should have been some."); } }
public void GetWithWhereClauseSuccessTest() { //Given var databseFactory = new DatabaseFactoryBase <SharedCommonDatabaseContext>("SharedCommonDatabaseContext"); using (var unitOfWork = new UnitOfWork <SharedCommonDatabaseContext>(databseFactory)) { var repository = new AccountRepository(databseFactory); var listOfItems = AccountEntityHelper.CreateTestAccounts(3); listOfItems[2].CompanyName = "TestReferenceOtherValue"; repository.AddRange(listOfItems); unitOfWork.Commit(); //When var items = repository.Get(x => x.CompanyName.Contains("TestReference")); //Then EqualityHelper.PropertyValuesAreEqual(items, listOfItems[2], new[] { "AccountID", "LastModified", "LastModifiedBy", "Contacts" }); } }
public void DeleteWithWhereClauseSuccessTest() { //Given var databseFactory = new DatabaseFactoryBase <SharedCommonDatabaseContext>("SharedCommonDatabaseContext"); using (var unitOfWork = new UnitOfWork <SharedCommonDatabaseContext>(databseFactory)) { var repository = new AccountRepository(databseFactory); var listOfItems = AccountEntityHelper.CreateTestAccounts(3); var originalItems = repository.GetAll(); repository.AddRange(listOfItems); var allNewItems = repository.GetAll().ToList(); var itemsAdded = allNewItems.Except(originalItems).ToList(); //When var idsToDelete = itemsAdded.Select(x => x.AccountID); repository.Delete(x => idsToDelete.Contains(x.AccountID)); unitOfWork.Commit(); //Then Assert.AreEqual(0, repository.GetAll().Except(allNewItems).Count(), "The items have not been deleted."); } }