public DaoResponse<Country> Delete(Country entity) { using (var connection = _dbCommProvider.CreateDbConnection()) using (var command = _dbCommProvider.CreateDbCommand(connection, SqlQueries.DeleteCountry, CreateCountryParameter(entity))) { _dbCommProvider.ExecuteNonQuery(command); } return DaoResponse.QuerySuccessful(entity); }
public void TestInsertCountryDbAccess() { var dao = FactoryProvider.GetFactory<IDaoProviderFactory>( TestDbDaoAssemblyName, TestDbDaoNameSpace, TestDbDaoClassName).CreateCountryDao(); using (var scope = new TransactionScope()) { var country = new Country { Code="PD", Name ="Pandora" }; dao.Insert(country) .OnFailure(response => Assert.Fail($"Insert does not work! {response.Exception}")); // do not commit changes; only for testing //scope.Complete(); } }
public void TestDeleteCountryDbAccess() { var dao = FactoryProvider.GetFactory<IDaoProviderFactory>( TestDbDaoAssemblyName, TestDbDaoNameSpace, TestDbDaoClassName).CreateCountryDao(); using (var scope = new TransactionScope()) { var country = new Country { Code = "PD", Name = "Pandora" }; dao.Insert(country) .OnFailure(response => Assert.Fail($"Insert does not work! {response.Exception}")); var getRsp = dao.SelectByCode("PD"); getRsp .OnEmptyResult(() => Assert.Fail("No data found")) .OnFailure(response => Assert.Fail($"Unexpected exception occurred: {response.Exception}")); country = getRsp.ResultObject; dao.Delete(country) .OnFailure(response => Assert.Fail($"Delete does not work! {response.Exception}")); // do not commit changes; only for testing //scope.Complete(); } }
public DaoResponse<Country> Update(Country entity) { throw new NotImplementedException(); }
private Dictionary<string, QueryParameter> CreateCountryParameter(Country entity) { return new Dictionary<string, QueryParameter> { {"?Code", new QueryParameter {ParameterValue = entity.Code}}, {"?Name", new QueryParameter {ParameterValue = entity.Name}} }; }
private Country CreateCountryObject(IDataReader dataReader) { var country = new Country { Code = _dbCommProvider.CastDbObject<string>(dataReader, "Code"), Name = _dbCommProvider.CastDbObject<string>(dataReader, "Name") }; return country; }