Ejemplo n.º 1
0
        public async Task Interest_ApplyInterest_CreatesValidTransaction()
        {
            // Arrange
            var context      = FakeContext.Get();
            var mockDateTime = new MockDateTime {
                Now = DateTime.Today.AddDays(600).Date
            };
            var lastCalculatedDate = DateTime.Today.Date;
            var account            = context.Accounts.Single(a => a.AccountId == 5);

            // Act
            var sut = new ApplyInterestCommandHandler(context, mockDateTime);
            await sut.Handle(new ApplyInterestsCommand { AccountId = 5, APR = 5, LastCalculatedDate = lastCalculatedDate }, CancellationToken.None);

            // Assert
            account.Transactions.Count.ShouldBe(1);
            var transaction = context.Transactions.Single(t => t.AccountId == 5);

            transaction.Balance.ShouldBe(108333.33m);
            transaction.Amount.ShouldBe(8333.33m);
            transaction.AccountId.ShouldBe(5);
            transaction.Date.ShouldBe(mockDateTime.Now);
            transaction.Operation.ShouldBe(Operation.Credit);
            transaction.Type.ShouldBe(TransactionType.Credit);
            transaction.Symbol.ShouldBe(Interest.Symbol);
        }
Ejemplo n.º 2
0
        public void Store_Directory()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.RegisterDirectory(@"C:\dir");

            var dateTime = new MockDateTime(new DateTime(2010, 10, 1, 0, 0, 0));

            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <IFileSystem>(fileSystem);
            serviceContainer.Register <IDateTimeService>(dateTime);

            var executionContext = new ExecutionContext(serviceContainer);

            var directory = new DirectoryObject(@"C:\dir", fileSystem);

            var storage         = new DirectoryStorage(@"C:\backup");
            var storageInstance = storage.CreateInstance(executionContext);

            var backupContext = new BackupContext(null, executionContext);
            var result        = storageInstance.Store(directory, backupContext).ToArray();

            var expected = new IOperation[] {
                new CreateDirectoryOperation(new DirectoryObject(@"C:\backup\2010-10-01 00-00-00\C\dir", fileSystem), fileSystem, executionContext)
            };

            CollectionAssert.AreEqual(expected, result);
        }
Ejemplo n.º 3
0
        public async Task ShouldSetRecordStatusTextForApprenticeshipWithUpdateReadyForReview()
        {
            MockDateTime.Setup(m => m.Now).Returns(new DateTime(1998, 12, 8));
            MockMediator.Setup(m => m.SendAsync(It.IsAny <GetApprenticeshipQueryRequest>()))
            .ReturnsAsync(new GetApprenticeshipQueryResponse
            {
                Apprenticeship =
                    new Apprenticeship {
                    PaymentStatus             = PaymentStatus.Active
                    , StartDate               = new DateTime(1998, 11, 1)
                    , PendingUpdateOriginator = Originator.Provider
                }
            });

            MockMediator.Setup(m => m.SendAsync(It.IsAny <GetApprenticeshipUpdateRequest>()))
            .ReturnsAsync(new GetApprenticeshipUpdateResponse
            {
                ApprenticeshipUpdate =
                    new ApprenticeshipUpdate {
                    ApprenticeshipId = 1L, Originator = Originator.Provider
                }
            });

            var result = await Orchestrator.GetApprenticeship("hashedAccountId", "hashedApprenticeshipId", "UserId");

            MockMediator.Verify(m => m.SendAsync(It.IsAny <GetApprenticeshipQueryRequest>()), Times.Once);
            result.Data.PendingChanges.Should().Be(PendingChanges.ReadyForApproval);
        }
Ejemplo n.º 4
0
        public void Arrange()
        {
            _now = new DateTime(DateTime.Now.Year, 11, 01);

            AcademicYearValidator.Setup(m => m.IsAfterLastAcademicYearFundingPeriod).Returns(true);
            AcademicYearValidator.Setup(m => m.Validate(It.IsAny <DateTime>())).Returns(AcademicYearValidationResult.Success);

            MockDateTime.Setup(m => m.Now).Returns(_now);
        }
Ejemplo n.º 5
0
    public void GoneInSixtySeconds()
    {
        MockDateTime d = new MockDateTime();

        d.fakeDate = '2010-01-01 12:00:00';
        Stopwatch s = new Stopwatch();

        s.Run();
        d.fakeDate = '2010-01-01 12:01:00';
        s.Stop();
        assertEquals(60, s.ElapsedSeconds);
    }
        public async Task Withdrawal_ValidWithdrawal_Debited()
        {
            // Arrange
            IDateTime time    = new MockDateTime();
            var       context = FakeContext.Get();

            // Act
            var sut = new CreateAccountDebitCommandHandler(context, time);
            await sut.Handle(new CreateAccountDebitCommand { AccountId = 4, Amount = 250.145612m }, CancellationToken.None);

            // Assert
            var account = await context.Accounts.Include(a => a.Transactions).SingleOrDefaultAsync(a => a.AccountId == 4);

            account.Balance.ShouldBe(249.85m);
        }
        public async Task Deposit_ValidDeposit_Credited()
        {
            // Arrange
            IDateTime time    = new MockDateTime();
            var       context = FakeContext.Get();

            // Act
            var sut = new CreateAccountDepositCommandHandler(context, time);
            await sut.Handle(new CreateAccountDepositCommand()
            {
                AccountId = 1, Amount = 500m
            }, CancellationToken.None);

            // Assert
            context.Accounts.Single(a => a.AccountId == 1).Balance.ShouldBe(1000m);
        }
Ejemplo n.º 8
0
        public async Task Loan_ApplyInterest_CalculatedCorrectly()
        {
            // Arrange
            var context      = FakeContext.Get();
            var mockDateTime = new MockDateTime {
                Now = DateTime.Today.AddDays(60).Date
            };
            var lastCalculatedDate = DateTime.Today.Date;
            var account            = context.Accounts.Single(a => a.AccountId == 5);

            // Act
            var sut = new ApplyInterestCommandHandler(context, mockDateTime);
            await sut.Handle(new ApplyInterestsCommand { AccountId = 5, APR = 5, LastCalculatedDate = lastCalculatedDate }, CancellationToken.None);

            // Assert
            account.Balance.ShouldBe(100833.33m);
        }
        public async Task Withdrawal_MoreThanBalance_ThrowsException()
        {
            // Arrange
            IDateTime time    = new MockDateTime();
            var       context = FakeContext.Get();

            // Act
            var sut = new CreateAccountDebitCommandHandler(context, time);

            // Assert
            await Assert.ThrowsAsync <InsufficientFundsException>(() =>
                                                                  sut.Handle(new CreateAccountDebitCommand {
                AccountId = 1, Amount = 501m
            }, CancellationToken.None));

            context.Accounts.Single(a => a.AccountId == 1).Balance.ShouldBe(500m);
        }
Ejemplo n.º 10
0
        public async Task Transfer_ValidAmounts_CreditAndDebitCorrectly()
        {
            // Arrange
            IDateTime time    = new MockDateTime();
            var       context = FakeContext.Get();

            // Act
            var sut = new CreateAccountTransferCommandHandler(context, time);
            await sut.Handle(new CreateAccountTransferCommand { AccountIdFrom = 1, AccountIdTo = 2, Amount = 250m }, CancellationToken.None);

            // Assert
            var accOne = context.Accounts.Single(a => a.AccountId == 1);
            var accTwo = context.Accounts.Single(a => a.AccountId == 2);

            accOne.Balance.ShouldBe(250m);
            accTwo.Balance.ShouldBe(750m);
        }
Ejemplo n.º 11
0
        public async Task IfIsAfterR14CutoffTimeThenDateOfchangeIsStartOfacademicYear()
        {
            _testApprenticeship.StartDate = AcademicYearDateProvider.Object.CurrentAcademicYearStartDate.AddMonths(-6);          // Apprenticeship was started last academic year
            _testApprenticeship.PauseDate = AcademicYearDateProvider.Object.CurrentAcademicYearStartDate.AddMonths(-3);          // Apprenticeship was was paused last academic year

            MockDateTime.Setup(x => x.Now).Returns(AcademicYearDateProvider.Object.LastAcademicYearFundingPeriod.AddMinutes(1)); // resume after r14 cutoff
            OrchestratorResponse <ConfirmationStateChangeViewModel> response = await Orchestrator.GetChangeStatusConfirmationViewModel(
                "ABC123",
                "CDE321",
                ChangeStatusType.Resume,
                WhenToMakeChangeOptions.Immediately,
                null, null,
                "user123");



            response.Data.ChangeStatusViewModel.DateOfChange.DateTime.Should().Be(AcademicYearDateProvider.Object.CurrentAcademicYearStartDate);
        }
        public async Task Withdrawal_NegativeAmount_ThrowsException()
        {
            // Arrange
            IDateTime time    = new MockDateTime();
            var       context = FakeContext.Get();

            // Arrange
            var sut = new CreateAccountDebitCommandHandler(context, time);

            // Assert
            await Assert.ThrowsAsync <NegativeAmountException>
                (() => sut.Handle(new CreateAccountDebitCommand()
            {
                AccountId = 1, Amount = -500m
            }, CancellationToken.None));

            context.Accounts.Single(a => a.AccountId == 1).Balance.ShouldBe(500m);
        }
        public async Task Withdrawal_Transaction_Created()
        {
            // Arrange
            IDateTime time    = new MockDateTime();
            var       context = FakeContext.Get();

            // Act
            var sut = new CreateAccountDebitCommandHandler(context, time);
            await sut.Handle(new CreateAccountDebitCommand { AccountId = 3, Amount = 250m }, CancellationToken.None);

            // Assert
            var transaction = await context.Transactions.SingleOrDefaultAsync(t => t.AccountId == 3);

            transaction.Amount.ShouldBe(-250m);
            transaction.AccountId.ShouldBe(3);
            transaction.Operation.ShouldBe(Operation.Withdrawal);
            transaction.Type.ShouldBe(TransactionType.Debit);
        }
        public void ThenInvalidStateExceptionOccursWhenNoViewModelReturned()
        {
            MockDateTime.Setup(m => m.Now).Returns(new DateTime(1998, 1, 1));
            MockMediator.Setup(m => m.SendAsync(It.IsAny <GetApprenticeshipQueryRequest>()))
            .ReturnsAsync(new GetApprenticeshipQueryResponse
            {
                Apprenticeship =
                    new Apprenticeship
                {
                    PaymentStatus = PaymentStatus.Active,
                    StartDate     = new DateTime(1998, 1, 1)
                }
            });
            MockMediator.Setup(m => m.SendAsync(It.IsAny <GetApprenticeshipUpdateRequest>()))
            .ReturnsAsync(new GetApprenticeshipUpdateResponse());

            Assert.ThrowsAsync <InvalidStateException>(() => Orchestrator.GetViewChangesViewModel("hashedAccountId", "hashedApprenticeshipId", "UserId"));
        }
Ejemplo n.º 15
0
        public async Task Interest_ZeroBalance_ShouldNotApplyInterest()
        {
            // Arrange
            var context      = FakeContext.Get();
            var mockDateTime = new MockDateTime {
                Now = DateTime.Today.AddDays(200).Date
            };
            var calculatedDate = DateTime.Today.Date;
            var account        = context.Accounts.Single(a => a.AccountId == 5);

            account.Balance = 0m;
            context.SaveChanges();

            // Act
            var sut = new ApplyInterestCommandHandler(context, mockDateTime);
            await sut.Handle(new ApplyInterestsCommand { AccountId = 5, APR = 5, LastCalculatedDate = calculatedDate }, CancellationToken.None);

            // Assert
            account.Balance.ShouldBe(0m);
            account.Transactions.Count.ShouldBe(0);
        }
        public async Task Deposit_Transaction_Created()
        {
            // Arrange
            IDateTime time    = new MockDateTime();
            var       context = FakeContext.Get();

            // Act
            var sut = new CreateAccountDepositCommandHandler(context, time);
            await sut.Handle(new CreateAccountDepositCommand()
            {
                AccountId = 1, Amount = 500m
            }, CancellationToken.None);

            // Assert
            var transaction = context.Transactions.Single(t => t.AccountId == 1);

            transaction.AccountId.ShouldBe(1);
            transaction.Amount.ShouldBe(500m);
            transaction.Balance.ShouldBe(1000m);
            transaction.Type.ShouldBe(TransactionType.Credit);
            transaction.Operation.ShouldBe(Operation.Credit);
        }
Ejemplo n.º 17
0
        public async Task ShouldSetStatusTextForApprenticeshipNotStarted(int nowMonth, int nowDay, int startMonth)
        {
            MockDateTime.Setup(m => m.Now).Returns(new DateTime(1998, nowMonth, nowDay));
            MockMediator.Setup(m => m.SendAsync(It.IsAny <GetApprenticeshipQueryRequest>()))
            .ReturnsAsync(new GetApprenticeshipQueryResponse
            {
                Apprenticeship =
                    new Apprenticeship
                {
                    PaymentStatus = PaymentStatus.Active,
                    StartDate     = new DateTime(1998, startMonth, 1)
                }
            });
            MockMediator.Setup(m => m.SendAsync(It.IsAny <GetApprenticeshipUpdateRequest>()))
            .ReturnsAsync(new GetApprenticeshipUpdateResponse());

            var result = await Orchestrator.GetApprenticeship("hashedAccountId", "hashedApprenticeshipId", "UserId");

            MockMediator.Verify(m => m.SendAsync(It.IsAny <GetApprenticeshipQueryRequest>()), Times.Once);

            result.Data.Status.Should().Be("Waiting to start");
        }
Ejemplo n.º 18
0
        public void Store_Drive()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.RegisterDrive(@"C:");

            var dateTime = new MockDateTime(new DateTime(2010, 10, 1, 0, 0, 0));

            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <IFileSystem>(fileSystem);
            serviceContainer.Register <IDateTimeService>(dateTime);

            var executionContext = new ExecutionContext(serviceContainer);

            var drive = new DriveObject(@"C:", fileSystem);

            var storage         = new DirectoryStorage(@"C:\backup");
            var storageInstance = storage.CreateInstance(executionContext);

            var backupContext = new BackupContext(null, executionContext);
            var result        = storageInstance.Store(drive, backupContext).ToArray();
        }
Ejemplo n.º 19
0
        public async Task Transfer_ValidAmounts_CreateTransactions()
        {
            // Arrange
            IDateTime time    = new MockDateTime();
            var       context = FakeContext.Get();

            // Act
            var sut = new CreateAccountTransferCommandHandler(context, time);
            await sut.Handle(new CreateAccountTransferCommand { AccountIdFrom = 1, AccountIdTo = 2, Amount = 250m }, CancellationToken.None);

            // Assert
            var transactionFrom = context.Transactions.Single(t => t.AccountId == 1);
            var transactionTo   = context.Transactions.Single(t => t.AccountId == 2);

            transactionFrom.Operation.ShouldBe(Operation.TransferDebit);
            transactionFrom.Type.ShouldBe(TransactionType.Debit);
            transactionFrom.Amount.ShouldBe(-250m);
            transactionFrom.Balance.ShouldBe(250m);
            transactionTo.Operation.ShouldBe(Operation.Transfer);
            transactionTo.Type.ShouldBe(TransactionType.Credit);
            transactionTo.Amount.ShouldBe(250m);
            transactionTo.Balance.ShouldBe(750m);
        }
Ejemplo n.º 20
0
        public void BackupDirectoryPath()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.RegisterFile(@"C:\file");

            var dateTime = new MockDateTime(new DateTime(2010, 10, 1, 0, 0, 0));

            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <IFileSystem>(fileSystem);
            serviceContainer.Register <IDateTimeService>(dateTime);

            var executionContext = new ExecutionContext(serviceContainer);

            var file = new FileObject(@"C:\file", fileSystem);

            var storage         = new DirectoryStorage(@"C:\backup");
            var storageInstance = (DirectoryStorageInstance)storage.CreateInstance(executionContext);

            var expected = Path.Parse(@"C:\backup").Combine(dateTime.GetCurrentDateTime().ToString("yyyy-MM-dd HH-mm-ss"));

            Assert.AreEqual(expected, storageInstance.BackupDirectoryPath);
        }
Ejemplo n.º 21
0
 protected void SetUtcDateTime(DateTime now) =>
 MockDateTime
 .Setup(m => m.UtcNow)
 .Returns(now);
Ejemplo n.º 22
0
 protected void SetLocalDateTime(DateTime now) =>
 MockDateTime
 .Setup(m => m.Now)
 .Returns(now);