private void Persist(NewsletterSubscription view, ReaderSubscribed @event)
 {
     view.Id           = @event.SubscriptionId;
     view.NewsletterId = @event.NewsletterId;
     view.ReaderId     = @event.ReaderId;
     view.FirstName    = @event.FirstName;
     view.OpensCount   = 0;
 }
Exemplo n.º 2
0
 public void Apply(NewsletterSubscription view, ReaderSubscribed @event)
 {
     view.Id           = @event.SubscriptionId;
     view.NewsletterId = @event.NewsletterId;
     view.ReaderId     = @event.ReaderId;
     view.FirstName    = @event.FirstName;
     view.OpensCount   = 0;
 }
        public async Task updateonly_event_for_custom_view_projection_should_not_create_new_document()
        {
            StoreOptions(_ =>
            {
                _.AutoCreateSchemaObjects = AutoCreate.All;
                _.Events.TenancyStyle     = Marten.Storage.TenancyStyle.Conjoined;
                _.Events.InlineProjections.Add <NewsletterSubscriptionProjection>();
            });

            var subscriptionId = Guid.NewGuid();
            var newsletterId   = Guid.NewGuid();
            var readerId       = Guid.NewGuid();

            var readerSubscribed = new ReaderSubscribed(subscriptionId, newsletterId, readerId, "John Doe");

            theSession.Events.StartStream <NewsletterSubscription>(streamId, readerSubscribed);
            await theSession.SaveChangesAsync();

            var subscription = await theSession.LoadAsync <NewsletterSubscription>(subscriptionId);

            subscription.ShouldNotBeNull();

            var newsletterOpened = new NewsletterOpened(subscriptionId, DateTime.Now);

            theSession.Events.Append(subscriptionId, newsletterOpened);
            await theSession.SaveChangesAsync();

            subscription = await theSession.LoadAsync <NewsletterSubscription>(subscriptionId);

            subscription.ShouldNotBeNull();

            var readerUnsubscribed = new ReaderUnsubscribed(subscriptionId);

            theSession.Events.Append(subscriptionId, readerUnsubscribed);
            await theSession.SaveChangesAsync();

            subscription = await theSession.LoadAsync <NewsletterSubscription>(subscriptionId);

            subscription.ShouldBeNull();

            var newsletterOpenedAfterUnsubscribe = new NewsletterOpened(subscriptionId, DateTime.Now);

            theSession.Events.Append(subscriptionId, newsletterOpenedAfterUnsubscribe);
            await theSession.SaveChangesAsync();

            subscription = await theSession.LoadAsync <NewsletterSubscription>(subscriptionId);

            subscription.ShouldBeNull();
        }