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 async Task GetNextBestelling_ShouldReturnStatusCode408_WhenUpdateBestelStatusCommandTimedOut() { // Arrange BevestigdeBestellingBuilder builder = new BevestigdeBestellingBuilder(); var bestelling = builder.SetDummy().SetBestelStatus(BestelStatus.Geplaatst).Create(); _jwtHelperMock.Setup(j => j.GetEmail(It.IsAny <HttpContext>())).Returns("email"); _magazijnSessionDataMapperMock.Setup(m => m.Find(It.IsAny <Expression <Func <MagazijnSessionEntity, bool> > >())) .Returns(new List <MagazijnSessionEntity>()); _bestellingDataMapperMock.Setup(mapper => mapper.Find(It.IsAny <Expression <Func <BevestigdeBestelling, bool> > >())) .Returns(new List <BevestigdeBestelling>() { bestelling }); _commandPublisherMock.Setup(publisher => publisher.Publish <long>(It.IsAny <UpdateBestelStatusCommand>())) .ThrowsAsync(new TimeoutException()); // Act ActionResult <BevestigdeBestelling> result = await _target.GetNextBestelling(); // Assert _bestellingDataMapperMock.VerifyAll(); Assert.IsNotNull(result); var res = (ObjectResult)result.Result; Assert.AreEqual(408, res.StatusCode); }
public void GetBestelling_WithoutBestellingen_ShouldReturnListOfBestellingenWithProvidedStatus() { // Arrange BevestigdeBestellingBuilder builder = new BevestigdeBestellingBuilder(); var bestellingen = new List <BevestigdeBestelling> { builder.SetDummy().SetBestelStatus(BestelStatus.Goedgekeurd).Create(), builder.SetDummy().SetBestelStatus(BestelStatus.Geplaatst).Create(), builder.SetDummy().SetBestelStatus(BestelStatus.Afgekeurd).Create(), builder.SetDummy().SetBestelStatus(BestelStatus.Goedgekeurd).Create(), }; _bestellingDataMapperMock.Setup(mapper => mapper.Find(It.IsAny <Expression <Func <BevestigdeBestelling, bool> > >())) .Returns <Expression <Func <BevestigdeBestelling, bool> > >(expr => { var query = expr.Compile(); return(bestellingen.Where(query)); }); // Act var result = _target.GetBestellingen("Goedgekeurd").Value.ToList(); // Assert _bestellingDataMapperMock.VerifyAll(); Assert.AreEqual(2, result.Count); }
public void BeforeEach() { _bestellingBuilder = new BevestigdeBestellingBuilder(); _connection = new SqliteConnection("DataSource=:memory:"); _connection.Open(); var options = new DbContextOptionsBuilder <BffContext>() .UseSqlite(_connection) .Options; _dbContext = new BffContext(options); _dbContext.Database.EnsureCreated(); var bestellingDataMapper = new BestellingDataMapper(_dbContext); var klantDataMapper = new KlantDataMapper(_dbContext); var magazijnSessionDataMapper = new MagazijnSessionDataMapper(_dbContext); _jwtHelperMock = new Mock <IJwtHelper>(MockBehavior.Strict); _nijnContext = new TestBusContextBuilder().CreateTestContext(); _target = new BestellingController( new CommandPublisher(_nijnContext), bestellingDataMapper, klantDataMapper, magazijnSessionDataMapper, _jwtHelperMock.Object, new LoggerFactory() ); SeedDatabase(); }
public void Insert_Should_InsertArtikel_When_NieuwArtikel_IsGiven() { // Arrange BevestigdeBestelling bevestigdeBestelling = new BevestigdeBestellingBuilder().SetDummy().Create(); // Act _target.Insert(bevestigdeBestelling); BevestigdeBestelling result = _target.GetByFactuurnummer(bevestigdeBestelling.Factuurnummer); // Assert Assert.IsNotNull(result); Assert.IsTrue(bevestigdeBestelling.IsEqual(result)); }
public void GetByFactuurnummer_Should_ReturnBevestigdeBestellingWithCertainId_When_Factuurnummer_IsGiven() { // Arrange BevestigdeBestelling bevestigdeBestelling = new BevestigdeBestellingBuilder().SetDummy().Create(); _context.BevestigdeBestellingen.Add(bevestigdeBestelling); _context.SaveChanges(); // Act BevestigdeBestelling result = _target.GetByFactuurnummer(bevestigdeBestelling.Factuurnummer); // Assert Assert.IsNotNull(result); Assert.IsTrue(bevestigdeBestelling.IsEqual(result)); }
public void Delete_Should_Throw_InvalidOperationException() { // Arrange BevestigdeBestelling bevestigdeBestelling = new BevestigdeBestellingBuilder().SetDummy().Create(); // Act void Act() { _target.Delete(bevestigdeBestelling); } // Assert var exception = Assert.ThrowsException <InvalidOperationException>((Action)Act); Assert.AreEqual("Deleting a bestelling is not allowed.", exception.Message); }
public void GetAll_ShouldReturnAllArtikelen() { // Arrange BevestigdeBestelling bevestigdeBestelling1 = new BevestigdeBestellingBuilder().SetDummy().Create(); BevestigdeBestelling bevestigdeBestelling2 = new BevestigdeBestellingBuilder().SetDummy().Create(); _context.BevestigdeBestellingen.Add(bevestigdeBestelling1); _context.BevestigdeBestellingen.Add(bevestigdeBestelling2); _context.SaveChanges(); // Act List <BevestigdeBestelling> result = _target.GetAll().OrderBy(r => r.Besteldatum).ToList(); // Assert Assert.AreEqual(2, result.Count); Assert.IsTrue(bevestigdeBestelling1.IsEqual(result[0])); Assert.IsTrue(bevestigdeBestelling2.IsEqual(result[1])); }
public void Update_ShouldUpdateBevestigdeBestelling_When_AnUpdatedBevestigdeBestelling_IsGiven() { // Arrange BevestigdeBestelling bevestigdeBestelling = new BevestigdeBestellingBuilder().SetDummy().Create(); BevestigdeBestelling bevestigdeBestellingUpdate = bevestigdeBestelling; bevestigdeBestellingUpdate.BestelStatus = BestelStatus.Goedgekeurd; _target.Insert(bevestigdeBestelling); // Act _target.Update(bevestigdeBestellingUpdate); BevestigdeBestelling result = _target.GetByFactuurnummer(bevestigdeBestellingUpdate.Factuurnummer); // Assert Assert.IsNotNull(result); Assert.IsTrue(result.IsEqual(bevestigdeBestellingUpdate)); }
public async Task GetNextBestelling_ShouldCallBestellingDataMapperWithExpression() { // Arrange BevestigdeBestellingBuilder builder = new BevestigdeBestellingBuilder(); var bestellingen = new List <BevestigdeBestelling> { builder.SetDummy() .SetFactuurnummer(1) .SetBesteldatum(new DateTime(2018, 11, 10)) .Create(), builder.SetDummy() .SetFactuurnummer(2) .SetBesteldatum(new DateTime(2018, 11, 11)) .Create(), }; _jwtHelperMock.Setup(j => j.GetEmail(It.IsAny <HttpContext>())).Returns("email"); _magazijnSessionDataMapperMock.Setup(m => m.Find(It.IsAny <Expression <Func <MagazijnSessionEntity, bool> > >())) .Returns(new List <MagazijnSessionEntity>()); _magazijnSessionDataMapperMock.Setup(m => m.Insert(It.Is <MagazijnSessionEntity>(e => e.MedewerkerEmail == "email" && e.Factuurnummer == 1 ))).Returns(new MagazijnSessionEntity()); _bestellingDataMapperMock.Setup(d => d.Find(It.IsAny <Expression <Func <BevestigdeBestelling, bool> > >())) .Returns(bestellingen); _commandPublisherMock.Setup(publisher => publisher.Publish <long>(It.IsAny <UpdateBestelStatusCommand>())) .ReturnsAsync(1); // Act var result = await _target.GetNextBestelling(); // Assert _jwtHelperMock.VerifyAll(); _magazijnSessionDataMapperMock.VerifyAll(); _bestellingDataMapperMock.VerifyAll(); _commandPublisherMock.VerifyAll(); Assert.IsNotNull(result); Assert.AreEqual(bestellingen.First(), result.Value); }
public void Find_Should_ReturnArtikelWithCertainPredicate_When_Predicate_IsGiven() { // Arrange BevestigdeBestelling bevestigdeBestelling1 = new BevestigdeBestellingBuilder().SetDummy().Create(); BevestigdeBestelling bevestigdeBestelling2 = new BevestigdeBestellingBuilder().SetDummy() .SetBestelStatus(BestelStatus.Goedgekeurd).Create(); _context.BevestigdeBestellingen.Add(bevestigdeBestelling1); _context.BevestigdeBestellingen.Add(bevestigdeBestelling2); _context.SaveChanges(); // Act List <BevestigdeBestelling> result = _target.Find(b => b.BestelStatus == BestelStatus.Goedgekeurd) .ToList(); // Assert Assert.AreEqual(1, result.Count); Assert.IsTrue(bevestigdeBestelling2.IsEqual(result[0])); }
public void ReceiveUpdateBestelling_WithCompleteBestelling_ShouldUpdateBestelling() { // Arrange long bestellingId = 10; BevestigdeBestelling bestelling = new BevestigdeBestellingBuilder() .SetDummy() .SetId(bestellingId) .SetBestelRegels(new List <BevestigdeBestelRegel> { new BevestigdeBestelRegel { PrijsExclBtw = 10m, PrijsInclBtw = 10.10m } }) .SetFactuurTotaalExclBtw(42m) .SetFactuurTotaalInclBtw(42.42m) .Create(); var mock = new Mock <IBestellingDataMapper>(); var artikelMock = new Mock <IArtikelDataMapper>(); BevestigdeBestelling result = null; mock.Setup(repo => repo.GetById(bestellingId)).Returns(bestelling); mock.Setup(repo => repo.Update(It.IsAny <BevestigdeBestelling>())) .Callback <BevestigdeBestelling>(b => result = b); var updatedBestelling = new DsBestelServiceBestelling { Id = bestellingId, BestelStatus = DsBestelServiceBestelStatus.Goedgekeurd }; var eventmessage = new BestelStatusBijgewerktEvent(updatedBestelling, ""); var listener = new EventListener(artikelMock.Object, null, mock.Object); // Act listener.ReceiveBestelStatusBijgewerktEvent(eventmessage); // Assert mock.VerifyAll(); Assert.AreEqual(bestelling, result); }
public async Task GetNextBestelling_ShouldReturnExistingBestelling_WhenSessionExists() { // Arrange BevestigdeBestellingBuilder builder = new BevestigdeBestellingBuilder(); var bestellingen = new List <BevestigdeBestelling> { builder.SetDummy() .SetFactuurnummer(1) .SetBesteldatum(new DateTime(2018, 11, 10)) .Create(), builder.SetDummy() .SetFactuurnummer(2) .SetBesteldatum(new DateTime(2018, 11, 11)) .Create(), }; var session = new MagazijnSessionEntity { MedewerkerEmail = "email", Factuurnummer = 1 }; _jwtHelperMock.Setup(j => j.GetEmail(It.IsAny <HttpContext>())).Returns("email"); _magazijnSessionDataMapperMock.Setup(m => m.Find(It.IsAny <Expression <Func <MagazijnSessionEntity, bool> > >())) .Returns(new List <MagazijnSessionEntity> { session }); _bestellingDataMapperMock.Setup(d => d.GetByFactuurnummer(session.Factuurnummer)) .Returns(bestellingen[0]); // Act var result = await _target.GetNextBestelling(); // Assert _jwtHelperMock.VerifyAll(); _magazijnSessionDataMapperMock.VerifyAll(); _bestellingDataMapperMock.VerifyAll(); _commandPublisherMock.Verify(publisher => publisher.Publish <long>(It.IsAny <UpdateBestelStatusCommand>()), Times.Never()); Assert.IsNotNull(result); Assert.AreEqual(bestellingen[0], result.Value); }
public void GetBestelling_ShouldReturnBestellingen() { // Arrange BevestigdeBestellingBuilder builder = new BevestigdeBestellingBuilder(); var bestellingen = new List <BevestigdeBestelling> { builder.SetDummy().Create(), builder.SetDummy().SetId(2).Create() }; _bestellingDataMapperMock.Setup(mapper => mapper.GetAll()).Returns(bestellingen); // Act var result = _target.GetBestellingen().Value.ToList(); // Assert _bestellingDataMapperMock.VerifyAll(); Assert.AreEqual(2, result.Count); Assert.AreEqual(2, result[1].Id); }
public void Insert_ShouldNotInsertArtikelInDatabase_When_AnExistingFactuurnummer_IsGiven() { // Arrange BevestigdeBestelling bevestigdeBestelling1 = new BevestigdeBestellingBuilder().SetDummy() .SetFactuurnummer(1) .Create(); BevestigdeBestelling bevestigdeBestelling2 = new BevestigdeBestellingBuilder().SetDummy() .SetFactuurnummer(1) .Create(); // Act _target.Insert(bevestigdeBestelling1); void Act() { _target.Insert(bevestigdeBestelling2); } // Assert Assert.ThrowsException <InvalidOperationException>((Action)Act); }