public async Task Deleting_church_with_id_incorrect() { //Arrange's var uow = new Mock <IUnitOfWork>(); var bus = new Mock <IBus>(); var domainNotification = new Mock <DomainNotificationHandler>(); var mockChurchRepository = new Mock <IChurchRepository>(); var arguments = DeleteChurchCommand.Factory.Create( id: Guid.Empty); DomainNotification domainNotificationResult = null; bus.Setup(x => x.RaiseEvent(It.IsAny <DomainNotification>())) .Callback <DomainNotification>(notification => domainNotificationResult = notification); //Act's var commandHandler = new ChurchCommandHandler( uow.Object, bus.Object , domainNotification.Object, mockChurchRepository.Object); await commandHandler.Handle(arguments, CancellationToken.None); //Assert's domainNotification.Should().NotBeNull(); domainNotificationResult.AggregateId.Should().Be(Guid.Empty); domainNotificationResult.Key.Should().Be("Id"); domainNotificationResult.MessageType.Should().Be("DomainNotification"); domainNotificationResult.Value.Should().Be("Please make sure you entered the id correctly."); }
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()); }
public async Task Registering_church_with_argument_invalid() { //Arrange's var uow = new Mock <IUnitOfWork>(); var bus = new Mock <IBus>(); var domainNotification = new Mock <DomainNotificationHandler>(); var mockChurchRepository = new Mock <IChurchRepository>(); var arguments = RegisterChurchCommand.Factory.Create( name: @"Richmond’s First Baptist ChurchRichmond’s First Baptist ChurchRichmond’s First Baptist ChurchRichmond’s First Baptist ChurchRichmond’s First Baptist Church Richmond’s First Baptist Church" , email: "*****@*****.**" , photo: "1.jpg" , region: 55 , prefix: 21 , cellPhone: "123456789" , homePhone: "22222222"); DomainNotification domainNotificationResult = null; bus.Setup(x => x.RaiseEvent(It.IsAny <DomainNotification>())) .Callback <DomainNotification>(notification => domainNotificationResult = notification); //Act's var commandHandler = new ChurchCommandHandler( uow.Object, bus.Object , domainNotification.Object, mockChurchRepository.Object); await commandHandler.Handle(arguments, CancellationToken.None); //Assert's domainNotification.Should().NotBeNull(); domainNotificationResult.AggregateId.Should().Be(Guid.Empty); domainNotificationResult.Key.Should().Be("Name"); domainNotificationResult.MessageType.Should().Be("DomainNotification"); domainNotificationResult.Value.Should().Be("Name must be between 2 and 150 characters."); }