public void given_two_events_with_the_same_value_for_unique_field_with_single_property_when_inline_transformation_is_applied_then_throws_exception() { //1. Create Events const string email = "*****@*****.**"; var firstEvent = new UserCreated { UserId = Guid.NewGuid(), Email = email, FirstName = "John", Surname = "Smith" }; var secondEvent = new UserCreated { UserId = Guid.NewGuid(), Email = email, FirstName = "John", Surname = "Doe" }; using (var session = theStore.OpenSession()) { //2. Publish Events session.Events.Append(firstEvent.UserId, firstEvent); session.Events.Append(secondEvent.UserId, secondEvent); //3. Unique Exception Was thrown try { session.SaveChanges(); } catch (Marten.Exceptions.MartenCommandException exception) { ((PostgresException)exception.InnerException).SqlState.ShouldBe(UniqueSqlState); } } }
private void Apply(UniqueUser view, UserCreated @event) { view.Id = @event.UserId; view.Email = @event.Email; view.UserName = @event.Email; view.FirstName = @event.Email; view.Surname = @event.Surname; }