public void NoSharesOwned() { var stock = new Stock(Guid.NewGuid()); stock.List("ABC", "ABC Pty Ltd", new Date(1974, 01, 01), false, AssetCategory.AustralianStocks); var transaction = new Disposal() { Id = Guid.NewGuid(), Date = new Date(2020, 02, 01), Stock = stock, Comment = "Test Disposal", Units = 100, AveragePrice = 10.00m, TransactionCosts = 19.95m, CgtMethod = CgtCalculationMethod.FirstInFirstOut, CreateCashTransaction = true }; var mockRepository = new MockRepository(MockBehavior.Strict); var holding = mockRepository.Create <IHolding>(); holding.Setup(x => x.IsEffectiveAt(new Date(2020, 02, 01))).Returns(false); var cashAccount = mockRepository.Create <ICashAccount>(); var handler = new DisposalHandler(); Action a = () => handler.Apply(transaction, holding.Object, cashAccount.Object); a.Should().Throw <NoSharesOwnedException>(); mockRepository.Verify(); }
public void SingleParcelPartiallySold() { var stock = new Stock(Guid.NewGuid()); stock.List("ABC", "ABC Pty Ltd", new Date(1974, 01, 01), false, AssetCategory.AustralianStocks); var transaction = new Disposal() { Id = Guid.NewGuid(), Date = new Date(2020, 02, 01), Stock = stock, Comment = "Test Disposal", Units = 100, AveragePrice = 20.00m, TransactionCosts = 19.95m, CgtMethod = CgtCalculationMethod.FirstInFirstOut, CreateCashTransaction = true }; var mockRepository = new MockRepository(MockBehavior.Strict); var parcelId = Guid.NewGuid(); var parcel = mockRepository.Create <IParcel>(); parcel.Setup(x => x.Id).Returns(parcelId); parcel.Setup(x => x.EffectivePeriod).Returns(new DateRange(new Date(2007, 01, 01), Date.MaxValue)); parcel.Setup(x => x.AquisitionDate).Returns(new Date(2007, 01, 01)); parcel.Setup(x => x.Properties[new Date(2020, 02, 01)]).Returns(new ParcelProperties(200, 1000.00m, 1500.00m)); var holding = mockRepository.Create <IHolding>(); holding.Setup(x => x.IsEffectiveAt(new Date(2020, 02, 01))).Returns(true); holding.Setup(x => x.Properties[new Date(2020, 02, 01)]).Returns(new HoldingProperties(200, 1000.00m, 1000.00m)); holding.Setup(x => x.Parcels(new Date(2020, 02, 01))).Returns(new IParcel[] { parcel.Object }); holding.Setup(x => x.DisposeOfParcel(parcelId, new Date(2020, 02, 01), 100, 1980.05m, 1230.05m, CgtMethod.Discount, transaction)).Verifiable(); var cashAccount = mockRepository.Create <ICashAccount>(); cashAccount.Setup(x => x.Transfer(new Date(2020, 02, 01), 2000.00m, "Sale of ABC")).Verifiable(); cashAccount.Setup(x => x.FeeDeducted(new Date(2020, 02, 01), 19.95m, "Brokerage for sale of ABC")).Verifiable(); var handler = new DisposalHandler(); handler.Apply(transaction, holding.Object, cashAccount.Object); mockRepository.Verify(); }
public void IncorrectTransactionType() { var transaction = new CashTransaction() { Id = Guid.NewGuid(), Date = new Date(2020, 01, 01), Comment = "Test Deposit", CashTransactionType = BankAccountTransactionType.Deposit, Amount = 100.00m }; var mockRepository = new MockRepository(MockBehavior.Strict); var holding = mockRepository.Create <IHolding>(); var cashAccount = mockRepository.Create <ICashAccount>(); var handler = new DisposalHandler(); Action a = () => handler.Apply(transaction, holding.Object, cashAccount.Object); a.Should().Throw <ArgumentException>(); mockRepository.Verify(); }