Ejemplo n.º 1
0
        private static Period ChangeSpendingInfo(Amount amount = null, Label label = null, Pair pair = null, SpendingCategory category = null)
        {
            var period = Some.Period(p => p.WithEvent(new SpendingAdded(OperationId.From(1), Amount.From(10), Label.From("test"), Pair.First, SpendingCategory.Advance)));

            MakeChanges(period, amount, label, pair, category);
            return(period);
        }
Ejemplo n.º 2
0
        public void RaiseAmountChangedIfJustChangingAmount()
        {
            var period = ChangeSpendingInfo(amount: Amount.From(5));

            period.UncommittedEvents.GetStream().Should().HaveCount(2).And
            .ContainEquivalentOf(new AmountChanged(OperationId.From(1), Amount.From(5)),
                                 e => e.Excluding(a => a.AggregateId).Excluding(a => a.Sequence));
        }
Ejemplo n.º 3
0
 private static void MakeChanges(Period period, Amount amount = null, Label label = null, Pair pair = null, SpendingCategory category = null)
 {
     period.ChangeSpending(OperationId.From(1),
                           amount ?? Amount.From(10),
                           label ?? Label.From("test"),
                           pair ?? Pair.First,
                           category ?? SpendingCategory.Advance);
 }
Ejemplo n.º 4
0
        public void Raise_CategoryChanged_if_just_changing_category()
        {
            var period = ChangeSpendingInfo(category: SpendingCategory.Common);

            period.UncommittedEvents.GetStream().Should().HaveCount(2).And
            .ContainEquivalentOf(new SpendingCategoryChanged(OperationId.From(1), SpendingCategory.Common),
                                 e => e.Excluding(a => a.AggregateId).Excluding(a => a.Sequence));
        }
Ejemplo n.º 5
0
        public void RaisePairChangedIfJustChangingPair()
        {
            var period = ChangeSpendingInfo(pair: Pair.Second);

            period.UncommittedEvents.GetStream().Should().HaveCount(2).And
            .ContainEquivalentOf(new PairChanged(OperationId.From(1), Pair.Second),
                                 e => e.Excluding(a => a.AggregateId).Excluding(a => a.Sequence));
        }
Ejemplo n.º 6
0
        public void raise_label_changed_if_just_changing_label()
        {
            var period = ChangeSpendingInfo(label: Label.From("coucou"));

            period.UncommittedEvents.GetStream().Should().HaveCount(1).And
            .ContainEquivalentOf(new LabelChanged(OperationId.From(1), Label.From("coucou")),
                                 e => e.Excluding(a => a.AggregateId).Excluding(a => a.Sequence));
        }
Ejemplo n.º 7
0
        public OperationId AddRecipe(Amount amount, Label label, Pair pair, RecipeCategory category)
        {
            var operationId = OperationId.From(State.GetNextOperationId());

            RaiseEvent(new RecipeAdded(operationId, amount, label, pair, category));
            RaiseBalanceChanged();
            return(operationId);
        }
Ejemplo n.º 8
0
        public void dont_raise_spending_removed_when_remove_unexisting_spending()
        {
            var period = Some.Period(p =>
                                     p.WithEvent(new PeriodCreated(PeriodName.From(1, 2019)))
                                     .WithEvent(Some.SpendingAdded(OperationId.From(1))));

            period.RemoveOperation(OperationId.From(2));

            period.UncommittedEvents.GetStream().OfType <SpendingRemoved>().Should().BeEmpty();
        }
Ejemplo n.º 9
0
 public async Task Save_SpendingAdded_in_csv_file()
 {
     await Make.TestFile("SpendingAdded.es").AndExecute(async env =>
     {
         var store = new FileEventStoreWithCache(new CustomJsonSerializer(), env.FilePath);
         await store.Save(new SpendingAdded(OperationId.From(5), Amount.From(15.2), Label.From("this is a test"), Pair.First, SpendingCategory.Advance));
         var @event = await store.GetEvents(a => true);
         @event.Last().Should().BeOfType <SpendingAdded>().Which.OperationId.Should().Be(OperationId.From(5));
     });
 }
Ejemplo n.º 10
0
 public async Task <IActionResult> ChangeSpending([FromBody] UpdateSpending input)
 {
     return(await SendCommandAsync(new ChangeSpending(
                                       PeriodId.From(input.PeriodId),
                                       OperationId.From(input.OperationId),
                                       Amount.From(input.Amount),
                                       Label.From(input.Label),
                                       Pair.From(input.Pair),
                                       SpendingCategory.From(input.Category))));
 }
Ejemplo n.º 11
0
        public void RaiseRecipeAddedWhenAddingRecipe()
        {
            var period = Some.Period();

            period.AddRecipe(Amount.From(100), Label.From("test"), Pair.First, RecipeCategory.Common);

            period.UncommittedEvents.GetStream().Should().HaveCount(3).And
            .ContainEquivalentOf(new RecipeAdded(OperationId.From(1), Amount.From(100), Label.From("test"), Pair.First, RecipeCategory.Common),
                                 e => e.Excluding(a => a.AggregateId).Excluding(a => a.Sequence));
        }
Ejemplo n.º 12
0
        public void raise_spending_added_when_add_spending()
        {
            var period = Some.Period();

            period.AddSpending(Amount.From(10), Label.From("Test spending"), Pair.First, SpendingCategory.Common);

            period.UncommittedEvents.GetStream().Should()
            .ContainEquivalentOf(
                new SpendingAdded(OperationId.From(1), Amount.From(10), Label.From("Test spending"), Pair.First, SpendingCategory.Common),
                e => e.Excluding(a => a.AggregateId).Excluding(a => a.Sequence));
        }
Ejemplo n.º 13
0
        public void RaiseRecipeRemovedWhenRemoveExistingRecipe()
        {
            var period = Some.Period(p =>
                                     p.WithEvent(new PeriodCreated(PeriodName.From(1, 2019)))
                                     .WithEvent(Some.RecipeAdded(OperationId.From(1))));

            period.RemoveOperation(OperationId.From(1));

            period.UncommittedEvents.GetStream().Should().HaveCount(2).And
            .ContainEquivalentOf(new RecipeRemoved(OperationId.From(1)),
                                 e => e.Excluding(a => a.AggregateId).Excluding(a => a.Sequence));
        }
Ejemplo n.º 14
0
        public void raise_spending_removed_when_remove_existing_spending()
        {
            var period = Some.Period(p =>
                                     p.WithEvent(new PeriodCreated(PeriodName.From(1, 2019)))
                                     .WithEvent(Some.SpendingAdded(OperationId.From(1))));

            period.RemoveOperation(OperationId.From(1));

            period.UncommittedEvents.GetStream().Should()
            .ContainEquivalentOf(new SpendingRemoved(OperationId.From(1)),
                                 e => e.Excluding(a => a.AggregateId).Excluding(a => a.Sequence));
        }
Ejemplo n.º 15
0
        public void Generate_operationId_based_on_previous_events()
        {
            var period = Some.Period(p =>
                                     p.WithEvent(Some.SpendingAdded(OperationId.From(1)))
                                     .WithEvent(Some.SpendingAdded(OperationId.From(2)))
                                     .WithEvent(Some.SpendingAdded(OperationId.From(3)))
                                     .WithEvent(Some.SpendingAdded(OperationId.From(4))));

            period.AddSpending(Amount.From(10), Label.From("test"), Pair.First, SpendingCategory.Advance);

            period.UncommittedEvents.GetStream().Should()
            .ContainEquivalentOf(new SpendingAdded(OperationId.From(5), Amount.From(10), Label.From("test"), Pair.First, SpendingCategory.Advance),
                                 e => e.Excluding(a => a.AggregateId).Excluding(a => a.Sequence));
        }
Ejemplo n.º 16
0
 public async Task <IActionResult> Remove([FromBody] OperationToRemove input)
 {
     return(await SendCommandAsync(new RemoveOperation(PeriodId.From(input.PeriodId), OperationId.From(input.OperationId))));
 }
Ejemplo n.º 17
0
        public void SerializeOperationId()
        {
            var data = _serializer.Serialize(OperationId.From(5));

            data.Should().Be("{\"$type\":\"OperationId\",\"Value\":5}");
        }