public EF6UnitOfWorkTests()
        {
            DbConnection connection = Effort.DbConnectionFactory.CreateTransient();
            _context = new FooContext(connection);

            _unitOfWork = new Ef6UnitOfWork(_context, IsolationLevel.Unspecified);

            var repository = new BaseRepository<Foo>(_unitOfWork);
            _repositoryWriter = repository;
            _repositoryReader = repository;
        }
        public BaseRepositoryTests()
        {
            DbConnection connection = DbConnectionFactory.CreateTransient();
            _context = new FooContext(connection);

            var repository = new BaseRepository<Foo>(new Ef6UnitOfWork(_context, IsolationLevel.Unspecified));
            _repositoryWriter = repository;
            _repositoryReader = repository;
            _repositoryWriterAsync = repository;
            _repositoryReaderAsync = repository;
        }
Exemple #3
0
 public DepartmentRepository()
 {
     BaseInstance = new BaseRepository();
 }
        public BaseRepositoryTests()
        {
            _connection = new SqlConnection(@"Data Source=(localdb)\v11.0.;
                                                Initial Catalog=AdoUoWTestDb;
                                                Integrated Security=True");

            #region Mock

            var dataMapperStup = new Mock<IAdoDataMapper<Foo>>();
            dataMapperStup.Setup(f => f.Map(It.IsAny<IDataReader>()))
                .Returns(
                    (IDataReader reader) =>
                    new Foo
                        {
                            Id = Guid.Parse(reader["Id"].ToString()),
                            Name = reader["Name"].ToString()
                        });
            _dataMapper = dataMapperStup.Object;

            var commandProviderStud = new Mock<IAdoDbCommandProvider<Foo>>();
            commandProviderStud.Setup(f => f.SelectByIdCommand(It.IsAny<IDbConnection>(), It.IsAny<IDbTransaction>(), It.IsAny<Guid>()))
                .Returns(
                    (IDbConnection connection, IDbTransaction transaction, Guid id) =>
                        {
                            IDbCommand command = new SqlCommand();

                            command.Transaction = _transaction;
                            command.Connection = connection;
                            command.CommandType = CommandType.Text;
                            command.CommandText = "SELECT * FROM [Foos] WHERE Id = @Id";
                            command.Parameters.Add(
                                new SqlParameter { ParameterName = "@Id", DbType = DbType.Guid, Value = id });

                            return command;
                        });
            commandProviderStud.Setup(f => f.DeleteCommand(It.IsAny<IDbConnection>(), It.IsAny<IDbTransaction>(), It.IsAny<Foo>()))
                .Returns(
                    (IDbConnection connection, IDbTransaction transaction, Foo item) =>
                    {
                        IDbCommand command = new SqlCommand();

                        command.Connection = connection;
                        command.Transaction = _transaction;
                        command.CommandType = CommandType.Text;
                        command.CommandText = "DELETE FROM [Foos] WHERE Id = @Id";
                        command.Parameters.Add(
                            new SqlParameter { ParameterName = "@Id", DbType = DbType.Guid, Value = item.Id });

                        return command;
                    });
            commandProviderStud.Setup(f => f.InsertCommand(It.IsAny<IDbConnection>(), It.IsAny<IDbTransaction>(), It.IsAny<Foo>()))
                .Returns(
                    (IDbConnection connection, IDbTransaction transaction, Foo item) =>
                    {
                        IDbCommand command = new SqlCommand();

                        command.Connection = connection;
                        command.Transaction = _transaction;
                        command.CommandType = CommandType.Text;
                        command.CommandText = "INSERT INTO [Foos] VALUES(@Id,@Name)";
                        command.Parameters.Add(
                            new SqlParameter { ParameterName = "@Id", DbType = DbType.Guid, Value = item.Id });
                        command.Parameters.Add(
                            new SqlParameter { ParameterName = "@Name", DbType = DbType.String, Value = item.Name });

                        return command;
                    });
            commandProviderStud.Setup(f => f.UpdateCommand(It.IsAny<IDbConnection>(), It.IsAny<IDbTransaction>(), It.IsAny<Foo>()))
                .Returns(
                    (IDbConnection connection, IDbTransaction transaction, Foo item) =>
                    {
                        IDbCommand command = new SqlCommand();

                        command.Connection = connection;
                        command.Transaction = _transaction;
                        command.CommandType = CommandType.Text;
                        command.CommandText = "UPDATE T SET T.Name = @Name FROM [Foos] T WHERE T.Id = @Id";
                        command.Parameters.Add(
                            new SqlParameter { ParameterName = "@Id", DbType = DbType.Guid, Value = item.Id });
                        command.Parameters.Add(
                            new SqlParameter { ParameterName = "@Name", DbType = DbType.String, Value = item.Name });

                        return command;
                    });
            commandProviderStud.Setup(f => f.SelectAllCommand(It.IsAny<IDbConnection>(), It.IsAny<IDbTransaction>()))
                .Returns(
                    (IDbConnection connection, IDbTransaction transaction) =>
                    {
                        IDbCommand command = new SqlCommand();

                        command.Connection = connection;
                        command.Transaction = _transaction;
                        command.CommandType = CommandType.Text;
                        command.CommandText = "SELECT * FROM [Foos]";

                        return command;
                    });

            _commandProvider = commandProviderStud.Object;

            #endregion

            var repository = new BaseRepository<Foo>(_connection, _commandProvider, _dataMapper);
            _repositoryWriter = repository;
            _repositoryReader = repository;

            _connection.Open();
        }
        public void DisposeWorksCorrectly()
        {
            //Arrange
            DbConnection connection = Effort.DbConnectionFactory.CreateTransient();
            var context = new FooContext(connection);
            var unitOfWork = new Ef6UnitOfWork(_context, IsolationLevel.Unspecified);
            var repository = new BaseRepository<Foo>(unitOfWork);

            //Act
            repository.Insert(new Foo { Id = Guid.NewGuid() });
            unitOfWork.SaveChanges();
            unitOfWork.Dispose();

            //Assert
        }
Exemple #6
0
 public DepartmentRepository()
 {
     BaseInstance = new BaseRepository();
 }
Exemple #7
0
 public EmployeeRepository()
 {
     BaseInstance = new BaseRepository();
 }