Ejemplo n.º 1
0
        public async void AddPurchaseTest()
        {
            var command = new CreatePurchaseCommand()
            {
                Group        = 1,
                Currency     = "Usd",
                Participants = new [] { 1, 2 },
                Purchaser    = 1,
                Cost         = 15
            };
            var handler = new CreateAddPurchaseCommandHandler(Context);

            PurchaseModel result = await handler.Handle(command, CancellationToken.None);

            Group @group = await Groups.FindAsync(1);

            User jon = await Users.FindAsync(1);

            User danny = await Users.FindAsync(2);

            User ghost = await Users.FindAsync(3);

            Assert.Equal(command.Currency, result.Currency);
            Assert.Equal(command.Group, result.Group);
            Assert.Equal(command.Participants.ToList(), result.Participants.Select(p => p.Id));
            Assert.Equal(command.Cost, result.Cost);
            Assert.Equal(command.Purchaser, result.Purchaser);

            Assert.Single(group.Purchases);
            Purchase purchase = group.Purchases.Single();

            Assert.Equal(jon, purchase.Purchaser);
            Assert.Collection(purchase.Participants, p => p.User.Equals(danny), p => p.User.Equals(ghost));
        }
Ejemplo n.º 2
0
        public async void AddPurchaseWithNonExistentCurrencyTest()
        {
            var command = new CreatePurchaseCommand()
            {
                Group        = 1,
                Currency     = "Peso venezolano",
                Participants = new [] { 1, 2 },
                Purchaser    = 1,
                Cost         = 15
            };
            var handler = new CreateAddPurchaseCommandHandler(Context);

            Assert.ThrowsAny <Exception>(() => handler.Handle(command, CancellationToken.None).Result);
        }