Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 14, 2016
0 parents commit 682e046
Show file tree
Hide file tree
Showing 337 changed files with 15,815 additions and 0 deletions.
27 changes: 27 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Freeware License, some rights reserved

Copyright (c) 2010 Gary Hall

Permission is hereby granted, free of charge, to anyone obtaining a copy
of this software and associated documentation files (the "Software"),
to work with the Software within the limits of freeware distribution and fair use.
This includes the rights to use, copy, and modify the Software for personal use.
Users are also allowed and encouraged to submit corrections and modifications
to the Software for the benefit of other users.

It is not allowed to reuse, modify, or redistribute the Software for
commercial use in any way, or for a user�s educational materials such as books
or blog articles without prior permission from the copyright holder.

The above copyright notice and this permission notice need to be included
in all copies or substantial portions of the software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


10 changes: 10 additions & 0 deletions Pro WPF Silverlight MVVM/Ch10_MyMoney/Local.testsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="Local" id="e533ef08-9b5d-45f9-9cf4-b65cf17f0508" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>These are default test settings for a local test run.</Description>
<Deployment enabled="false" />
<Execution>
<TestTypeSpecific />
<AgentRule name="Execution Agents">
</AgentRule>
</Execution>
</TestSettings>
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MyMoney.Model.Test
{
[TestClass]
public class CompositeAccountTests
{
[TestMethod]
public void TestAddAccount()
{
CompositeAccount ac1 = new CompositeAccount("A");
CompositeAccount ac2 = new CompositeAccount("B");

ac1.AddAccount(ac2);

Assert.AreEqual(1, ac1.ChildAccounts.Count());
Assert.AreEqual(ac2, ac1.ChildAccounts.FirstOrDefault());
}

[TestMethod]
public void TestRemoveAccount()
{
CompositeAccount ac1 = new CompositeAccount("A");
CompositeAccount ac2 = new CompositeAccount("B");

ac1.AddAccount(ac2);

ac1.RemoveAccount(ac2);
Assert.AreEqual(0, ac1.ChildAccounts.Count());
}

[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void TestAccountOnlyAppearsOnceInHierarchy()
{
CompositeAccount ac1 = new CompositeAccount("A");
CompositeAccount ac2 = new CompositeAccount("B");
CompositeAccount ac3 = new CompositeAccount("C");

ac1.AddAccount(ac3);
ac2.AddAccount(ac3);
}

[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void TestAccountsWithSameNameCannotShareParent()
{
CompositeAccount ac1 = new CompositeAccount("AC1");
CompositeAccount ac2 = new CompositeAccount("ABC");
CompositeAccount ac3 = new CompositeAccount("ABC");

ac1.AddAccount(ac2);
ac1.AddAccount(ac3);
}

[TestMethod]
public void TestAccountsWithSameNameCanExistInHierarchy()
{
CompositeAccount ac1 = new CompositeAccount("AC1");
CompositeAccount ac2 = new CompositeAccount("ABC");
CompositeAccount ac3 = new CompositeAccount("AC3");
CompositeAccount ac4 = new CompositeAccount("ABC");

ac1.AddAccount(ac2);
ac2.AddAccount(ac3);
ac3.AddAccount(ac4);
}

[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void TestAccountsCannotBeDirectlyCyclical()
{
CompositeAccount ac1 = new CompositeAccount("AC1");
CompositeAccount ac2 = new CompositeAccount("AC2");

ac1.AddAccount(ac2);
ac2.AddAccount(ac1);
}

[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void TestAccountsCannotBeIndirectlyCyclical()
{
CompositeAccount ac1 = new CompositeAccount("AC1");
CompositeAccount ac2 = new CompositeAccount("AC2");
CompositeAccount ac3 = new CompositeAccount("AC3");

ac1.AddAccount(ac2);
ac2.AddAccount(ac3);
ac3.AddAccount(ac1);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MyMoney.Model.Test
{
[TestClass]
public class EntryTests
{
[TestMethod]
public void TestCalculateNewBalanceWithDeposit()
{
Entry entry = new Entry(EntryType.Deposit, 10M);

Money oldBalance = 5M;
Money newBalance = entry.CalculateNewBalance(oldBalance);

Assert.IsTrue(newBalance > oldBalance);
Assert.AreEqual(newBalance, new Money(15M));
}

[TestMethod]
public void TestCalculateNewBalanceWithWithdrawal()
{
Entry entry = new Entry(EntryType.Withdrawal, 5M);

Money oldBalance = 10M;
Money newBalance = entry.CalculateNewBalance(oldBalance);

Assert.IsTrue(newBalance < oldBalance);
Assert.AreEqual(newBalance, new Money(5m));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MyMoney.Model.Test
{
[TestClass]
public class LeafAccountTests
{
[TestMethod]
public void TestDefaultAccountBalanceIsZero()
{
LeafAccount account = new LeafAccount("AC1");

Assert.AreEqual(account.Balance, Money.Zero);
}

[TestMethod]
public void TestAccountBalanceAllDeposits()
{
LeafAccount account = new LeafAccount("AC1");

account.AddEntry(new Entry(EntryType.Deposit, 15.05M));
account.AddEntry(new Entry(EntryType.Deposit, 67.32M));
account.AddEntry(new Entry(EntryType.Deposit, 11.10M));
account.AddEntry(new Entry(EntryType.Deposit, 112.35M));

Assert.AreEqual(account.Entries.Count(), 4);
Assert.AreEqual(account.Balance, 205.82M);
}
}
}

0 comments on commit 682e046

Please sign in to comment.