Question: I am learning TDD and mocking and I'm wondering how I can add some objects to private list to test the method and property. Essential parts of my code are as follows:

```
public class Account
{
    private List<Transaction> transactions = new List<Transaction>();

    public decimal Balance
    {
        get
        {
            throw new NotImplementedException();
            // Should be calculated by adding amounts of all transactions 
            // from private list
        }
    }

    public void AddTransaction(Transaction transaction)
    {
        throw new NotImplementedException();
    }
}

public class Transaction
{
    public decimal Amount { get; set; }
    public string Note { get; set; }
    public DateTime DateTime { get; set; }

    public Transaction(decimal amount, string note, DateTime dateTime)
    {
        Amount = amount;
        Note = note;
        DateTime = dateTime;
    }
}

```

I would like to test property Balance, but I don't know how to add some data to list. Can I do this by using Mock or should I write the code for AddTransaction first and use it in Balance tests?

Answer: 
You should test your class by using only public "endpoints" exposed to it's consumers.  

In your case it will be `constructor`, `AddTransaction` and `Balance`. 
Responsibility of your class is adding transactions and calculate balance.  

So in your tests you will add transactions and check that `Balance` returns expected result. `AddTransaction` method will be tested through tests for `Balance` property.

If you approaching solution by writing tests first, then you don't need to care about is there private list or dictionary or something else.

For example first test will look like

```
var transaction = new Transaction(12.4m, "note", 12.January(2018));
var account = new Account();

account.AddTransaction(transaction);

account.Balance.Should().Be(12.4m);

```

Second test

```
var transaction1 = new Transaction(50.00m, "note1", 12.January(2018));
var transaction2 = new Transaction(45.99m, "note2", 13.January(2018));
var transaction3 = new Transaction(4.01m, "note3", 14.January(2018));
var account = new Account();

account.AddTransaction(transaction1);
account.AddTransaction(transaction2);
account.AddTransaction(transaction3);

account.Balance.Should().Be(100.0m);

```

Where implementation could be

```
private decimal _balance;

public void AddTransaction(Transaction transaction)
{
    _balance += transaction.Amount;
}

public decimal Balance => _balance;

```

As you see, class can be implemented without list. Approach above can be effective in case when application use `Balance` much more times then `AddTransaction` method. 

By having tests which don't know about implementation can give you some freedom to refactor class under tests without changing tests.
Obviously, you first need to implement the getter for Balance and the AddTransaction method. Now, it's easy to test Balance. You create a transaction or two with known amounts in your test method, call AddTransactions to add them to the account, and then get the value of Balance and compare it with the sum of all amounts.
For testing add transaction, you will have to modify your Account class slightly. The options that I see are: 

1. Add a constructor that can take a transactions list (as Ethan already mentioned).
2. You may have concerns about the first approach as this gives a lot more control over the account. If that's the case then, you can create a method to get the number of transactions in an account and test AddTransactions based on that.
3. Create a GetFirstTransaction and a GetLastTransaction method and test your AddTransaction method based on that.
4. It's not worth doing this, but it's possible to create a public property with just a getter that returns a deep copy of transactions list and you can test against that in your test method.