Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's not possible to use Task in the class name in v4 #1647

Closed
oskardudycz opened this issue Dec 5, 2020 · 0 comments
Closed

It's not possible to use Task in the class name in v4 #1647

oskardudycz opened this issue Dec 5, 2020 · 0 comments

Comments

@oskardudycz
Copy link
Collaborator

Having such code

using System;
using Marten.Integration.Tests.TestsInfrasructure;
using SharpTestsEx;
using Xunit;

namespace Marten.Integration.Tests.EventStore.Aggregate
{
    public class TaskCreated
    {
        public Guid TaskId { get; set; }
        public string Description { get; set; }
    }

    public class TaskUpdated
    {
        public Guid TaskId { get; set; }
        public string Description { get; set; }
    }

    namespace OldVersion
    {
        public class Task
        {
            public Guid Id { get; set; }

            public string Description { get; set; }

            public void Apply(TaskCreated @event)
            {
                Id = @event.TaskId;
                Description = @event.Description;
            }

            public void Apply(TaskUpdated @event)
            {
                Description = @event.Description;
            }
        }
    }

    namespace NewVersion
    {
        public class Task
        {
            public Guid Id { get; set; }

            public string Description { get; set; }

            public void Apply(TaskCreated @event)
            {
                Id = @event.TaskId;
                Description = $"New Logic: {@event.Description}";
            }

            public void Apply(TaskUpdated @event)
            {
                Description = $"New Logic: {@event.Description}";
            }
        }
    }

    public class Reaggregation: MartenTest
    {
        public Reaggregation() : base(false)
        {
        }

        public IDocumentSession CreateSessionWithInlineAggregationFor<TTask>() where TTask : class, new()
        {
            return base.CreateSession(options =>
            {
                options.Events.AddEventTypes(new[] { typeof(TaskCreated), typeof(TaskUpdated) });
                //It's needed to manualy set that inline aggegation should be applied
                options.Events.InlineProjections.AggregateStreamsWith<TTask>();
            });
        }

        [Fact]
        public void Given_When_Then()
        {
            var taskId = Guid.NewGuid();

            var events = new object[]
            {
                new TaskCreated {TaskId = taskId, Description = "Task 1"},
                new TaskUpdated {TaskId = taskId, Description = "Task 1 Updated"},
            };

            OldVersion.Task taskFromV1InlineAggregation;
            OldVersion.Task taskFromV1OnlineAggregation;

            using (var session = CreateSessionWithInlineAggregationFor<OldVersion.Task>())
            {
                //1. Publish events
                session.Events.StartStream<OldVersion.Task>(taskId, events);

                session.SaveChanges();

                taskFromV1InlineAggregation = session.Load<OldVersion.Task>(taskId);
                taskFromV1OnlineAggregation = session.Events.AggregateStream<OldVersion.Task>(taskId);
            }

            //2. Both inline and online aggregation for the same type should be the same
            taskFromV1InlineAggregation.Description.Should().Be.EqualTo("Task 1 Updated");
            taskFromV1InlineAggregation.Description.Should().Be.EqualTo(taskFromV1OnlineAggregation.Description);

            //3. Simulate change to aggregation logic
            NewVersion.Task taskFromV2InlineAggregation;
            NewVersion.Task taskFromV2OnlineAggregation;

            using (var session = CreateSessionWithInlineAggregationFor<NewVersion.Task>())
            {
                taskFromV2InlineAggregation = session.Load<NewVersion.Task>(taskId);
                taskFromV2OnlineAggregation = session.Events.AggregateStream<NewVersion.Task>(taskId);
            }

            //4. Inline aggregated snapshot won't change automatically
            taskFromV2InlineAggregation.Description.Should().Be.EqualTo(taskFromV1InlineAggregation.Description);
            taskFromV2InlineAggregation.Description.Should().Not.Be.EqualTo("New Logic: Task 1 Updated");

            //5. But online aggregation is being applied automatically
            taskFromV2OnlineAggregation.Description.Should().Not.Be.EqualTo(taskFromV1OnlineAggregation.Description);
            taskFromV2OnlineAggregation.Description.Should().Be.EqualTo("New Logic: Task 1 Updated");

            //6. Reagregation
            using (var session = CreateSessionWithInlineAggregationFor<NewVersion.Task>())
            {
                //7. Get online aggregation
                //8. Store manually online aggregation as inline aggregation
                session.Store(taskFromV2OnlineAggregation);
                session.SaveChanges();

                var taskFromV2AfterReaggregation = session.Load<NewVersion.Task>(taskId);

                taskFromV2AfterReaggregation.Description.Should().Not.Be.EqualTo(taskFromV1OnlineAggregation.Description);
                taskFromV2AfterReaggregation.Description.Should().Be.EqualTo(taskFromV2OnlineAggregation.Description);
                taskFromV2AfterReaggregation.Description.Should().Be.EqualTo("New Logic: Task 1 Updated");

                //9. Check if next event would be properly applied to inline aggregation
                session.Events.Append(taskId, new TaskUpdated { TaskId = taskId, Description = "Completely New text" });
                session.SaveChanges();

                var taskFromV2NewInlineAggregation = session.Load<NewVersion.Task>(taskId);
                taskFromV2NewInlineAggregation.Description.Should().Be.EqualTo("New Logic: Completely New text");
            }
        }
    }
}

results with compilation error for 4.0.0-alpha.4:

CS0104: 'Task' is an ambiguous reference between 'Marten.Integration.Tests.EventStore.Aggregate.OldVersion.Task' and 'System.Threading.Tasks.Task'
CS0104: 'Task' is an ambiguous reference between 'Marten.Integration.Tests.EventStore.Aggregate.OldVersion.Task' and 'System.Threading.Tasks.Task'
CS0104: 'Task' is an ambiguous reference between 'Marten.Integration.Tests.EventStore.Aggregate.OldVersion.Task' and 'System.Threading.Tasks.Task'
CS0104: 'Task' is an ambiguous reference between 'Marten.Integration.Tests.EventStore.Aggregate.OldVersion.Task' and 'System.Threading.Tasks.Task'
CS0161: 'UpdateTaskOperation.PostprocessAsync(DbDataReader, IList<Exception>, CancellationToken)': not all code paths return a value
CS0104: 'Task' is an ambiguous reference between 'Marten.Integration.Tests.EventStore.Aggregate.OldVersion.Task' and 'System.Threading.Tasks.Task'
CS0104: 'Task' is an ambiguous reference between 'Marten.Integration.Tests.EventStore.Aggregate.OldVersion.Task' and 'System.Threading.Tasks.Task'

Eventhough it's not the smartest to name class as Task I think that it's the common name in the codebase and it might be too big restriction for the users.

See more in the Gitter dicscussion: https://gitter.im/JasperFx/marten?at=5fcbe8214b6e8f2d3c7f9051

@oskardudycz oskardudycz added this to the 4.0 milestone Dec 5, 2020
@oskardudycz oskardudycz changed the title It's not possible to use Task in the class name It's not possible to use Task in the class name in v4 Dec 5, 2020
oskardudycz added a commit to oskardudycz/EventSourcing.NetCore that referenced this issue Dec 5, 2020
oskardudycz added a commit to oskardudycz/EventSourcing.NetCore that referenced this issue Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant