private void AdoNetConfiguration() { AdoNetContext.TableSet <Customer>("Customers"); AdoNetContext.TableSet <Order>("Orders"); AdoNetContext.UseSql("Server=NURLAN_B;Database=Northwind;User Id=sa1;Password=2"); }
public void CreateCommand() { var factory = Substitute.For <IConnectionFactory>(); var connectionMock = Substitute.For <IDbConnection>(); var expected = Substitute.For <IDbCommand>(); connectionMock.CreateCommand().Returns(expected); factory.Create().Returns(connectionMock); var context = new AdoNetContext(factory); var command = context.CreateCommand(); Assert.NotNull(command); Assert.Same(expected, command); }
static void Main(string[] args) { //Here we are creating the actual object MyDbContext MyDbContext ctx1 = new MyDbContext(connectionString); //Here is where we pass it to our first repository using (IRepository repo = new TestDb1Repository(ctx1)) { //Here we add 1000 customers to TestDb1 //bool IsSuccess = Add1000Customers(repo); //We have to save our changes to our database //repo.SaveChanges(); //Deleting customers with Id's 4, 7, 9 and 11 from database // IsSuccess = DeleteCustomersFromDatabase(repo, new List<int> { 4, 7, 8, 9, 11 }); //repo.SaveChanges(); //Get a list of addresses for the customer //List<Address> addresses = GetAddresses(repo, 20); //Console.WriteLine(IsSuccess); //addresses.ForEach(a => Console.WriteLine(a)); //Console.ReadKey(); } //Here we make our second repository connected to a different db //with a different context. connectionString = ConfigurationManager.ConnectionStrings["TestDb2"].ToString(); AdoNetContext ctx2 = new AdoNetContext(connectionString); using (IRepository repo = new TestDb2Repository(ctx2)) { //Here we add 1000 students to TestDb1 bool IsSuccess = Add1000Customers(repo); //Deleting Students with Id's 4, 7, 9 and 11 from database IsSuccess = DeleteCustomersFromDatabase(repo, new List <int> { 4, 7, 8, 9, 11 }); Console.ReadKey(); } }
public void CommandWithoutTransaction() { var factory = Substitute.For <IConnectionFactory>(); var connectionMock = Substitute.For <IDbConnection>(); var command = Substitute.For <IDbCommand>(); connectionMock.CreateCommand().Returns(command); var transaction = Substitute.For <IDbTransaction>(); connectionMock.BeginTransaction().Returns(transaction); factory.Create().Returns(connectionMock); var context = new AdoNetContext(factory); context.CreateUnitOfWork().Dispose(); var cmd = context.CreateCommand(); Assert.NotSame(transaction, cmd.Transaction); }
public IActionResult ResetGridState([FromBody] GridGetStateDto request) { var result = new OperationResponse <bool>(); var connectionFactory = new AppConfigConnectionFactory(_configuration.GetConnectionString("CosDB"), "System.Data.SqlClient"); var context = new AdoNetContext(connectionFactory); try { result.Data = _gridHandler.ResetGridState(request.UserName, request.GridKey, context); } catch (Exception e) { result.State = ResponseState.Error; result.Messages.Add("Error resetting grid state"); _logger.LogError(e, "Error resetting grid state"); } finally { context.Dispose(); } return(Json(result)); }
private SqlServerConnectionFactory() { //if (connectionName == null) throw new ArgumentNullException("connectionName"); string connectionName = "OlimpiadaDB"; var conStr = ConfigurationManager.ConnectionStrings[connectionName]; if (conStr == null) { throw new ConfigurationErrorsException(string.Format("Failed to find connection string named '{0}' in app/web.config.", connectionName)); } _name = conStr.ProviderName; _provider = DbProviderFactories.GetFactory(conStr.ProviderName); _connectionString = conStr.ConnectionString; //_name = "System.Data.SqlClient"; //_provider = DbProviderFactories.GetFactory("System.Data.SqlClient"); //_connectionString = ""; // during start of the current session _context = new AdoNetContext(this); }
public Repository(AdoNetContext context) { _context = context; }
public MedicoRepositorio(AdoNetContext context) : base(context) { }
public TestDb2Repository(AdoNetContext ctx) { _ctx = ctx; }
public EspecialidadeRepositorio(AdoNetContext context) : base(context) { }
/// <summary> /// Constructor to make a ComicRepository. /// </summary> /// <param name="context">Context to use.</param> public DeliveryRepository(AdoNetContext context) { this.context = context; }
public CidadeRepositorio(AdoNetContext context) : base(context) { }
private Order GetOrder(Expression <Func <Order, bool> > expression) { _adoNetContext = new AdoNetContext(); return(_adoNetContext.Set <Order>(expression)); }
private Customer GetCustomer(Expression <Func <Customer, bool> > expression) { _adoNetContext = new AdoNetContext(); return(_adoNetContext.Set <Customer>(expression)); }
public UsuarioRepositorio(AdoNetContext context) : base(context) { }
public GoalsController(DatabaseContext context, AdoNetContext adoContext) { _context = context; _adoContext = adoContext; }
/// <summary> /// Constructor to make a ComicRepository. /// </summary> /// <param name="context">Context to use.</param> public OrderRepository(AdoNetContext context) { this.context = context; }
/// <summary> /// Constructor to make a ComicRepository. /// </summary> /// <param name="context">Context to use.</param> public ComicRepository(AdoNetContext context) { this.context = context; }
public UserController() { factory = new AppConfigConnectionFactory("Sample"); context = new AdoNetContext(factory); userRepo = new UserRepository(context); }