public async Task Registering_church_successfully() { //Arrange's var uow = new Mock <IUnitOfWork>(); var bus = new Mock <IBus>(); var notification = new Mock <DomainNotificationHandler>(); var mockChurchRepository = new Mock <IChurchRepository>(); var argument = RegisterChurchCommand.Factory.Create("Richmond’s First Baptist Church", email: "*****@*****.**", photo: "1.jpg", region: 55, prefix: 21, cellPhone: "123456789", homePhone: "22222222"); //Setup uow.Setup(x => x.Commit()).Returns(new CommandResult(success: true)); //Act's var commandHandler = new ChurchCommandHandler(uow.Object, bus.Object, notification.Object, mockChurchRepository.Object); await commandHandler.Handle(argument, CancellationToken.None); //Assert's commandHandler.Commit().Should().BeTrue(); //Verify that methods were invocation mockChurchRepository.Verify(x => x.Add(It.IsAny <Church>()), Times.Once); bus.Verify(x => x.RaiseEvent(It.IsAny <DomainNotification>()), Times.Never()); uow.Verify(x => x.Commit()); bus.Verify(x => x.RaiseEvent(It.IsAny <ChurchRegisteredEvent>()), Times.Once); }
public async Task Deleting_church_successfully() { //Arrange's var uow = new Mock <IUnitOfWork>(); var bus = new Mock <IBus>(); var domainNotification = new Mock <DomainNotificationHandler>(); var mockChurchRepository = new Mock <IChurchRepository>(); var argument = DeleteChurchCommand.Factory.Create(id: Guid.NewGuid()); //Setup uow.Setup(x => x.Commit()).Returns(new CommandResult(success: true)); //Act's var commandHandler = new ChurchCommandHandler(uow.Object, bus.Object , domainNotification.Object, mockChurchRepository.Object); await commandHandler.Handle(argument, CancellationToken.None); //Assent's commandHandler.Commit().Should().BeTrue(); //Verify that methods were invocation mockChurchRepository.Verify(x => x.GetById(It.IsAny <Guid>()), Times.Never); mockChurchRepository.Verify(x => x.Update(It.IsAny <Church>()), Times.Never); mockChurchRepository.Verify(x => x.Remove(It.IsAny <Guid>()), Times.Once); bus.Verify(x => x.RaiseEvent(It.IsAny <DomainNotification>()), Times.Never()); bus.Verify(x => x.RaiseEvent(It.IsAny <ChurchDeletedEvent>()), Times.Once); uow.Verify(x => x.Commit()); }