Commit b04747e

unknown <mo@.(none)>
2010-01-27 03:42:55
fixed broken tests and updated build script to exclude test.helpers project in app.compile.
1 parent 567dc4e
build/project.build
@@ -38,6 +38,7 @@
 				<include name="${build.config.dir}\**\*.cs" />
 				<exclude name="${product.dir}\**\AssemblyInfo.cs" />
 				<exclude name="${product.dir}\**\*Specs.cs" />
+				<exclude name="${product.dir}\commons\testing\**\*.cs" />
 			</sources>			
 			<references>
 				<include name="${build.lib.dir}\app\**\*.dll" />
product/client/domain/Accounting/AccountHolderSpecs.cs
@@ -26,13 +26,10 @@ namespace MoMoney.Domain.accounting
 
             context c = () =>
                         {
-                            first_unpaid_bill = an<Bill>();
-                            second_unpaid_bill = an<Bill>();
-                            paid_bill = an<Bill>();
-
-                            first_unpaid_bill.is_told_to(x => x.is_paid_for()).it_will_return(false);
-                            second_unpaid_bill.is_told_to(x => x.is_paid_for()).it_will_return(false);
-                            paid_bill.is_told_to(x => x.is_paid_for()).it_will_return(true);
+                            
+                            first_unpaid_bill = Bill.New(null,10.00, DateTime.Now);
+                            second_unpaid_bill = Bill.New(null, 11.00, DateTime.Now);
+                            paid_bill = Bill.New(null, 0.00, DateTime.Now);
                         };
 
             because b = () =>
@@ -59,13 +56,13 @@ namespace MoMoney.Domain.accounting
                             income_for_february_2008 = MockRepository.GenerateMock<Income>();
 
                             income_for_january_2007.is_told_to(x => x.date_of_issue).it_will_return<Date>(new DateTime(2007, 01, 01));
-                            income_for_january_2007.is_told_to(x => x.amount_tendered).it_will_return(new Money(1000, 00));
+                            income_for_january_2007.is_told_to(x => x.amount_tendered).it_will_return(new Money(1000.00));
 
                             income_for_february_2007.is_told_to(x => x.date_of_issue).it_will_return<Date>(new DateTime(2007, 02, 01));
-                            income_for_february_2007.is_told_to(x => x.amount_tendered).it_will_return(new Money(1000, 00));
+                            income_for_february_2007.is_told_to(x => x.amount_tendered).it_will_return(new Money(1000.00));
 
                             income_for_february_2008.is_told_to(x => x.date_of_issue).it_will_return<Date>(new DateTime(2008, 02, 01));
-                            income_for_february_2008.is_told_to(x => x.amount_tendered).it_will_return(new Money(1000, 00));
+                            income_for_february_2008.is_told_to(x => x.amount_tendered).it_will_return(new Money(1000.00));
                         };
 
             because b = () =>
@@ -76,7 +73,7 @@ namespace MoMoney.Domain.accounting
                             result = sut.calculate_income_for(2007);
                         };
 
-            it should_return_the_correct_amount = () => result.should_be_equal_to(2000.as_money());
+            it should_return_the_correct_amount = () => result.should_be_equal_to(2000);
 
             static Money result;
             static Income income_for_january_2007;
product/client/domain/Accounting/BillSpecs.cs
@@ -36,7 +36,7 @@ namespace MoMoney.Domain.Accounting
 
         context c = () =>
                         {
-                            one_hundred_twenty_three_dollars_fourty_five_cents = new Money(123, 45);
+                            one_hundred_twenty_three_dollars_fourty_five_cents = new Money(123.45);
                             direct_energy = an<Company>();
                         };
 
product/client/domain/Core/Money.cs
@@ -1,60 +1,47 @@
 using System;
-using gorilla.commons.utility;
 
 namespace MoMoney.Domain.Core
 {
     [Serializable]
     public class Money : IEquatable<Money>
     {
-        readonly long dollars;
-        readonly int cents;
+        double value;
 
-        public Money(long dollars) : this(dollars, 0) {}
+        public static readonly Money Zero = new Money(0);
 
-        public Money(long dollars, int cents)
+        public Money(double value)
         {
-            this.dollars = dollars;
-            this.cents = cents;
-            if (this.cents >= 100)
-            {
-                this.dollars += (this.cents/100).to_long();
-                this.cents = this.cents%100;
-            }
+            this.value = value;
         }
 
         public Money add(Money other)
         {
-            var new_dollars = dollars + other.dollars;
-            if (other.cents + cents > 100)
-            {
-                ++new_dollars;
-                var pennies = cents + other.cents - 100;
-                return new Money(new_dollars, pennies);
-            }
-            return new Money(new_dollars, cents + other.cents);
+            return new Money(value + other.value);
+        }
+
+        static public implicit operator Money(double value)
+        {
+            return new Money(value);
         }
 
         public bool Equals(Money other)
         {
             if (ReferenceEquals(null, other)) return false;
             if (ReferenceEquals(this, other)) return true;
-            return other.dollars == dollars && other.cents == cents;
+            return other.value.Equals(value);
         }
 
         public override bool Equals(object obj)
         {
             if (ReferenceEquals(null, obj)) return false;
             if (ReferenceEquals(this, obj)) return true;
-            if (obj.GetType() != typeof (Money)) return false;
+            if (!(obj is Money)) return false;
             return Equals((Money) obj);
         }
 
         public override int GetHashCode()
         {
-            unchecked
-            {
-                return (dollars.GetHashCode()*397) ^ cents;
-            }
+            return value.GetHashCode();
         }
 
         static public bool operator ==(Money left, Money right)
@@ -69,7 +56,7 @@ namespace MoMoney.Domain.Core
 
         public override string ToString()
         {
-            return "{0}.{1:d2}".formatted_using(dollars, cents);
+            return value.ToString("c");
         }
     }
 }
\ No newline at end of file
product/client/domain/Core/MoneyExtensions.cs
@@ -1,31 +0,0 @@
-using gorilla.commons.utility;
-
-namespace MoMoney.Domain.Core
-{
-    static public class MoneyExtensions
-    {
-        static public Money as_money(this double amount)
-        {
-            var quotient = amount/0.01;
-            var wholePart = (int) quotient;
-            var mantissa = ((decimal) quotient) - wholePart;
-
-            var roundedAmount = mantissa >= .5m ? .01*(wholePart + 1) : .01*wholePart;
-            var cents = (roundedAmount*100).to_int();
-
-            return new Money(cents/100, cents%100);
-        }
-
-        static public Money as_money(this int amount)
-        {
-            var quotient = amount/0.01;
-            var wholePart = (int) quotient;
-            var mantissa = ((decimal) quotient) - wholePart;
-
-            var roundedAmount = mantissa >= .5m ? .01*(wholePart + 1) : .01*wholePart;
-            var cents = (roundedAmount*100).to_int();
-
-            return new Money(cents/100, cents%100);
-        }
-    }
-}
\ No newline at end of file
product/client/domain/Core/MoneyExtensionsSpecs.cs
@@ -5,9 +5,9 @@ namespace MoMoney.Domain.Core
 {
     public class when_converting_a_valid_amount_to_a_money : concerns
     {
-        it should_return_the_correct_money = () => result.should_be_equal_to(new Money(1, 99));
+        it should_return_the_correct_money = () => result.should_be_equal_to(new Money(1.99));
 
-        because b = () => { result = 1.99.as_money(); };
+        because b = () => { result = 1.99; };
 
         static Money result;
     }
product/client/domain/Core/MoneySpecs.cs
@@ -6,14 +6,16 @@ namespace MoMoney.Domain.Core
     [Concern(typeof (Money))]
     public class when_adding_two_monies_together : concerns_for<Money>
     {
-        it should_return_the_correct_money = () => result.should_be_equal_to(new Money(2, 98));
+        it should_return_the_correct_money = () => result.should_be_equal_to(new Money(2.98));
 
-
-        because b = () => { result = sut.add(new Money(1, 99)); };
+        because b = () =>
+                    {
+                        result = sut.add(new Money(1.99));
+                    };
 
         public override Money create_sut()
         {
-            return new Money(0, 99);
+            return new Money(0.99);
         }
 
         static Money result;
@@ -25,25 +27,16 @@ namespace MoMoney.Domain.Core
         it they_should_be_equal = () => result.should_be_equal_to(true);
 
 
-        because b = () => { result = sut.Equals(new Money(1, 99)); };
+        because b = () =>
+                    {
+                        result = sut.Equals(new Money(1.99));
+                    };
 
         public override Money create_sut()
         {
-            return new Money(1, 99);
+            return new Money(1.99);
         }
 
         static bool result;
     }
-
-    [Concern(typeof (Money))]
-    public class when_creating_a_money_with_pennies_greater_than_a_dollar : concerns_for<Money>
-    {
-        it should_create_a_money_representing_the_correct_amount_of_dollars_and_pennies =
-            () => sut.should_be_equal_to(new Money(3, 00));
-
-        public override Money create_sut()
-        {
-            return new Money(1, 200);
-        }
-    }
 }
\ No newline at end of file
product/client/domain/Domain.csproj
@@ -80,7 +80,6 @@
     <Compile Include="core\GenericEntity.cs" />
     <Compile Include="core\Entity.cs" />
     <Compile Include="core\Money.cs" />
-    <Compile Include="core\MoneyExtensions.cs" />
     <Compile Include="core\MoneyExtensionsSpecs.cs" />
     <Compile Include="core\MoneySpecs.cs" />
     <Compile Include="core\Month.cs" />
product/client/presentation/Model/Menu/File/SaveChangesPresenter.cs
@@ -14,6 +14,10 @@ namespace MoMoney.Presentation.Model.Menu.File
         readonly ISaveAsCommand save_as_command;
         ISaveChangesCallback callback;
 
+        protected SaveChangesPresenter()
+        {
+        }
+
         public SaveChangesPresenter(IProjectController current_project, ISaveChangesView view, ISaveAsCommand save_as_command)
         {
             this.current_project = current_project;
@@ -21,12 +25,12 @@ namespace MoMoney.Presentation.Model.Menu.File
             this.view = view;
         }
 
-        public void present(IShell shell)
+        public virtual void present(IShell shell)
         {
             throw new NotImplementedException();
         }
 
-        public void run(ISaveChangesCallback item)
+        public virtual void run(ISaveChangesCallback item)
         {
             callback = item;
             if (current_project.has_unsaved_changes())
@@ -40,7 +44,7 @@ namespace MoMoney.Presentation.Model.Menu.File
             }
         }
 
-        public void save()
+        public virtual void save()
         {
             if (current_project.has_been_saved_at_least_once())
             {
@@ -53,12 +57,12 @@ namespace MoMoney.Presentation.Model.Menu.File
             callback.saved();
         }
 
-        public void dont_save()
+        public virtual void dont_save()
         {
             callback.not_saved();
         }
 
-        public void cancel()
+        public virtual void cancel()
         {
             callback.cancelled();
         }
product/client/service/Application/AddNewIncomeCommand.cs
@@ -1,6 +1,5 @@
 using System.Linq;
 using gorilla.commons.utility;
-using MoMoney.Domain.Core;
 using MoMoney.Domain.repositories;
 using MoMoney.DTO;
 using MoMoney.Service.Contracts.Application;
@@ -35,7 +34,7 @@ namespace MoMoney.Service.Application
                     .find_company_by(item.company_id)
                     .pay(
                     query.fetch(),
-                    item.amount.as_money(),
+                    item.amount,
                     item.recieved_date
                     );
             }
@@ -46,7 +45,7 @@ namespace MoMoney.Service.Application
             if (all_income.all().Count() == 0) return false;
             return all_income
                        .all()
-                       .where(x => x.amount_tendered.Equals(income.amount.as_money()))
+                       .where(x => x.amount_tendered.Equals(income.amount))
                        .where(x => x.company.id.Equals(income.company_id))
                        .where(x => x.date_of_issue.Equals(income.recieved_date))
                        .Count() > 0;
product/client/service/Application/AddNewIncomeCommandSpecs.cs
@@ -4,7 +4,6 @@ using Gorilla.Commons.Testing;
 using gorilla.commons.utility;
 using Gorilla.Commons.Utility;
 using MoMoney.Domain.Accounting;
-using MoMoney.Domain.Core;
 using MoMoney.Domain.repositories;
 using MoMoney.DTO;
 using MoMoney.Service.Contracts.Application;
@@ -51,7 +50,7 @@ namespace MoMoney.Service.Application
                          recieved_date = today,
                      };
 
-            when_the(matching_income).is_asked_for(x => x.amount_tendered).it_will_return(100.as_money());
+            when_the(matching_income).is_asked_for(x => x.amount_tendered).it_will_return(100);
             when_the(matching_income).is_asked_for(x => x.company).it_will_return(a_company);
             when_the(matching_income).is_asked_for(x => x.date_of_issue).it_will_return(today);
             when_the(a_company).is_asked_for(x => x.id).it_will_return(id);
product/client/service/Application/SaveNewBillCommand.cs
@@ -1,4 +1,3 @@
-using MoMoney.Domain.Core;
 using MoMoney.Domain.repositories;
 using MoMoney.DTO;
 using MoMoney.Service.Contracts.Application;
@@ -23,7 +22,7 @@ namespace MoMoney.Service.Application
                 .issue_bill_to(
                 tasks.fetch(),
                 item.due_date,
-                item.total.as_money()
+                item.total
                 );
         }
     }