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 BeforeEach()
        {
            _bestellingDataMapperMock = new Mock <IBestellingDataMapper>(MockBehavior.Strict);
            _betalingDataMapperMock   = new Mock <IBetalingDataMapper>(MockBehavior.Strict);
            _eventPublisherMock       = new Mock <IEventPublisher>(MockBehavior.Strict);
            _bestellingDataMapperMock.Setup(b => b.GetByFactuurnummer(1)).Returns(new Bestelling()
            {
                Klantnummer = 1
            });

            _eventPublisherMock.Setup(s => s.Publish(It.IsAny <DomainEvent>()));
            _bestellingBuilder = new BestellingBuilder();
            _target            = new BetalingVerwerkenService(_betalingDataMapperMock.Object, _bestellingDataMapperMock.Object, _eventPublisherMock.Object, new LoggerFactory());
        }
コード例 #3
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 BetalingDataMapper(_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));
        }
コード例 #5
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);
        }
コード例 #8
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 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]));
        }
        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 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);
        }
コード例 #12
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);
        }