public void Commit_MultipleCallsFail() { var conn = new TestDbConnection(); var target = new DataTransaction(conn.BeginTransaction()); target.Commit(); Action action = () => target.Commit(); action.Should().Throw <InvalidOperationException>(); }
public void Commit_DoesNotClosesConnection() { var conn = new TestDbConnection(); var target = new DataTransaction(conn.BeginTransaction(), false); //Act target.Commit(); //Assert conn.State.Should().Be(ConnectionState.Open); }
public void Commit_ClosesConnection() { var conn = new TestDbConnection(); var target = new DataTransaction(conn.BeginTransaction(), true); //Act target.Commit(); //Assert conn.State.Should().Be(ConnectionState.Closed); }
public void Ctor_DefaultClosesConnection() { //Act var conn = new TestDbConnection(); var target = new DataTransaction(conn.BeginTransaction()); target.Commit(); //Assert conn.State.Should().Be(ConnectionState.Closed); }
public void Commit_RaisesEvent() { var conn = new TestDbConnection(); var target = new DataTransaction(conn.BeginTransaction()); bool wasCommitted = false, wasRolledBack = false; //Act target.Committed += (o, e) => wasCommitted = true; target.RolledBack += (o, e) => wasRolledBack = true; target.Commit(); //Assert wasCommitted.Should().BeTrue(); wasRolledBack.Should().BeFalse(); }
/// <summary> /// Finishes the transport by committing the <see cref="DataTransaction"/> to the database, providing a filter to exclude some objects /// from being committed. /// </summary> /// <param name="filter">A filter delegate called for each object that would be committed to the database. Return true to include the /// object in the commit, or false to leave its state in the database as is.</param> /// <remarks>This method invalidated the <see cref="TransportedDomainObjects"/> object, setting <see cref="DataTransaction"/> and /// <see cref="TransportedObjects"/> to <see langword="null"/> and discarding <see cref="DataTransaction"/>. The transported object references /// cannot be used any longer after calling this method.</remarks> public void FinishTransport(Func <DomainObject, bool> filter) { ArgumentUtility.CheckNotNull("filter", filter); if (DataTransaction == null) { throw new InvalidOperationException("FinishTransport can only be called once."); } DataTransaction.AddListener(new TransportFinishTransactionListener(filter)); DataTransaction.Commit(); DataTransaction.Discard(); _dataTransaction = null; _transportedObjects = null; }
public void Commit() { _trans.Commit(); }