示例#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));
        }
示例#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);
        }
示例#3
0
        public async void CreatePurchase()
        {
            var command = new CreatePurchaseCommand()
            {
                Name         = "Compra en pesos",
                Cost         = 100,
                Currency     = "Ars",
                Group        = 1,
                Participants = new[] { 1 },
                Purchaser    = 2
            };

            HttpResponseMessage response = await _client.PostObjectAsync(PurchasesUrl, command);

            response.EnsureSuccessStatusCode();
            PurchaseModel purchase = await response.DeserializeObject <PurchaseModel>();

            Assert.Equal(2, purchase.Id);
            Assert.Equal(2, purchase.Purchaser);
            Assert.Equal(1, purchase.Group);
        }
示例#4
0
        public async void AddPurchase()
        {
            var command = new CreatePurchaseCommand()
            {
                Name         = "Compra en dolares",
                Group        = 1,
                Currency     = "Usd",
                Participants = new[] { 1, 2 },
                Purchaser    = 1,
                Cost         = 15
            };

            HttpResponseMessage response = await _client.PostObjectAsync($"{GroupUrl}/1/purchases", command);

            response.EnsureSuccessStatusCode();
            PurchaseModel purchase = await response.DeserializeObject <PurchaseModel>();

            Assert.Equal(command.Currency, purchase.Currency);
            Assert.Equal(command.Group, purchase.Group);
            Assert.Equal(command.Participants.ToList(), purchase.Participants.Select(p => p.Id));
            Assert.Equal(command.Cost, purchase.Cost);
            Assert.Equal(command.Purchaser, purchase.Purchaser);
        }
        public async Task <ActionResult <IEnumerable <PurchaseModel> > > CreatePurchase([FromBody] CreatePurchaseCommand command)
        {
            PurchaseModel purchase = await Mediator.Send(command);

            return(Ok(purchase));
        }