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.
I can think of three possible options to test this kind of code.

1. As you mentioned, implement the AddTransaction code and use that in your tests to compare the value of Balance.
2. You can potentially make the transactions property public and mock it in your tests.
3. Modify the Account class by adding a constructor that will allow you to initialize the Account with a Transactions parameter, then you can mock the Transactions and inject it into the class in the tests.