Esempio n. 1
0
        public void ThenVoegEenKlantToeAanHetSysteemMetVoornaamAchternaamTelefoonnummerEmailEnAdres()
        {
            var dataMapper         = new KlantDataMapper(_context);
            var eventPublisherMock = new Mock <IEventPublisher>(MockBehavior.Strict);

            eventPublisherMock.Setup(p => p.Publish(It.IsAny <DomainEvent>()));
            var controller = new KlantController(dataMapper, eventPublisherMock.Object, new LoggerFactory());

            List <long> results = new List <long>();

            for (int i = 0; i < _klanten.Count; i++)
            {
                Klant nieuweKlant = new Klant()
                {
                    Voornaam       = _klanten[i].Item1,
                    Achternaam     = _klanten[i].Item2,
                    Telefoonnummer = _klanten[i].Item3,
                    Email          = _klanten[i].Item4,
                    Adres          = _klanten[i].Item5
                };

                results.Add(controller.HandleVoegKlantToe(new VoegKlantToeCommand(nieuweKlant, "")));
            }

            eventPublisherMock.Verify(e => e.Publish(It.IsAny <DomainEvent>()), Times.Exactly(2));
            eventPublisherMock.VerifyAll();
            Assert.AreEqual(1, results[0]);
            Assert.AreEqual(2, results[1]);
        }
        public void HandleVoegKlantToe_ShouldInsertKlantIntoTheDatabase()
        {
            var eventQueueName = "TestEventQueue";
            var klant          = _klantBuilder.SetDummy().SetId(3).SetEmail("*****@*****.**").Create();
            var command        = new VoegKlantToeCommand(klant, NameConstants.KlantBeheerVoegKlantToeCommand);

            _nijnContext.EventBus.DeclareQueue(eventQueueName, new List <string> {
                NameConstants.KlantBeheerKlantToegevoegdEvent
            });

            var result = _target.HandleVoegKlantToe(command);

            var eventQueue = _nijnContext.EventBus.Queues[eventQueueName];

            Assert.AreEqual(1, eventQueue.MessageQueueLength);

            var dbResult = _dbContext.Klanten.Include(k => k.Adres).SingleOrDefault(k => k.Id == 3);

            Assert.IsNotNull(dbResult);
            Assert.AreEqual(klant.Email, dbResult.Email);
        }
        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));
        }