public void WHEN_receiving_message_twice_THEN_consumes_only_once() { var commandId = SequentialGuid.GenerateNewGuid(); var e = new ItemAdded { SourceType = "DomainAggregate", CorrelationId = commandId, SourceId = Guid.Empty, Id = 1, Name = "Silla", Version = 1 }; var mailSent = 0; this.sut.Consume <MailingSubscription>(e, () => { ++mailSent; Console.WriteLine("Mail sent once!"); }); this.sut.Consume <MailingSubscription>(e, () => { ++mailSent; Console.WriteLine("Mail sent twice! this not good...."); }); Assert.Equal(1, mailSent); }
public void WHEN_receiving_message_once_THEN_proyects_in_proc() { var commandId = SequentialGuid.GenerateNewGuid(); var e = new ItemAdded { SourceType = "DomainAggregate", CorrelationId = commandId, SourceId = Guid.Empty, Id = 1, Name = "Silla", Version = 1 }; this.sut.Project(e, (context) => { context.Items.Add(new Item { UnidentifiableId = e.Id, Name = e.Name }); }, (context) => { }); using (var context = this.contextFactory.Invoke()) { var item = context.Items.Where(i => i.UnidentifiableId == 1).FirstOrDefault(); var log = context.ReadModelingEvents.Where(l => l.SourceId == Guid.Empty && l.Version == 1).FirstOrDefault(); Assert.Equal("Silla", item.Name); Assert.True(log != null); Assert.Equal(commandId, log.CorrelationId); } }
public void CUANDO_se_actualiza_resumen_de_animales_por_periodo_ENTONCES_se_proyecta() { var correlationId = SequentialGuid.GenerateNewGuid(); var e = new SeActualizoResumenDeAnimalesPorPeriodo { SourceType = "TestAggregate", CantidadDeAnimales = 5, CorrelationId = correlationId, Periodo = 2015, SourceId = Guid.Empty, Version = 1 }; this.sut.Handle(e); using (var context = this.contextFactory.Invoke()) { var resumen = context.ResumenDeAnimalesDeTodosLosPeriodos .Where(x => x.Periodo == e.Periodo.ToString()) .FirstOrDefault(); Assert.NotNull(resumen); Assert.Equal(e.CantidadDeAnimales, resumen.Cantidad); var log = context.ReadModelingEvents .Where(x => x.CorrelationId == correlationId) .FirstOrDefault(); Assert.NotNull(log); } }
public void WHEN_receiving_message_twice_concurrently_THEN_proyects_only_once() { var commandId = SequentialGuid.GenerateNewGuid(); var e = new ItemAdded { SourceType = "DomainAggregate", CorrelationId = commandId, SourceId = Guid.Empty, Id = 1, Name = "Silla", Version = 1 }; try { this.sut.Project(e, (context) => { context.Items.Add(new Item { UnidentifiableId = e.Id, Name = e.Name }); // Concurrency this.sut.Project(e, (otherContextInstance) => { otherContextInstance.Items.Add(new Item { UnidentifiableId = e.Id, Name = e.Name }); }, (otherContextInstance) => { }); }, (context) => { }); // Should have thrown an error. Assert.True(false); } catch (Exception) { using (var context = this.contextFactory.Invoke()) { var item = context.Items.Where(i => i.UnidentifiableId == 1).ToList(); var log = context.ReadModelingEvents.Where(l => l.SourceId == Guid.Empty && l.Version == 1).ToList(); Assert.True(item.Count() == 1); Assert.True(log.Count() == 1); } } }
public GIVEN_events_and_read_model_with_data() { var id = SequentialGuid.GenerateNewGuid(); var actor = new ItemActor(id); actor.HandleCommands(); this.eventStore.Save(actor, new FakeCommand(id)); using (var context = this.readModelContextFactory.Invoke()) { context.ReadModelingEvents.Add( new ProjectedEvent { SourceId = Guid.Empty, CorrelationId = Guid.Empty, SourceType = "TestAggregate", EventType = "TestEvent", Version = 1 }); context.ReadModelingEvents.Add( new ProjectedEvent { SourceId = Guid.Empty, CorrelationId = Guid.Empty, SourceType = "TestAggregate", EventType = "TestEvent", Version = 2 }); context.ReadModelingEvents.Add( new ProjectedEvent { SourceId = Guid.Empty, CorrelationId = Guid.Empty, SourceType = "TestAggregate", EventType = "TestEvent", Version = 3 }); context.SaveChanges(); } }
public void AddItemBuggyProcess(string name) { var command = new AddItem(SequentialGuid.GenerateNewGuid()); this.buggyApp.Send(command); }
public void AddItem(string name) { var command = new AddItem(SequentialGuid.GenerateNewGuid()); this.app.Send(command); }