public void HandleMaakKlantAanCommand_ShouldReturnCommand(string naam, string omschrijving) { // Arrange var repositoryMock = new Mock <IOefeningRepository>(MockBehavior.Strict); repositoryMock.Setup(x => x.Add(It.IsAny <Oefening>())); var evenPublisherMock = new Mock <IEventPublisher>(MockBehavior.Strict); evenPublisherMock.Setup(x => x.PublishAsync(It.IsAny <DomainEvent>())) .Returns(new Task(() => { })); var target = new OefeningCommandListener(repositoryMock.Object, evenPublisherMock.Object); var oefening = new Oefening { Naam = naam, Omschrijving = omschrijving }; var command = new MaakOefeningAanCommand { Oefening = oefening }; // Act MaakOefeningAanCommand result = target.HandleMaakKlantAanCommand(command); // Assert Assert.AreSame(command, result); }
public void HandleMaakKlantAanCommand_ShouldPublishEventWithOefening(string naam, string omschrijving) { // Arrange var repositoryMock = new Mock <IOefeningRepository>(MockBehavior.Strict); repositoryMock.Setup(x => x.Add(It.IsAny <Oefening>())); var evenPublisherMock = new Mock <IEventPublisher>(MockBehavior.Strict); evenPublisherMock.Setup(x => x.PublishAsync(It.IsAny <DomainEvent>())) .Returns(new Task(() => { })); var target = new OefeningCommandListener(repositoryMock.Object, evenPublisherMock.Object); var oefening = new Oefening { Naam = naam, Omschrijving = omschrijving }; var command = new MaakOefeningAanCommand { Oefening = oefening }; // Act target.HandleMaakKlantAanCommand(command); // Assert evenPublisherMock.Verify(x => x.PublishAsync( It.Is <OefeningAangemaaktEvent>(e => e.Oefening == oefening)), Times.Once); }
public async Task <IActionResult> Add(Oefening oefening) { var command = new MaakOefeningAanCommand { Oefening = oefening }; var result = await _commandPublisher.PublishAsync <MaakOefeningAanCommand>(command); return(Ok(result.Oefening.Id)); }
public MaakOefeningAanCommand HandleMaakKlantAanCommand(MaakOefeningAanCommand command) { _oefeningRepository.Add(command.Oefening); _eventPublisher.PublishAsync(new OefeningAangemaaktEvent { Oefening = command.Oefening }); return(command); }