public void ThrowsExceptionWhenEmailIsAlreadyInUse() { _repoMock.Setup(r => r.Get(It.IsAny <Expression <Func <Trainer, bool> > >())) .Returns(new List <Trainer> { new Trainer { } }); var handler = new RegisterTrainerHandler(null, _repoMock.Object); Action action = () => handler.Handle(Request, new System.Threading.CancellationToken()); action.Should().ThrowExactly <EntityAlreadyExistsException>().WithMessage("[email protected] is already in use."); }
public void CallRepoAddAndPublishesEventWhenDataIsValid() { _repoMock.Setup(r => r.Get(It.IsAny <Expression <Func <Trainer, bool> > >())) .Returns(new List <Trainer>()); _repoMock.Setup(r => r.Add(It.IsAny <Trainer>())); _busMock.Setup(r => r.Publish(It.IsAny <UserRegisteredEvent>())); var handler = new RegisterTrainerHandler(_busMock.Object, _repoMock.Object); handler.Handle(Request, new System.Threading.CancellationToken()); _repoMock.Verify(r => r.Add(It.IsAny <Trainer>()), Times.Once); _busMock.Verify(r => r.Publish(It.IsAny <UserRegisteredEvent>()), Times.Once); }