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 ThenVerwerkEenBestellingInHetSysteemMetHetKlantnummerBesteldatumEnBestelregels()
        {
            var bestellingDataMapper = new BestellingDataMapper(_context);
            var artikelDataMapper    = new ArtikelDataMapper(_context);
            var eventPublisherMock   = new Mock <IEventPublisher>(MockBehavior.Strict);
            var commandSenderMock    = new Mock <ICommandSender>(MockBehavior.Strict);

            var response = new ResponseCommandMessage(JsonConvert.SerializeObject(true), "type", "correlationId");

            eventPublisherMock.Setup(p => p.Publish(It.IsAny <DomainEvent>()));
            commandSenderMock.Setup(sendr => sendr.SendCommandAsync(It.IsAny <RequestCommandMessage>())).ReturnsAsync(response);

            var controller = new BestellingController(bestellingDataMapper, artikelDataMapper, eventPublisherMock.Object, new LoggerFactory());

            var bestelling = new BestellingCM
            {
                Klantnummer  = _klantnummer,
                BestelRegels = new List <BestelRegelCM>()
            };

            foreach (var regel in _bestelregels)
            {
                bestelling.BestelRegels.Add(new BestelRegelCM()
                {
                    Artikelnummer = regel.Item1,
                    Aantal        = regel.Item5
                });
            }

            var result = controller.HandlePlaatsBestelling(new PlaatsBestellingCommand(bestelling, ""));

            eventPublisherMock.VerifyAll();
            Assert.AreEqual(1, result);
        }
Exemplo n.º 3
0
        public void BeforeEach()
        {
            _connection = new SqliteConnection("DataSource=:memory:");
            _connection.Open();

            _options = new DbContextOptionsBuilder <BestelContext>()
                       .UseSqlite(_connection)
                       .EnableSensitiveDataLogging()
                       .Options;

            _nijnHost = new TestBusContextBuilder().CreateTestContext();

            _context = new BestelContext(_options);
            _context.Database.EnsureCreated();
            SeedDatabase();

            var bestellingDataMapper = new BestellingDataMapper(_context);
            var artikelDataMapper    = new ArtikelDataMapper(_context);
            var eventPublisher       = new EventPublisher(_nijnHost);

            _target = new BestellingController(
                bestellingDataMapper: bestellingDataMapper,
                artikelDataMapper: artikelDataMapper,
                eventPublisher: eventPublisher,
                loggerFactory: new LoggerFactory()
                );
        }
        public void BeforeEach()
        {
            _bestellingBuilder = new BestellingBuilder();

            _connection = new SqliteConnection("DataSource=:memory:");
            _connection.Open();

            var options = new DbContextOptionsBuilder <BetaalContext>()
                          .UseSqlite(_connection)
                          .EnableSensitiveDataLogging()
                          .Options;

            _nijnContext = new TestBusContextBuilder().CreateTestContext();

            _dbContext = new BetaalContext(options);
            _dbContext.Database.EnsureCreated();
            SeedDatabase();
            var bestellingDataMapper = new BestellingDataMapper(_dbContext);
            var betalingDataMapper   = new BetalingDataMapper(_dbContext);
            var eventPublisher       = new EventPublisher(_nijnContext);

            var betalingVerwerkenService = new BetalingVerwerkenService(betalingDataMapper, bestellingDataMapper, eventPublisher, new LoggerFactory());


            _target = new EventListener(bestellingDataMapper, betalingVerwerkenService);

            _dbContext.Database.EnsureCreated();
        }
        public void ThenGenereerEenFactuurnummer()
        {
            var dataMapper = new BestellingDataMapper(_context);
            var result     = dataMapper.GetById(1);

            Assert.AreEqual(1, result.Factuurnummer);
            Assert.AreEqual(2, result.BestelRegels.Count);
            Assert.AreEqual(_klantnummer, result.Klantnummer);
            Assert.AreEqual(DateTime.Now.Date, result.Besteldatum.Date);
        }
Exemplo n.º 6
0
        public void Initialize()
        {
            _connection = new SqliteConnection("DataSource=:memory:");
            _connection.Open();

            _options = new DbContextOptionsBuilder <BffContext>()
                       .UseSqlite(_connection)
                       .Options;

            _context = new BffContext(_options);
            _target  = new BestellingDataMapper(_context);

            _context.Database.EnsureCreated();
        }
Exemplo n.º 7
0
        public void BeforeEach()
        {
            _connection = new SqliteConnection("DataSource=:memory:");
            _connection.Open();

            _options = new DbContextOptionsBuilder <BetaalContext>()
                       .UseSqlite(_connection)
                       .Options;

            _betaalContext = new BetaalContext(_options);
            _betaalContext.Database.EnsureCreated();

            _bestellingBuilder = new BestellingBuilder();
            _target            = new BestellingDataMapper(_betaalContext);
        }
        public void Insert_Should_InsertArtikel_When_NieuwArtikel_IsGiven()
        {
            // Arrange
            Bestelling bestelling = new BestellingBuilder().SetDummy().Create();

            var dataMapper = new BestellingDataMapper(_context);

            // Act
            dataMapper.Insert(bestelling);

            Bestelling result = dataMapper.GetByFactuurnummer(bestelling.Factuurnummer);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(bestelling.IsEqual(result));
        }
Exemplo n.º 9
0
        public void GetByFactuurnummer_Should_ReturnBestellingWithCertainId_When_Factuurnummer_IsGiven()
        {
            // Arrange
            Bestelling bestelling = new BestellingBuilder().SetDummy().Create();

            _betaalContext.Bestellingen.Add(bestelling);
            _betaalContext.SaveChanges();

            var dataMapper = new BestellingDataMapper(_betaalContext);

            // Act
            Bestelling result = dataMapper.GetByFactuurnummer(bestelling.Factuurnummer);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(bestelling.Factuurnummer, result.Factuurnummer);
        }
        public void GetById_Should_ReturnBestellingWithCertainId_When_Id_IsGiven()
        {
            // Arrange
            Bestelling bestelling = new BestellingBuilder().SetDummy().Create();

            _context.Bestellingen.Add(bestelling);
            _context.SaveChanges();

            var dataMapper = new BestellingDataMapper(_context);

            // Act
            Bestelling result = dataMapper.GetById(bestelling.Id);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(bestelling.IsEqual(result));
        }
        public void Delete_Should_Throw_InvalidOperationException()
        {
            // Arrange
            Bestelling bestelling = new BestellingBuilder().SetDummy().Create();

            var dataMapper = new BestellingDataMapper(_context);

            // Act
            void Act()
            {
                dataMapper.Delete(bestelling);
            }

            // Assert
            var exception = Assert.ThrowsException <InvalidOperationException>((Action)Act);

            Assert.AreEqual("Deleting bestelling is not allowed", exception.Message);
        }
Exemplo n.º 12
0
        public void Find_Should_ReturnArtikelWithCertainPredicate_When_Predicate_IsGiven()
        {
            // Arrange
            Bestelling bestelling1 = new BestellingBuilder().SetDummy().Create();
            Bestelling bestelling2 = new BestellingBuilder().SetDummy().SetBestelStatus(BestelStatus.Goedgekeurd).Create();

            _betaalContext.Bestellingen.Add(bestelling1);
            _betaalContext.Bestellingen.Add(bestelling2);
            _betaalContext.SaveChanges();

            var dataMapper = new BestellingDataMapper(_betaalContext);

            // Act
            List <Bestelling> result = dataMapper.Find(b => b.BestelStatus == BestelStatus.Goedgekeurd).ToList();

            // Assert
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(bestelling2.Factuurnummer, result[0].Factuurnummer);
        }
        public void Insert_ShouldNotInsertArtikelInDatabase_When_NoKlantNummer_IsGiven()
        {
            // Arrange
            Bestelling bestelling = new BestellingBuilder()
                                    .SetBesteldatum(DateTime.Now)
                                    .SetBestelStatus(BestelStatus.Geplaatst)
                                    .SetFactuurnummer(1)
                                    .Create();

            var dataMapper = new BestellingDataMapper(_context);

            // Act
            void Act()
            {
                dataMapper.Insert(bestelling);
            }

            // Assert
            Assert.ThrowsException <ArgumentNullException>((Action)Act);
        }
        public void Update_ShouldUpdateBestelling_When_AnUpdatedBestelling_IsGiven()
        {
            // Arrange
            Bestelling bestelling       = new BestellingBuilder().SetDummy().Create();
            Bestelling bestellingUpdate = bestelling;

            bestellingUpdate.BestelStatus = BestelStatus.Goedgekeurd;

            var dataMapper = new BestellingDataMapper(_context);

            dataMapper.Insert(bestelling);

            // Act
            dataMapper.Update(bestellingUpdate);
            Bestelling result = dataMapper.GetByFactuurnummer(bestellingUpdate.Factuurnummer);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.IsEqual(bestellingUpdate));
        }
        public void GetAll_ShouldReturnAllArtikelen()
        {
            // Arrange
            Bestelling bestelling1 = new BestellingBuilder().SetDummy().Create();
            Bestelling bestelling2 = new BestellingBuilder().SetDummy().Create();

            _context.Bestellingen.Add(bestelling1);
            _context.Bestellingen.Add(bestelling2);
            _context.SaveChanges();

            var dataMapper = new BestellingDataMapper(_context);

            // Act
            List <Bestelling> result = dataMapper.GetAll().ToList();

            // Assert
            Assert.AreEqual(2, result.Count);
            Assert.IsTrue(bestelling1.IsEqual(result[0]));
            Assert.IsTrue(bestelling2.IsEqual(result[1]));
        }
Exemplo n.º 16
0
        public void GetAll_ShouldReturnAllBestellingen()
        {
            // Arrange
            Bestelling bestelling1 = new BestellingBuilder().SetDummy().Create();
            Bestelling bestelling2 = new BestellingBuilder().SetDummy().Create();

            _betaalContext.Bestellingen.Add(bestelling1);
            _betaalContext.Bestellingen.Add(bestelling2);
            _betaalContext.SaveChanges();

            var dataMapper = new BestellingDataMapper(_betaalContext);

            // Act
            List <Bestelling> result = dataMapper.GetAll().ToList();

            // Assert
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(bestelling1.BestelRegels.Count, result[0].BestelRegels.Count);
            Assert.AreEqual(bestelling2.BestelRegels.Count, result[1].BestelRegels.Count);
            Assert.AreEqual(bestelling1.Besteldatum, result[0].Besteldatum);
            Assert.AreEqual(bestelling2.Besteldatum, result[1].Besteldatum);
        }
        public void Insert_ShouldNotInsertArtikelInDatabase_When_AnExistingFactuurnummer_IsGiven()
        {
            // Arrange
            Bestelling bestelling1 = new BestellingBuilder().SetDummy()
                                     .SetFactuurnummer(1)
                                     .Create();
            Bestelling bestelling2 = new BestellingBuilder().SetDummy()
                                     .SetFactuurnummer(1)
                                     .Create();

            var dataMapper = new BestellingDataMapper(_context);

            // Act
            dataMapper.Insert(bestelling1);

            void Act()
            {
                dataMapper.Insert(bestelling2);
            }

            // Assert
            Assert.ThrowsException <DbUpdateException>((Action)Act);
        }