Beispiel #1
0
 public BankAccountBuilder(OId <BankAccount, Guid> id)
 {
     this.id         = id;
     employeeId      = OId.Of <Employee, Guid>(Guid.Parse("309dc64d-bde5-4ee5-9e21-33a517e2fe35"));
     accountHolderId = OId.Of <AccountHolder, Guid>(Guid.Parse("59ed2782-881b-49a9-8230-d0b3bb1c9072"));
     iban            = Iban.Of("DE37200505501340426749");
     accountCurrency = Currency.Euro;
 }
Beispiel #2
0
        public void TestShouldCreateIban_validated()
        {
            // Arrange
            const string iban = "123456789";

            // Act
            var result = Iban.Of(iban);

            // Assert
            Assert.IsTrue(result.IsValid);
            Assert.AreEqual(iban, result.GetObject().Value);
        }
Beispiel #3
0
        private static Task CreateAccountAsync(IMediator mediator)
        {
            System.Console.Clear();
            System.Console.Write("IBAN: ");
            var iban = Iban.Of(System.Console.ReadLine());
            var createBankAccount = new CreateBankAccount(OId.Of <AccountHolder, Guid>(Guid.NewGuid()),
                                                          OId.Of <Employee, Guid>(EmployeeId),
                                                          Currency.Euro,
                                                          iban,
                                                          TimeStamp.Of(DateTimeOffset.Now.ToUnixTimeSeconds()));

            return(mediator.Send(createBankAccount));
        }
Beispiel #4
0
        public void TestShouldCreateIban_invalid()
        {
            // Arrange
            const string iban = "";

            // Act
            var result = Iban.Of(iban);

            // Assert
            Assert.IsFalse(result.IsValid);
            var e = result.GetErrors().ToList();

            Assert.AreEqual(1, e.Count);
            Assert.AreEqual("Iban is invalid.", e.Single().Message);
        }
Beispiel #5
0
        private static Task Deposit(IMediator mediator, AvailableAccountsProjection availableAccountsProjection)
        {
            System.Console.Clear();
            System.Console.Write("IBAN: ");
            var iban = Iban.Of(System.Console.ReadLine());

            System.Console.Write("Amount: ");
            var amount        = decimal.Parse(System.Console.ReadLine());
            var bankAccountId = OId.Of <CoreDomain.BankAccount, Guid>(availableAccountsProjection.GetId(iban));
            var depositMoney  = new DepositMoney(bankAccountId,
                                                 Transaction.Of(Guid.NewGuid()),
                                                 new Money(amount, Currency.Euro),
                                                 TimeStamp.Of(DateTimeOffset.Now.ToUnixTimeSeconds()));

            return(mediator.Send(depositMoney));
        }
Beispiel #6
0
        public void CreateNewBankAccount_Always_SavesNewBankAccount()
        {
            var       bankAccountRepository = Substitute.For <IBankAccountRepository>();
            var       systemUnderTest       = new CreateBankAccountHandler(bankAccountRepository);
            var       employeeId            = OId.Of <Employee, Guid>(Guid.Parse("309dc64d-bde5-4ee5-9e21-33a517e2fe35"));
            var       accountHolderId       = OId.Of <AccountHolder, Guid>(Guid.Parse("59ed2782-881b-49a9-8230-d0b3bb1c9072"));
            var       iban              = Iban.Of("DE37200505501340426749");
            const int unixTimestamp     = 1;
            var       command           = new CreateBankAccount(accountHolderId, employeeId, Currency.Euro, iban, TimeStamp.Of(unixTimestamp));
            var       expectedAccountId = Guid.Parse("5fd9c8fe-2a2c-4d76-9c57-2460dd516dbf");

            UniqueId.OverrideNewGuid(expectedAccountId);

            systemUnderTest.Handle(command, CancellationToken.None).GetAwaiter().GetResult();

            var expectedEvents = new BankAccountEvent[] { new BankAccountCreated(expectedAccountId, accountHolderId.Value, iban.Value, Currency.Euro.Value, employeeId.Value, unixTimestamp) };

            bankAccountRepository.Received()
            .SaveAsync(Arg.Is <BankAccount>(it => it.IsCorrectBankAccount(aggregate =>
                                                                          aggregate.Id.Value.Equals(expectedAccountId) &&
                                                                          aggregate.Version == 1 &&
                                                                          aggregate.GetUncommittedEvents().SequenceEqual(expectedEvents))));
            UniqueId.ResetOverride();
        }
 void IApply <BankAccountCreated> .Apply(BankAccountCreated @event)
 {
     iban     = Iban.Of(@event.Iban);
     currency = Currency.Of(@event.Currency);
 }
Beispiel #8
0
        public void Build_WithInvalidIban_ThrowsException()
        {
            const string invalidIban = "invalidIban";

            this.Invoking(_ => Iban.Of(invalidIban)).Should().Throw <ConstraintViolationException>();
        }
Beispiel #9
0
        public void Build_WithValidIban_ReturnsIban(string validIban, string expectedIban)
        {
            var systemUnderTest = Iban.Of(validIban);

            systemUnderTest.Value.Should().Be(expectedIban);
        }