public async Task HandlingUpdateWhenExpectedVersionIsNotEqualToAggregateVersionShouldRaiseConcurrencyException() { //Arrange string title = @"Lorem Ipsum is simply dummy text"; string newTitle = @"New Lorem Ipsum is simply dummy text"; string description = @"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book"; string url = "http://www.test.com"; UpdateSpeechCommandMessage command = new UpdateSpeechCommandMessage(Guid.NewGuid(), newTitle, description, url, SpeechType.Conferences.IntValue, 2); var mockEventSourcingSubscriber = new Mock <IEventSourcingSubscriber>(); Mock <ISpeechRepository> moqSpeechRepository = new Mock <ISpeechRepository>(); var speech = new Domain.SpeechAggregate.Speech(Guid.NewGuid(), new Title(title), new UrlValue("http://mysite.com"), new Description(description), SpeechType.Conferences); Mock <IEventStoreRepository> moqEventStoreRepository = new Mock <IEventStoreRepository>(); moqEventStoreRepository.Setup(m => m.GetByIdAsync <Domain.SpeechAggregate.Speech>(It.IsAny <Guid>())) .Returns(Task.FromResult(speech)); IUpdateSpeechUseCase usecase = new SpeechUseCase(moqSpeechRepository.Object, mockEventSourcingSubscriber.Object, moqEventStoreRepository.Object); //Act //Assert await Assert.ThrowsAsync <ConcurrencyException>(() => usecase.Handle(command)); }
public async Task HandlingUpdateWhenCommandIsNotNullShouldUpdateSpeechTitle() { //Arrange string title = @"Lorem Ipsum is simply dummy text"; string newTitle = @"New Lorem Ipsum is simply dummy text"; string description = @"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book"; string newDescription = @"new Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book"; string url = "http://www.test.com"; string newUrl = "http://www.test_new.com"; var type = SpeechType.Conferences.Value.ToString(); var newType = SpeechType.SelfPacedLabs.IntValue; UpdateSpeechCommandMessage command = new UpdateSpeechCommandMessage(Guid.NewGuid(), newTitle, newDescription, newUrl, newType, 0); var mockEventSourcingSubscriber = new Mock <IEventSourcingSubscriber>(); Mock <ISpeechRepository> moqSpeechRepository = new Mock <ISpeechRepository>(); moqSpeechRepository.Setup(x => x.UpdateAsync(It.IsAny <Domain.SpeechAggregate.Speech>())) .Returns(Task.CompletedTask).Verifiable(); var speech = new Domain.SpeechAggregate.Speech(Guid.NewGuid(), new Title(title), new UrlValue(url), new Description(description), new SpeechType(type)); Mock <IEventStoreRepository> moqEventStoreRepository = new Mock <IEventStoreRepository>(); moqEventStoreRepository.Setup(m => m.GetByIdAsync <Domain.SpeechAggregate.Speech>(It.IsAny <Guid>())) .Returns(Task.FromResult(speech)); IUpdateSpeechUseCase usecase = new SpeechUseCase(moqSpeechRepository.Object, mockEventSourcingSubscriber.Object, moqEventStoreRepository.Object); //Act await usecase.Handle(command); //Assert moqSpeechRepository.Verify(m => m.UpdateAsync(It.Is <Domain.SpeechAggregate.Speech>(n => n.Id.Equals(speech.Id) && n.Description.Value.Equals(command.Description, StringComparison.InvariantCultureIgnoreCase) && n.Title.Value.Equals(command.Title) && n.Url.Value.Equals(command.Url, StringComparison.InvariantCultureIgnoreCase) && n.Type.Equals(new SpeechType(command.Type.Value)) )), Times.Once); mockEventSourcingSubscriber.Verify(m => m.Subscribe(It.IsAny <IEventSourcing>()), Times.Once); }
public async Task HandlingUpdateWhenCommandIsNullShouldRaiseApplicationArgumentNullException() { //Arrange Mock <ISpeechRepository> moqSpeechRepository = new Mock <ISpeechRepository>(); var mockEventSourcingSubscriber = new Mock <IEventSourcingSubscriber>(); //Act IUpdateSpeechUseCase usecase = new SpeechUseCase(moqSpeechRepository.Object, mockEventSourcingSubscriber.Object, It.IsAny <IEventStoreRepository>()); //Assert await Assert.ThrowsAsync <ArgumentNullApplicationException>(() => usecase.Handle(null)); }
public async Task RegisterSpeechUseCaseWithNullSpeechThrowsExceptionTest() { //Arrange Mock <ISpeechRepository> moqSpeechRepository = new Mock <ISpeechRepository>(); var mockEventSourcingSubscriber = new Mock <IEventSourcingSubscriber>(); //Act ICreateSpeechUseCase usecase = new SpeechUseCase(moqSpeechRepository.Object, mockEventSourcingSubscriber.Object, It.IsAny <IEventStoreRepository>()); //Assert await Assert.ThrowsAsync <ArgumentNullApplicationException>(() => usecase.Handle(null)); }
public async Task DeleteSpeechUseCaseWithValidInputReturnSuccessTest() { //Arrange long orignalVersion = 0; var id = Guid.NewGuid(); string title = @"Lorem Ipsum is simply dummy text"; string description = @"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book"; var speech = new Domain.SpeechAggregate.Speech(id, new Title(title), new UrlValue("http://mysite.com"), new Description(description), SpeechType.Conferences); /* ------------ I will use repository pattern, aggregate roots are the only objects my * code loads from the repository.*/ Mock <ISpeechRepository> moqSpeechRepository = new Mock <ISpeechRepository>(); moqSpeechRepository.Setup(m => m.DeleteAsync(It.IsAny <Domain.SpeechAggregate.Speech>())) .Returns(Task.FromResult <ISpeechRepository>(null)).Verifiable(); var mockEventStoreRepository = new Mock <IEventStoreRepository>(); mockEventStoreRepository.Setup(m => m.GetByIdAsync <Domain.SpeechAggregate.Speech>(It.IsAny <Guid>())).Returns(Task.FromResult(speech)); // ------------ I'm on the command side of CQRS pattern, so I don't need an output port // ------------ I need a command to delete a new speech var deleteSpeechCommand = new DeleteSpeechCommandMessage(id, orignalVersion); var mockEventSourcingSubscriber = new Mock <IEventSourcingSubscriber>(); //Act // ------------ DeleteSpeechUseCase is the object under test IDeleteSpeechUseCase usecase = new SpeechUseCase(moqSpeechRepository.Object, mockEventSourcingSubscriber.Object, mockEventStoreRepository.Object); await usecase.Handle(deleteSpeechCommand); //Assert /* ------------ The object returns void , so I will verify that a new Speech will be inserted into the database * when SaveChanges is called.*/ moqSpeechRepository.Verify(m => m.DeleteAsync(It.IsAny <Domain.SpeechAggregate.Speech>()), Times.Once, "DeleteAsync must be called only once"); }
public async Task RegisterSpeechUseCaseWithValidInputReturnSuccessTest() { //Arrange /* ------------ I will use repository pattern, aggregate roots are the only objects my * code loads from the repository.*/ Mock <ISpeechRepository> moqSpeechRepository = new Mock <ISpeechRepository>(); moqSpeechRepository.Setup(m => m.CreateAsync(It.IsAny <Domain.SpeechAggregate.Speech>())) .Returns(Task.FromResult <ISpeechRepository>(null)).Verifiable(); // ------------ I'm on the command side of CQRS pattern, so I don't need an output port // ------------ I need a command to regsiter a new speech var registerSpeechCommand = new RegisterSpeechCommandMessage( "Microservices getting started", "A Microservices from scratch online event Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took rem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.", "http://microservices-getting-started.logcorner.com", 2); var mockEventSourcingSubscriber = new Mock <IEventSourcingSubscriber>(); //Act // ------------ RegisterSpeechUseCase is the object under test ICreateSpeechUseCase usecase = new SpeechUseCase(moqSpeechRepository.Object, mockEventSourcingSubscriber.Object, It.IsAny <IEventStoreRepository>()); await usecase.Handle(registerSpeechCommand); //Assert /* ------------ The object returns void , so I will verify that a new Speech will be inserted into the database * when SaveChanges is called.*/ moqSpeechRepository.Verify(m => m.CreateAsync(It.IsAny <Domain.SpeechAggregate.Speech>()), Times.Once, "CreateAsync must be called only once"); // Verify that SaveChanges is called // moqUnitOfWork.Verify(m => m.Commit(), Times.Once, "Commit must be called only once"); }
public async Task HandlingUpdateWhenSpeechDoesNotExistShouldRaiseApplicationNotFoundException() { //Arrange UpdateSpeechCommandMessage command = new UpdateSpeechCommandMessage( Guid.Empty, null, null, null, null, 0); Mock <ISpeechRepository> moqSpeechRepository = new Mock <ISpeechRepository>(); var mockEventSourcingSubscriber = new Mock <IEventSourcingSubscriber>(); Mock <IEventStoreRepository> moqEventStoreRepository = new Mock <IEventStoreRepository>(); moqEventStoreRepository.Setup(m => m.GetByIdAsync <Domain.SpeechAggregate.Speech>(command.SpeechId)) .Returns(Task.FromResult((Domain.SpeechAggregate.Speech)null)); IUpdateSpeechUseCase usecase = new SpeechUseCase(moqSpeechRepository.Object, mockEventSourcingSubscriber.Object, moqEventStoreRepository.Object); //Act //Assert await Assert.ThrowsAsync <NotFoundApplicationException>(() => usecase.Handle(command)); }