Beispiel #1
0
        public void CanChange_Attached_SubTransaction()
        {
            Account     Account     = TestBudget.Budget.Accounts[0];
            Transaction transaction = new Transaction();

            transaction.Amount = 100;
            transaction.MakeSplitTransaction();
            Account.Transactions.Add(transaction);

            var subTransaction = transaction.SubTransactions.Create();

            subTransaction.Amount = 50;

            var subTransaction2 = transaction.SubTransactions.Create();

            subTransaction2.Amount = 50;

            TestBudget.BudgetModel.SaveChanges();
            TestBudget.ClearEvents();

            subTransaction.Amount = 100;

            TestBudget.BudgetModel.SaveChanges();

            Assert.That(TestBudget.TestEvents, Has.Count.EqualTo(1));
            Assert.That(TestBudget.TestEvents[0], Is.TypeOf <GroupedFieldChangeEvent>());

            GroupedFieldChangeEvent groupedFieldChangeEvent = (GroupedFieldChangeEvent)TestBudget.TestEvents[0];

            Assert.That(groupedFieldChangeEvent.GroupedEvents, Has.Count.EqualTo(1));
            Assert.That(groupedFieldChangeEvent.GroupedEvents[0].EntityType, Is.EqualTo(nameof(SubTransaction)));
            var change = groupedFieldChangeEvent.GroupedEvents[0].Changes[nameof(SubTransaction.Amount)];

            Assert.That(change.NewValue, Is.EqualTo(CurrencyConverter.ToLongValue(100M, subTransaction.GetCurrencyDenominator())));
        }
Beispiel #2
0
        public void CreateSubTransaction()
        {
            Account     Account     = TestBudget.Budget.Accounts[0];
            Transaction transaction = new Transaction();

            transaction.MakeSplitTransaction();
            Account.Transactions.Add(transaction);

            var subTransaction = transaction.SubTransactions.Create();

            subTransaction.Amount = 100;

            TestBudget.BudgetModel.SaveChanges();
            Assert.That(TestBudget.TestEvents.Count, Is.EqualTo(1));

            GroupedFieldChangeEvent evt = TestBudget.TestEvents[0] as GroupedFieldChangeEvent;

            Assert.NotNull(evt);

            EntityCreatedEvent subTransactionCreatedEvent = evt.GroupedEvents[1] as EntityCreatedEvent;

            Assert.NotNull(subTransactionCreatedEvent);

            Assert.That(subTransactionCreatedEvent.EntityType, Is.EqualTo(nameof(SubTransaction)));
            Assert.That(subTransactionCreatedEvent.Changes[nameof(SubTransaction.Amount)].NewValue, Is.EqualTo(CurrencyConverter.ToLongValue(100M, subTransaction.GetCurrencyDenominator())));
            Assert.That(subTransactionCreatedEvent.Changes[nameof(SubTransactionSnapshot.Amount_Denominator)].NewValue, Is.EqualTo(subTransaction.GetCurrencyDenominator()));
            Assert.That(transaction.SubTransactions[0], Is.EqualTo(subTransaction));
        }
 public void Handle(GroupedFieldChangeEvent message)
 {
     foreach (var groupedEvent in message.GroupedEvents)
     {
         if (groupedEvent.EntityType == nameof(Transaction))
         {
             if (groupedEvent is EntityCreatedEvent entityCreatedEvent)
             {
                 this.Handle(entityCreatedEvent);
             }
             else if (groupedEvent is EntityUpdatedEvent entityUpdatedEvent)
             {
                 this.Handle(entityUpdatedEvent);
             }
         }
     }
 }
 public void Handle(GroupedFieldChangeEvent message)
 {
     if (!_budgetModel.IsSavingLocally)
     {
         foreach (var evt in message.GroupedEvents)
         {
             if (evt.EntityType == typeof(TEntity).Name)
             {
                 if (evt is EntityCreatedEvent entityCreatedEvent)
                 {
                     Handle(entityCreatedEvent);
                 }
                 else if (evt is EntityUpdatedEvent entityUpdatedEvent)
                 {
                     Handle(entityUpdatedEvent);
                 }
             }
         }
     }
 }
        public void Handle(GroupedFieldChangeEvent message)
        {
            List <FieldChangeEvent> eventsToBroadcast = message.GroupedEvents.ToList();

            foreach (var evt in eventsToBroadcast)
            {
                if (evt.EntityType == typeof(T).Name)
                {
                    if (evt is EntityUpdatedEvent entityUpdatedEvent)
                    {
                        Handle(entityUpdatedEvent);
                    }
                }
                else
                {
                    foreach (var entity in EnumerateRegistrations(message.EntityID))
                    {
                        entity.HandleSubEntityEvent(evt);
                    }
                }
            }
        }
Beispiel #6
0
        public void Can_Delete_SubTransaction()
        {
            Account     Account     = TestBudget.Budget.Accounts[0];
            Transaction transaction = new Transaction();

            transaction.Amount = 100;
            transaction.MakeSplitTransaction();
            Account.Transactions.Add(transaction);

            var subTransaction = transaction.SubTransactions.Create();

            subTransaction.Amount = 50;

            var subTransaction2 = transaction.SubTransactions.Create();

            subTransaction2.Amount = 50;

            TestBudget.BudgetModel.SaveChanges();
            TestBudget.ClearEvents();

            subTransaction.Delete();

            TestBudget.BudgetModel.SaveChanges();

            Assert.That(TestBudget.TestEvents, Has.Count.EqualTo(1));
            Assert.That(TestBudget.TestEvents[0], Is.TypeOf <GroupedFieldChangeEvent>());

            GroupedFieldChangeEvent groupedFieldChangeEvent = (GroupedFieldChangeEvent)TestBudget.TestEvents[0];

            Assert.That(groupedFieldChangeEvent.GroupedEvents, Has.Count.EqualTo(1));
            Assert.That(groupedFieldChangeEvent.GroupedEvents[0].EntityType, Is.EqualTo(nameof(SubTransaction)));
            var change = groupedFieldChangeEvent.GroupedEvents[0].Changes[nameof(SubTransaction.IsDeleted)];

            Assert.That(change.NewValue, Is.True);

            Assert.That(transaction.SubTransactions, Has.No.Member(subTransaction));
        }