public async Task CreateBestelling_ShouldReturn500StatusCode_WhenUnknownExceptionOccured_InBestellingCommand() { // Arrange var klant = new KlantBuilder().SetDummy().SetId(10).SetEmail("*****@*****.**").Create(); var bestelling = new Bestelling { ContactInfo = new ContactInfo(), Afleveradres = new Afleveradres(), BestelRegels = new List <BestelRegel>() }; _jwtHelperMock.Setup(h => h.GetEmail(It.IsAny <HttpContext>())).Returns(klant.Email); _klantDataMapperMock.Setup(k => k.GetByEmail(klant.Email)).Returns(klant); _commandPublisherMock.Setup(repo => repo.Publish <long>(It.IsAny <PlaatsBestellingCommand>())) .ThrowsAsync(new Exception()); // Act var result = await _target.CreateBestelling(bestelling); // Assert _commandPublisherMock.VerifyAll(); var requestResult = result as StatusCodeResult; Assert.IsNotNull(requestResult); Assert.AreEqual(500, requestResult.StatusCode); }
public async Task CreateBestelling_ShouldSendAdres_WhenAdresIsFilled() { // Arrange var klant = new KlantBuilder().SetDummy().SetId(10).SetEmail("*****@*****.**").Create(); var bestelling = new Bestelling { ContactInfo = new ContactInfo(), Afleveradres = new Afleveradres(), BestelRegels = new List <BestelRegel>() }; _jwtHelperMock.Setup(h => h.GetEmail(It.IsAny <HttpContext>())).Returns(klant.Email); _klantDataMapperMock.Setup(k => k.GetByEmail(klant.Email)).Returns(klant); _commandPublisherMock.Setup(repo => repo.Publish <long>(It.IsAny <PlaatsBestellingCommand>())) .ReturnsAsync(1); // Act var result = await _target.CreateBestelling(bestelling); // Assert _commandPublisherMock.VerifyAll(); var createdResult = result as CreatedResult; Assert.IsNotNull(createdResult); Assert.AreEqual(201, createdResult.StatusCode); Assert.AreEqual((long)1, createdResult.Value); }
public void ReceiveAddKlant_WithCompleteEvent_ShouldAddKlantToDatabase() { // Arrange Klant insertParam = null; var mock = new Mock <IKlantDataMapper>(); mock.Setup(repo => repo.Insert(It.IsAny <Klant>())).Returns(insertParam) .Callback <Klant>(entity => { insertParam = entity; }); Klant expected = new KlantBuilder().SetDummy().Create(); var eventmessage = new KlantToegevoegdEvent(Mapper.Map <CommonModels.DsKlantBeheer.Models.Klant>(expected), ""); var listener = new EventListener(null, mock.Object, null); // Act listener.ReceiveKlantToegevoegdEvent(eventmessage); // Assert Assert.AreEqual(expected.Achternaam, insertParam.Achternaam); }
public async Task CreateBestelling_ShouldReturn400StatusCode_WhenBestellingIsInvalid() { // Arrange var klant = new KlantBuilder().SetDummy().SetId(10).SetEmail("*****@*****.**").Create(); var bestelling = new Bestelling { ContactInfo = new ContactInfo(), Afleveradres = new Afleveradres(), BestelRegels = new List <BestelRegel>() }; _jwtHelperMock.Setup(h => h.GetEmail(It.IsAny <HttpContext>())).Returns(klant.Email); _klantDataMapperMock.Setup(k => k.GetByEmail(klant.Email)).Returns(klant); _commandPublisherMock.Setup(repo => repo.Publish <long>(It.IsAny <PlaatsBestellingCommand>())) .ThrowsAsync(new DatabaseException("error")); // Act var result = await _target.CreateBestelling(bestelling); // Assert _commandPublisherMock.VerifyAll(); var badRequestResult = result as BadRequestObjectResult; Assert.IsNotNull(badRequestResult); Assert.AreEqual("Bestelling bevat incorrecte data", badRequestResult.Value); }
public async Task CreateBestelling_ShouldReturn201StatusCode() { // Arrange var klant = new KlantBuilder().SetDummy().SetId(10).SetEmail("*****@*****.**").Create(); var bestelling = new Bestelling() { ContactInfo = new ContactInfo(), Afleveradres = new Afleveradres(), BestelRegels = new List <BestelRegel>() }; _jwtHelperMock.Setup(h => h.GetEmail(It.IsAny <HttpContext>())).Returns(klant.Email); _klantDataMapperMock.Setup(k => k.GetByEmail(klant.Email)).Returns(klant); _commandPublisherMock.Setup(repo => repo.Publish <long>(It.Is <PlaatsBestellingCommand>(c => c.RoutingKey == NameConstants.BestelServicePlaatsBestellingCommandQueue && c.Bestelling.Klantnummer == klant.Id ))).ReturnsAsync(42); // Act var result = await _target.CreateBestelling(bestelling); // Assert _commandPublisherMock.VerifyAll(); _klantDataMapperMock.VerifyAll(); var createdResult = result as CreatedResult; Assert.IsNotNull(createdResult); Assert.AreEqual(201, createdResult.StatusCode); Assert.IsInstanceOfType(createdResult.Value, typeof(long)); Assert.AreEqual(42L, createdResult.Value); }
public RentAVillaRentingService() { PandBuilder = new PandBuilder(); //tested HuurPanden = new HuurPandCatalogus(); //tested ReservatieBoek = new ReservatieBoek(); //tested Promoties = new Promoties(); //tested PrijsOfferteBuilder = new PrijsOfferteBuilder(Promoties); //tested ReservatieBuilder = new ReservatieBuilder(PrijsOfferteBuilder); //tested KlantenBestand = new KlantenBestand(); //tested KlantCategorieën = new List <KlantCategorie>(); //tested AfroepContracten = new List <AfroepContract>(); //tested KlantBuilder = new KlantBuilder(KlantCategorieën); //tested }
public void Insert_ShouldInsertKlant() { // Arrange Klant klant = new KlantBuilder().SetDummy().Create(); var dataMapper = new KlantDataMapper(_context); // Act dataMapper.Insert(klant); Klant result = dataMapper.GetById(klant.Id); // Assert Assert.IsNotNull(result); Assert.IsTrue(klant.IsEqual(result)); }
public void InsertKlant_ShouldReturnNewKlant() { // Arrange Klant klant = new KlantBuilder().SetDummy().Create(); klant.Adres = new AdresBuilder().SetDummy().Create(); // Act _target.Insert(klant); var result = _context.KlantEntities.Include(x => x.Adres).ToList(); // Assert Assert.AreEqual(1, result[0].Id); Assert.AreEqual("Kees", result[0].Voornaam); Assert.AreEqual("de Koning", result[0].Achternaam); }
public void GetById_ShouldReturnKlant_When_ExistingIdIsGiven() { // Arrange Klant klant = new KlantBuilder().SetDummy().Create(); _context.Klanten.Add(klant); _context.SaveChanges(); var dataMapper = new KlantDataMapper(_context); // Act Klant result = dataMapper.GetById(klant.Id); // Assert Assert.IsNotNull(result); Assert.IsTrue(klant.IsEqual(result)); }
public void HandleVoegKlantToe_ShouldReturnExistingKlantId_WhenEmailExists() { // Arrange long klantId = 42; var klant = new KlantBuilder().SetDummy().SetId(klantId).SetEmail("*****@*****.**").Create(); var klanten = new List <Klant> { klant }; var command = new VoegKlantToeCommand(klant, ""); _klantDataMapperMock.Setup(k => k.Insert(It.IsAny <Klant>())).Throws(new DbUpdateException("", new Exception())); // Act Action result = () => _target.HandleVoegKlantToe(command); // Assert Assert.ThrowsException <EmailAllreadyExistsException>(result); }
public void Delete_ShouldThrowInvalidOperationException() { // Arrange var klant = new KlantBuilder().SetDummy().Create(); var dataMapper = new KlantDataMapper(_context); // Act void Act() { dataMapper.Delete(klant); } // Assert var exception = Assert.ThrowsException <InvalidOperationException>((Action)Act); Assert.AreEqual("Deleting klanten is not allowed", exception.Message); }
public void GetByEmail_ShouldReturnKlantOfProvidedEmail() { // Arrange var email = "*****@*****.**"; var klant = new KlantBuilder().SetDummy().SetId(42).SetEmail(email).Create(); klant.Adres = new AdresBuilder().SetDummy().Create(); _context.KlantEntities.Add(klant); _context.SaveChanges(); // Act var result = _target.GetByEmail(email); // Assert Assert.AreEqual(klant.Id, result.Id); }
public void Update_ShouldUpdateKlant() { // Arrange Klant klant = new KlantBuilder().SetDummy().Create(); var dataMapper = new KlantDataMapper(_context); klant = dataMapper.Insert(klant); klant.Achternaam = "Worst"; // Act dataMapper.Update(klant); Klant result = dataMapper.Find(x => x.Achternaam == "Worst").FirstOrDefault(); // Assert Assert.IsNotNull(result); Assert.IsTrue(result.IsEqual(klant)); Assert.AreEqual("Worst", klant.Achternaam); }
public void Find_ShouldReturnKlantMatchingACertainPredicate_When_PredicateIsGiven() { // Arrange Klant klant1 = new KlantBuilder().SetDummy().Create(); Klant klant2 = new KlantBuilder().SetDummy().SetEmail("*****@*****.**").Create(); _context.Klanten.Add(klant1); _context.Klanten.Add(klant2); _context.SaveChanges(); var dataMapper = new KlantDataMapper(_context); // Act List <Klant> result = dataMapper.Find(x => x.Email.Contains("worst")).ToList(); // Assert Assert.AreEqual(1, result.Count); Assert.IsTrue(klant2.IsEqual(result[0])); }
public void HandleVoegKlantToe_ShouldThrowException_When_IncorrectInput() { // Arrange var klant = new KlantBuilder().SetDummy().Create(); var command = new VoegKlantToeCommand(klant, ""); _klantDataMapperMock.Setup(repo => repo.Insert(It.IsAny <Klant>())).Throws <Exception>(); // Act Action act = () => { _target.HandleVoegKlantToe(command); }; // Assert var exception = Assert.ThrowsException <DatabaseException>(act); Assert.AreEqual("Something unexpected happend while inserting into the database", exception.Message); }
public void GetKlantById_ShouldReturnKlantWithSpecifiedId() { // Arrange Klant klant = new KlantBuilder().SetDummy().Create(); klant.Adres = new AdresBuilder().SetDummy().Create(); Klant klant2 = new KlantBuilder().SetDummy().Create(); klant2.Adres = new AdresBuilder().SetDummy().Create(); _context.KlantEntities.Add(klant); _context.KlantEntities.Add(klant2); _context.SaveChanges(); // Act var result = _target.GetById(1); // Assert Assert.AreEqual("de Koning", klant.Achternaam); }
public async Task CreateBestelling_WithBestelRegels_ShouldReturn201StatusCode() { // Arrange var klant = new KlantBuilder().SetDummy().SetId(10).SetEmail("*****@*****.**").Create(); var bestelling = new Bestelling() { ContactInfo = new ContactInfo(), Afleveradres = new Afleveradres(), BestelRegels = new List <BestelRegel>() { new BestelRegel() { Aantal = 1, Artikelnummer = 1254 } } }; _jwtHelperMock.Setup(h => h.GetEmail(It.IsAny <HttpContext>())).Returns(klant.Email); _klantDataMapperMock.Setup(k => k.GetByEmail(klant.Email)).Returns(klant); _commandPublisherMock.Setup(repo => repo.Publish <long>(It.Is <PlaatsBestellingCommand>(c => c.Bestelling.BestelRegels.Any(r => r.Aantal == 1 && r.Artikelnummer == 1254) ))).ReturnsAsync(10); // Act var result = await _target.CreateBestelling(bestelling); // Assert _commandPublisherMock.VerifyAll(); var createdResult = result as CreatedResult; Assert.IsNotNull(createdResult); Assert.AreEqual(201, createdResult.StatusCode); Assert.AreEqual((long)10, createdResult.Value); }
public void HandleVoegKlantToe_ShouldCallDataMapperInsert() { // Arrange Klant klant = new KlantBuilder().SetDummy().Create(); var command = new VoegKlantToeCommand(klant, ""); Klant insertParam = null; _klantDataMapperMock.Setup(repo => repo.Insert(It.IsAny <Klant>())).Returns(klant) .Callback <Klant>(entity => { insertParam = entity; }); _eventPublisherMock.Setup(p => p.Publish(It.IsAny <KlantToegevoegdEvent>())); // Act var result = _target.HandleVoegKlantToe(command); // Assert _klantDataMapperMock.VerifyAll(); Assert.IsNotNull(result); Assert.IsTrue(klant.IsEqual(klant)); }
public void GetAllKlanten_ShouldReturnKlanten() { // Arrange Klant klant = new KlantBuilder().SetDummy().Create(); klant.Adres = new AdresBuilder().SetDummy().Create(); Klant klant2 = new KlantBuilder().SetDummy().Create(); klant2.Adres = new AdresBuilder().SetDummy().Create(); _context.KlantEntities.Add(klant); _context.KlantEntities.Add(klant2); _context.SaveChanges(); // Act var result = _target.GetAll().ToList(); // Assert Assert.AreEqual(2, result.Count); Assert.AreEqual(1, result[0].Id); Assert.AreEqual(2, result[1].Id); }
public void BeforeEach() { _klantBuilder = new KlantBuilder(); _connection = new SqliteConnection("DataSource=:memory:"); _connection.Open(); var options = new DbContextOptionsBuilder <KlantContext>() .UseSqlite(_connection) .EnableSensitiveDataLogging() .Options; _dbContext = new KlantContext(options); _dbContext.Database.EnsureCreated(); SeedDatabase(); _nijnContext = new TestBusContextBuilder().CreateTestContext(); var klantDataMapper = new KlantDataMapper(_dbContext); var eventPublisher = new EventPublisher(_nijnContext); _target = new KlantController(klantDataMapper, eventPublisher, new LoggerFactory()); }