public void HandlePlaatsBestelling_ShouldCallInsertOnDataMapper() { var artikel = new ArtikelBuilder() .SetArtikelNummer(1) .SetLeveranciercode("1-abc-xyz") .SetNaam("Fietsband") .SetPrijs(12.99m) .Create(); var bestellingCM = new BestellingCM { Klantnummer = 1234, ContactInfo = new ContactInfoCM(), Afleveradres = new AfleveradresCM(), BestelRegels = new List <BestelRegelCM> { new BestelRegelCM { Artikelnummer = 1, Aantal = 2 }, } }; Bestelling bestelling = null; _artikelDataMapperMock.Setup(a => a.GetById(1)).Returns(artikel); _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>())) .Callback <Bestelling>(b => bestelling = b); _eventPublisherMock.Setup(p => p.Publish(It.IsAny <DomainEvent>())); var requestCommand = new PlaatsBestellingCommand(bestellingCM, NameConstants.BestelServicePlaatsBestellingCommandQueue); var result = _target.HandlePlaatsBestelling(requestCommand); _bestellingDataMapperMock.VerifyAll(); _artikelDataMapperMock.VerifyAll(); _eventPublisherMock.VerifyAll(); Assert.AreEqual(42, result); Assert.AreEqual(42, bestelling.Factuurnummer); Assert.AreEqual(DateTime.Now.Date, bestelling.Besteldatum.Date); Assert.AreEqual(BestelStatus.Geplaatst, bestelling.BestelStatus); }
public async Task HandleUpdateBestelStatus_ShouldLowerStockWhenBestelStatusVerzonden() { // Arrange var artikel = new ArtikelBuilder() .SetArtikelNummer(1) .SetLeveranciercode("1-abc-xyz") .SetNaam("Fietsband") .SetPrijs(12.99m) .Create(); var existing = new Bestelling { Klantnummer = 1234, BestelStatus = BestelStatus.WordtIngepakt, ContactInfo = new ContactInfo(), Afleveradres = new Afleveradres(), BestelRegels = new List <BestelRegel> { new BestelRegel { Artikelnummer = 1, Aantal = 2 }, } }; var bestelStatusCommand = new UpdateBestelStatusCommand(1, BestelStatus.Verzonden, NameConstants.BestelServiceUpdateBestelStatusCommandQueue); _bestellingDataMapperMock.Setup(m => m.GetByFactuurnummer(1)).Returns(existing); _bestellingDataMapperMock.Setup(m => m.Update(It.IsAny <Bestelling>())); _eventPublisherMock.Setup(publisher => publisher.Publish(It.IsAny <DomainEvent>())); var response = new ResponseCommandMessage(JsonConvert.SerializeObject(true), "type", "correlationId"); _commandSenderMock.Setup(sendr => sendr.SendCommandAsync(It.Is <RequestCommandMessage>(cm => cm.RoutingKey == NameConstants.MagazijnServiceCommandQueue && cm.Type == NameConstants.MagazijnServiceHaalVoorraadUitMagazijnCommand ))).ReturnsAsync(response); // Act await _target.HandleUpdateBestelStatus(bestelStatusCommand); // Assert _nijnContextMock.VerifyAll(); _bestellingDataMapperMock.VerifyAll(); _eventPublisherMock.VerifyAll(); _commandSenderMock.VerifyAll(); }
public void HandlePlaatsBestelling_ShouldPublishBestellingGeplaatstEvent() { var artikel = new ArtikelBuilder() .SetArtikelNummer(1) .SetLeveranciercode("1-abc-xyz") .SetNaam("Fietsband") .SetPrijs(12.99m) .Create(); var bestellingCM = new BestellingCM { Klantnummer = 1234, ContactInfo = new ContactInfoCM(), Afleveradres = new AfleveradresCM(), BestelRegels = new List <BestelRegelCM> { new BestelRegelCM { Artikelnummer = 1, Aantal = 2 }, } }; Bestelling bestelling = null; _artikelDataMapperMock.Setup(a => a.GetById(1)).Returns(artikel); _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>())); _eventPublisherMock.Setup(e => e.Publish(It.Is <BestellingGeplaatstEvent>(evt => evt.RoutingKey == NameConstants.BestelServiceBestellingGeplaatstEvent && evt.Bestelling == bestelling ))).Verifiable("Publish event should be called"); var requestCommand = new PlaatsBestellingCommand(bestellingCM, NameConstants.BestelServicePlaatsBestellingCommandQueue); _target.HandlePlaatsBestelling(requestCommand); _bestellingDataMapperMock.VerifyAll(); _artikelDataMapperMock.VerifyAll(); _eventPublisherMock.VerifyAll(); }
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); }