public async Task Verify_that_UpdateAsync_can_be_called_on_SpeechRepository_and_fire_RepositoryUpdateAsync_only_once() { //Arrange Guid speechId = Guid.NewGuid(); 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"; var speech = new Domain.SpeechAggregate.Speech(speechId, new Title(newTitle), new UrlValue("http://mysite.com"), new Description(description), SpeechType.Conferences); Mock <IRepository <Domain.SpeechAggregate.Speech, Guid> > mockRepository = new Mock <IRepository <Domain.SpeechAggregate.Speech, Guid> >(); mockRepository.Setup(x => x.UpdateAsync(It.IsAny <Domain.SpeechAggregate.Speech>())) .Returns(Task.CompletedTask) .Callback <Domain.SpeechAggregate.Speech>(x => { }); var options = new DbContextOptionsBuilder <DataBaseContext>().UseInMemoryDatabase(databaseName: "InMemoryDB").Options; var context = new DataBaseContext(options); await context.Speech.AddAsync(speech); ISpeechRepository sut = new SpeechRepository(mockRepository.Object, context); //Act await sut.DeleteAsync(speech); //Assert mockRepository.Verify(x => x.UpdateAsync(It.IsAny <Domain.SpeechAggregate.Speech>()), Times.Once); }
public async Task HandlingUpdateWhenTheSpeechIsValidAndExistShouldPerformUpdate() { //Arrange Guid speechId = Guid.NewGuid(); 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"; var speech = new Domain.SpeechAggregate.Speech(speechId, new Title(newTitle), new UrlValue("http://mysite.com"), new Description(description), SpeechType.Conferences); Mock <IRepository <Domain.SpeechAggregate.Speech, Guid> > mockRepository = new Mock <IRepository <Domain.SpeechAggregate.Speech, Guid> >(); DbContextOptionsBuilder <DataBaseContext> optionsBuilder = new DbContextOptionsBuilder <DataBaseContext>(); optionsBuilder.UseInMemoryDatabase("FakeInMemoryData"); var context = new DataBaseContext(optionsBuilder.Options); //context.Speech.Add(speechToUpdate); //context.SaveChanges(); ISpeechRepository sut = new SpeechRepository(mockRepository.Object, context); //Act await sut.UpdateAsync(speech); //Assert var result = context.Entry(speech).Entity.Title.Value; Assert.Equal(newTitle, result); }
public async Task HandlingUpdateWhenTheSpeechDoesNotExistShouldRaiseRepositoryNotFoundException() { //Arrange 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"; var speech = new Domain.SpeechAggregate.Speech(Guid.NewGuid(), new Title(newTitle), new UrlValue("http://mysite.com"), new Description(description), SpeechType.Conferences); Mock <IRepository <Domain.SpeechAggregate.Speech, Guid> > mockRepository = new Mock <IRepository <Domain.SpeechAggregate.Speech, Guid> >(); DbContextOptionsBuilder <DataBaseContext> optionsBuilder = new DbContextOptionsBuilder <DataBaseContext>(); optionsBuilder.UseInMemoryDatabase("FakeInMemoryData"); var context = new DataBaseContext(optionsBuilder.Options); ISpeechRepository sut = new SpeechRepository(mockRepository.Object, context); //Act //Assert await Assert.ThrowsAsync <NotFoundRepositoryException>(() => sut.UpdateAsync(speech)); }
public async Task HandlingUpdateWhenSpeechIsNullShouldRaiseRepositoryArgumentNullException() { //Arrange Mock <IRepository <Domain.SpeechAggregate.Speech, Guid> > mockRepository = new Mock <IRepository <Domain.SpeechAggregate.Speech, Guid> >(); ISpeechRepository sut = new SpeechRepository(mockRepository.Object, It.IsAny <DataBaseContext>()); //Act //Assert await Assert.ThrowsAsync <ArgumentNullRepositoryException>(() => sut.UpdateAsync(null)); }
public async Task Verify_that_CreateAsync_can_be_called_on_SpeechRepository_and_fire_RepositoryCreateAsync_only_once() { //Arrange Mock <IRepository <Domain.SpeechAggregate.Speech, Guid> > mockRepository = new Mock <IRepository <Domain.SpeechAggregate.Speech, Guid> >(); mockRepository.Setup(x => x.CreateAsync(It.IsAny <Domain.SpeechAggregate.Speech>())) .Returns(Task.CompletedTask) .Callback <Domain.SpeechAggregate.Speech>(x => { }); ISpeechRepository sut = new SpeechRepository(mockRepository.Object); //Act await sut.CreateAsync(It.IsAny <Domain.SpeechAggregate.Speech>()); //Assert mockRepository.Verify(x => x.CreateAsync(It.IsAny <Domain.SpeechAggregate.Speech>()), Times.Once); }
public void RemoveJar() { JarContainer.SetActive(false); PaigeScript.Speak(SpeechRepository.PaigeFreedom()); // stop paige animating and kiss??? }