public async Task <BestellingAfkeurenResult> KeurBestellingAf(BestellingAfkeurenCommand bestellingAfkeurenCommand)
        {
            var bestellingToBeUpdated = await _datamapper.GetBestelling(bestellingAfkeurenCommand.Id);

            bestellingToBeUpdated.Klant.KredietOver     += bestellingToBeUpdated.GetTotaalPrijs;
            bestellingToBeUpdated.Klant.KredietMetSales -= bestellingToBeUpdated.GetTotaalPrijs;

            List <int> bestellingen = await RefreshKlantBestellingen(bestellingToBeUpdated.Klant);

            await _klantDatamapper.Update(bestellingToBeUpdated.Klant);

            bestellingToBeUpdated.BestellingStatus = BestellingStatus.Afgekeurd;
            await _datamapper.Update(bestellingToBeUpdated);

            _eventPublisher.Publish(new BestellingAfgekeurdEvent {
                Id = bestellingToBeUpdated.Id
            });
            _eventPublisher.Publish(new KlantKredietAangepastEvent()
            {
                KlantId = bestellingToBeUpdated.Klant.Id, NieuweKrediet = bestellingToBeUpdated.Klant.KredietOver
            });

            var bestellingAfkeuren = new BestellingAfkeurenResult()
            {
                Id                 = bestellingToBeUpdated.Id,
                IsSuccesfull       = true,
                PassedBestellingen = bestellingen
            };

            return(bestellingAfkeuren);
        }
예제 #2
0
        public async Task BestellingAfkeurenTest()
        {
            var bestellingAfkeurenResult = new BestellingAfkeurenResult()
            {
                Id                 = 1,
                IsSuccesfull       = true,
                PassedBestellingen = new List <int>()
                {
                    5, 8, 10
                }
            };

            var publisherMock = new Mock <ICommandPublisher>(MockBehavior.Strict);

            publisherMock.Setup(p => p.Publish <BestellingAfkeurenResult>(It.Is <BestellingAfkeurenCommand>(b => b.Id == 1),
                                                                          NameConstants.BestellingAfkeurenCommandQueue, ""))
            .ReturnsAsync(bestellingAfkeurenResult).Verifiable();

            var controller = new BestellingenController(publisherMock.Object, null);

            var result = await controller.BestellingAfkeuren(1) as OkObjectResult;

            List <int> resultList = result.Value as List <int>;

            Assert.IsNotNull(resultList);
            Assert.AreEqual(3, resultList.Count);
        }