public void TenantCompanyAccountGetForTenantId_ReturnsAllThreeRecordSets() { // ARRANGE var parameters = new TenantIdParameters { TenantId = 1 }; var procedure = new TenantCompanyAccountGetForTenantId(parameters); const int expectedTenantCount = 1; const int expectedCompanyCount = 2; const int expectedAccountCount = 3000000; // ACT var resultSet = Context.ExecuteStoredProcedure(procedure); List<TenantDto> tenants = resultSet.Tenants; List<CompanyDto> companies = resultSet.Companies; List<AccountDto> accounts = resultSet.Accounts; // ASSERT Assert.IsNotNull(tenants); Assert.IsNotNull(companies); Assert.IsNotNull(accounts); Assert.AreEqual(expectedTenantCount, tenants.Count); Assert.AreEqual(expectedCompanyCount, companies.Count); Assert.AreEqual(expectedAccountCount, accounts.Count); }
public void StoredProcedure_WithSqlTransactionCommitted_DoesWriteRecords() { // ARRANGE const int expectedIntermediateCount = 5; int originalCount; int intermediateCount; int finalCount; string connectionName = Settings.Default.ExampleDatabaseConnection; var companiesToAdd = new List<CompaniesAdd.CompanyTableType> { new CompaniesAdd.CompanyTableType { CompanyName = "Company 1", IsActive = true, TenantId = 2 }, new CompaniesAdd.CompanyTableType { CompanyName = "Company 2", IsActive = false, TenantId = 2 }, new CompaniesAdd.CompanyTableType { CompanyName = "Company 3", IsActive = true, TenantId = 2 } }; var companiesAddParameters = new CompaniesAdd.CompaniesAddParameters { Companies = companiesToAdd }; var companyAddProcedure = new CompaniesAdd(companiesAddParameters); var companyCountProcedure = new CompanyCountAll(); var companyDeleteParameters = new TenantIdParameters { TenantId = 2 }; var companyDeleteProcedure = new CompanyDeleteForTenantId(companyDeleteParameters); // ACT using (var connection = new SqlConnection(connectionName)) { connection.Open(); using (var transaction = connection.BeginTransaction()) { using (var context = new ApplicationDbContext(connection, false)) { originalCount = context.ExecuteStoredProcedure(companyCountProcedure, transaction: transaction).First().CountOfCompanies; context.ExecuteStoredProcedure(companyAddProcedure, transaction: transaction); transaction.Commit(); } } } using (var context = new ApplicationDbContext(connectionName)) { intermediateCount = context.ExecuteStoredProcedure(companyCountProcedure).First().CountOfCompanies; context.ExecuteStoredProcedure(companyDeleteProcedure); finalCount = context.ExecuteStoredProcedure(companyCountProcedure).First().CountOfCompanies; } // ASSERT Assert.AreEqual(originalCount, finalCount); Assert.AreEqual(expectedIntermediateCount, intermediateCount); }
public void CompanyGetAllForTenantId() { // ARRANGE var parameters = new TenantIdParameters { TenantId = 1 }; var procedure = new CompanyDeleteForTenantId(parameters); // ACT Context.ExecuteStoredProcedure(procedure); // ASSERT // Nothing to assert }
public void CompanyGetAllForTenantId() { // ARRANGE var parameters = new TenantIdParameters { TenantId = 1 }; var procedure = new CompanyGetAllForTenantID(parameters); const int expectedCompanyCount = 2; // ACT List<CompanyDto> companies = Connection.ExecuteStoredProcedure(procedure); CompanyDto company1 = companies.FirstOrDefault(); // ASSERT Assert.AreEqual(expectedCompanyCount, companies.Count); Assert.IsNotNull(company1); }
public void CompanyGetAllForTenantId() { // ARRANGE const int expectedCompanyCount = 2; string connectionName = Settings.Default.ExampleDatabaseConnection; var parameters = new TenantIdParameters { TenantId = 1 }; var procedure = new CompanyGetAllForTenantID(parameters); List<CompanyDto> companies; CompanyDto company1; // ACT using (ApplicationDbContext context = new ApplicationDbContext(connectionName)) { companies = context.ExecuteStoredProcedure(procedure); company1 = companies.FirstOrDefault(); } // ASSERT Assert.AreEqual(expectedCompanyCount, companies.Count); Assert.IsNotNull(company1); }
public void StoredProcedure_WithTransactionScopeCompleted_DoesWriteRecords() { // ARRANGE const int expectedIntermediateCount = 5; int originalCount; int intermediateCount; int finalCount; string connectionString = Settings.Default.ExampleDatabaseConnection; var companiesToAdd = new List<CompaniesAdd.CompanyTableType> { new CompaniesAdd.CompanyTableType { CompanyName = "Company 1", IsActive = true, TenantId = 2 }, new CompaniesAdd.CompanyTableType { CompanyName = "Company 2", IsActive = false, TenantId = 2 }, new CompaniesAdd.CompanyTableType { CompanyName = "Company 3", IsActive = true, TenantId = 2 } }; var companiesAddParameters = new CompaniesAdd.CompaniesAddParameters { Companies = companiesToAdd }; var companyAddProcedure = new CompaniesAdd(companiesAddParameters); var companyCountProcedure = new CompanyCountAll(); var companyDeleteParameters = new TenantIdParameters { TenantId = 2 }; var companyDeleteProcedure = new CompanyDeleteForTenantId(companyDeleteParameters); // ACT using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew)) { using (var connection = new SqlConnection(connectionString)) { connection.Open(); originalCount = connection.ExecuteStoredProcedure(companyCountProcedure).First().CountOfCompanies; connection.ExecuteStoredProcedure(companyAddProcedure); transactionScope.Complete(); } } using (var connection = new SqlConnection(connectionString)) { connection.Open(); intermediateCount = connection.ExecuteStoredProcedure(companyCountProcedure).First().CountOfCompanies; connection.ExecuteStoredProcedure(companyDeleteProcedure); finalCount = connection.ExecuteStoredProcedure(companyCountProcedure).First().CountOfCompanies; connection.Close(); } // ASSERT Assert.AreEqual(originalCount, finalCount); Assert.AreEqual(expectedIntermediateCount, intermediateCount); }