public void PersonCreatedService_receives_new_Person_and_Saves_to_Database() { //Arrange var options = new DbContextOptionsBuilder <DeelnemerContext>() .UseSqlServer(@"Server=.\SQLEXPRESS;Database=JeroenDonaldDuckDeelnemers;Trusted_Connection=true") .Options; using (var context = new DeelnemerContext(options)) using (var tx = context.Database.BeginTransaction()) using (var listener = new TestListener()) { context.Database.EnsureCreated(); var service = new BlockingReceiver <PersonCreated>(); service.SubscribeToEvents(listener); //Act service.Execute(new PersonCreated() { FirstName = "Klaas-Teake" }); context.SaveChanges(); //Assert var result = context.Deelnemers.Where(p => p.FirstName == "Klaas-Teake").First(); Assert.Equal("Klaas-Teake", result.FirstName); } }
public void WaitForNextValue() { var items = Enumerable.Range(0, 10).ToList(); using (var service = new BlockingReceiver <int>()) { var task = Task.Run(() => { foreach (var item in items) { service.Execute(item); Thread.Sleep(100); } }); foreach (var item in items) { var result = service.Next(); Assert.Equal(item, result); } } }