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); }
private void SeedDatabase() { var date = new DateTime(2018, 11, 10, 10, 42, 00); var bestellingen = new List <BevestigdeBestelling> { _bestellingBuilder.SetDummy() .SetFactuurnummer(1) .SetBestelStatus(BestelStatus.Geplaatst) .Create(), _bestellingBuilder.SetDummy() .SetFactuurnummer(2) .SetBestelStatus(BestelStatus.Goedgekeurd) .SetBesteldatum(date) .Create(), _bestellingBuilder.SetDummy() .SetFactuurnummer(3) .SetBestelStatus(BestelStatus.Goedgekeurd) .SetBesteldatum(date.AddMinutes(1)) .Create(), _bestellingBuilder.SetDummy() .SetFactuurnummer(4) .SetBestelStatus(BestelStatus.Goedgekeurd) .SetBesteldatum(date.AddDays(10)) .Create(), }; _dbContext.AddRange(bestellingen); _dbContext.SaveChanges(); }
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 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 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); }