コード例 #1
0
        public void ReceiveBestelling_WithCompleteEvent_ShouldAddBevestigdeBestellingToDatabase()
        {
            // Arrange
            BevestigdeBestelling insertParam = null;

            var bestellingMock = new Mock <IBestellingDataMapper>();

            bestellingMock.Setup(repo => repo.Insert(It.IsAny <BevestigdeBestelling>())).Returns(insertParam)
            .Callback <BevestigdeBestelling>(entity =>
            {
                insertParam    = entity;
                insertParam.Id = 1;
            });
            var artikelMock = new Mock <IArtikelDataMapper>();

            artikelMock.Setup(dm => dm.GetById(It.IsAny <int>())).Returns(new ArtikelEntity()
            {
                AfbeeldingUrl = "test"
            });
            BevestigdeBestelling expected = new BevestigdeBestellingBuilder().SetDummy().Create();

            var eventmessage = new BestellingGeplaatstEvent(Mapper.Map <CommonModels.DsBestelService.Models.Bestelling>(expected), "");

            var listener = new EventListener(artikelMock.Object, null, bestellingMock.Object);

            // Act
            listener.ReceiveBestellingGeplaatstEvent(eventmessage);

            // Assert
            Assert.AreEqual(expected.BestelStatus, insertParam.BestelStatus);
        }
        public void ReceiveBestellingGeplaatstEvent_ShouldAddBestellingToDatabase()
        {
            // Arrange
            var bestelling = new CommonModels.DsBestelService.Models.Bestelling()
            {
                FactuurTotaalInclBtw = 700,
                BestelStatus         = CommonModels.DsBestelService.Models.BestelStatus.Geplaatst,
                Factuurnummer        = 3,
                Klantnummer          = 1,
                Besteldatum          = DateTime.Now.AddDays(-2)
            };

            var request = new BestellingGeplaatstEvent(bestelling, NameConstants.BestelServiceBestellingGeplaatstEvent);

            // Act
            _target.ReceiveBestellingGeplaatstEvent(request);

            // Assert
            var dbResult = _dbContext.Bestellingen.SingleOrDefault(b => b.Factuurnummer == 3);

            Assert.AreEqual(bestelling.FactuurTotaalInclBtw, dbResult.FactuurTotaalInclBtw);
            Assert.AreEqual(bestelling.BestelStatus.ToString(), dbResult.BestelStatus.ToString());
            Assert.AreEqual(bestelling.Factuurnummer, dbResult.Factuurnummer);
            Assert.AreEqual(bestelling.Klantnummer, dbResult.Klantnummer);
            Assert.AreEqual(bestelling.Besteldatum, dbResult.Besteldatum);
        }
コード例 #3
0
        public void ReceiveBestellingGeplaatstEvent(BestellingGeplaatstEvent message)
        {
            var bestelling = Mapper.Map <Bestelling>(message.Bestelling);

            _bestellingDataMapper.Insert(bestelling);

            _betalingVerwerkenService.HandleBestellingVerwerken(bestelling.Factuurnummer);
        }
コード例 #4
0
        public void ReceiveBestellingGeplaatstEvent(BestellingGeplaatstEvent message)
        {
            var bestelling = Mapper.Map <BevestigdeBestelling>(message.Bestelling);

            int index = 0;

            foreach (var bestelRegel in message.Bestelling.BestelRegels)
            {
                var artikel = _artikelDataMapper.GetById((int)bestelRegel.Artikelnummer);
                bestelling.BestelRegels[index].AfbeeldingUrl = artikel.AfbeeldingUrl;
                index++;
            }
            _bestellingDataMapper.Insert(bestelling);
        }
コード例 #5
0
        public void ReceiveBestellingGeplaatstEvent_ShouldHandleBestellingMessage()
        {
            // Arrange
            var bestellingGeplaatstEvent = new BestellingGeplaatstEvent(new Bestelling()
            {
                Factuurnummer = 1
            }, "");

            _bestellingDataMapperMock.Setup(b => b.Insert(It.IsAny <CommonModels.PcsBetalingService.Models.Bestelling>())).Returns(new CommonModels.PcsBetalingService.Models.Bestelling());
            _betalingVerwerkenServiceMock.Setup(b => b.HandleBestellingVerwerken(1));
            // Act

            _target.ReceiveBestellingGeplaatstEvent(bestellingGeplaatstEvent);

            // Assert
            _bestellingDataMapperMock.VerifyAll();
        }
        public void ReceiveBestellingGeplaatstEvent_ShouldAddBestellingToDatabaseAndRaiseEvent()
        {
            // Arrange
            var queueName = "TestQueue";
            var receiver  = _nijnContext.CreateMessageReceiver(queueName, new List <string> {
                NameConstants.BetaalServiceBetalingGeaccrediteerdEvent
            });

            receiver.DeclareQueue();

            var bestelling = new CommonModels.DsBestelService.Models.Bestelling()
            {
                FactuurTotaalInclBtw = 400,
                BestelStatus         = CommonModels.DsBestelService.Models.BestelStatus.Geplaatst,
                Factuurnummer        = 3,
                Klantnummer          = 1,
                Besteldatum          = DateTime.Now.AddDays(-2)
            };

            var request = new BestellingGeplaatstEvent(bestelling, NameConstants.BestelServiceBestellingGeplaatstEvent);

            // Act
            _target.ReceiveBestellingGeplaatstEvent(request);
            bestelling.Factuurnummer = 4;
            _target.ReceiveBestellingGeplaatstEvent(request);

            // Assert
            var queue            = _nijnContext.EventBus.Queues[queueName];
            var bestellingResult = JsonConvert.DeserializeObject <BestellingGeaccrediteerdEvent>(queue[0].Message);

            Assert.AreEqual(1, queue.MessageQueueLength);
            Assert.AreEqual(3, bestellingResult.Factuurnummer);

            var dbResult = _dbContext.Bestellingen.SingleOrDefault(b => b.Factuurnummer == 3);

            Assert.AreEqual(bestelling.FactuurTotaalInclBtw, dbResult.FactuurTotaalInclBtw);
            Assert.AreEqual(bestelling.BestelStatus.ToString(), dbResult.BestelStatus.ToString());
            Assert.AreEqual(3, dbResult.Factuurnummer);
            Assert.AreEqual(bestelling.Klantnummer, dbResult.Klantnummer);
            Assert.AreEqual(bestelling.Besteldatum, dbResult.Besteldatum);
        }
        public void HandlePlaatsBestelling_ShouldCalculateBestellingTotaal()
        {
            var artikel1 = new ArtikelBuilder()
                           .SetArtikelNummer(1)
                           .SetLeveranciercode("1-abc-xyz")
                           .SetNaam("Fietsband")
                           .SetPrijs(12.99m)
                           .Create();

            var artikel2 = new ArtikelBuilder()
                           .SetArtikelNummer(2)
                           .SetLeveranciercode("2-abc-xyz")
                           .SetNaam("Ventieldopje")
                           .SetPrijs(.99m)
                           .Create();

            _artikelDataMapperMock.Setup(a => a.GetById(1)).Returns(artikel1);
            _artikelDataMapperMock.Setup(a => a.GetById(2)).Returns(artikel2);

            Bestelling bestelling = null;

            _bestellingDataMapperMock.Setup(m => m.Insert(It.IsAny <Bestelling>()))
            .Callback <Bestelling>(b => { b.Id = 42; bestelling = b; })
            .Returns(bestelling);

            _bestellingDataMapperMock.Setup(m => m.Update(It.IsAny <Bestelling>()));

            BestellingGeplaatstEvent result = null;

            _eventPublisherMock.Setup(p => p.Publish(It.IsAny <DomainEvent>()))
            .Callback <DomainEvent>(b => result = (BestellingGeplaatstEvent)b);

            var bestellingCM = new BestellingCM
            {
                Klantnummer  = 1234,
                ContactInfo  = new ContactInfoCM(),
                Afleveradres = new AfleveradresCM(),
                BestelRegels = new List <BestelRegelCM>
                {
                    new BestelRegelCM {
                        Artikelnummer = 1, Aantal = 2
                    },
                    new BestelRegelCM {
                        Artikelnummer = 2, Aantal = 1
                    }
                }
            };

            var requestCommand = new PlaatsBestellingCommand(bestellingCM, NameConstants.BestelServicePlaatsBestellingCommandQueue);

            _target.HandlePlaatsBestelling(requestCommand);

            _bestellingDataMapperMock.VerifyAll();
            _artikelDataMapperMock.VerifyAll();
            _eventPublisherMock.VerifyAll();

            Assert.AreEqual(25.98m, result.Bestelling.BestelRegels[0].RegelTotaalExclBtw);
            Assert.AreEqual(31.44m, result.Bestelling.BestelRegels[0].RegelTotaalInclBtw);

            Assert.AreEqual(26.97m, result.Bestelling.FactuurTotaalExclBtw);
            Assert.AreEqual(32.64m, result.Bestelling.FactuurTotaalInclBtw);
        }