public void Check_DomainEvents_ProjectAdded_Raise()
        {
            //given

            //existing project
            var project = Project.From(EntityId.From(1u), Description.From("descriptionText"));

            var taskOptionsBuilder = new DbContextOptionsBuilder <ActivityDbContext>();

            taskOptionsBuilder.UseSqlite("Data Source=todoagility_projectAdded_test.db;");
            var taskDbContext = new ActivityDbContext(taskOptionsBuilder.Options);
            var repTask       = new ActivityRepository(taskDbContext);

            using var taskDbSession = new DbSession <IActivityRepository>(taskDbContext, repTask);

            var handlerActivityAdded = new ProjectAddedHandler(taskDbSession);
            var dispatcher           = new DomainEventDispatcher();

            dispatcher.Subscribe(typeof(ProjectAddedEvent).FullName, handlerActivityAdded);

            //when
            dispatcher.Publish(ProjectAddedEvent.For(project));

            //then
            var projectId = EntityId.From(1u);
            var proj      = repTask.GetProject(projectId);

            Assert.NotNull(proj);
        }
        public void Check_ChangeStatusActivityCommandHandler_Failed()
        {
            var description    = "Given Description";
            var id             = 1u;
            var newStatus      = 4;
            var projectId      = 1u;
            var dispatcher     = new DomainEventDispatcher();
            var optionsBuilder = new DbContextOptionsBuilder <ActivityDbContext>();

            optionsBuilder.UseSqlite("Data Source=todoagility_cqrs_changed_failed_test.db;");
            var taskDbContext = new ActivityDbContext(optionsBuilder.Options);
            var repTask       = new ActivityRepository(taskDbContext);

            using var taskDbSession = new DbSession <IActivityRepository>(taskDbContext, repTask);

            var originalTask = Activity.From(Description.From(description), EntityId.From(id),
                                             EntityId.From(projectId), ActivityStatus.From(1));

            taskDbSession.Repository.Add(originalTask);
            taskDbSession.SaveChanges();

            var command = new ChangeActivityStatusCommand(id, newStatus);

            var handler = new ChangeActivityStatusCommandHandler(taskDbSession, dispatcher);
            var result  = handler.Execute(command);

            Assert.False(result.IsSucceed);
        }
        public void Check_UpdateActivityCommandHandler_Succeed()
        {
            var description        = "Given Description";
            var id                 = 1u;
            var projectId          = 1u;
            var dispatcher         = new DomainEventDispatcher();
            var taskOptionsBuilder = new DbContextOptionsBuilder <ActivityDbContext>();

            taskOptionsBuilder.UseSqlite("Data Source=todoagility_cqrs_test.db;");
            var taskDbContext = new ActivityDbContext(taskOptionsBuilder.Options);
            var repTask       = new ActivityRepository(taskDbContext);

            using var taskDbSession = new DbSession <IActivityRepository>(taskDbContext, repTask);

            var project      = Project.From(EntityId.From(projectId), Description.From(description));
            var originalTask = Activity.From(Description.From(description), EntityId.From(id),
                                             EntityId.From(projectId), ActivityStatus.From(1));

            taskDbSession.Repository.AddProject(project);
            taskDbSession.Repository.Add(originalTask);
            taskDbSession.SaveChanges();

            var descriptionNew = "Given Description Changed";
            var command        = new UpdateActivityCommand(id, descriptionNew);

            var handler = new UpdateActivityCommandHandler(taskDbSession, dispatcher);

            handler.Execute(command);

            var task = taskDbSession.Repository.Get(EntityId.From(id));

            Assert.NotEqual(task, originalTask);
        }
Example #4
0
        public void Check_ActivityRespository_Update()
        {
            //given
            var descriptionText        = "Given Description";
            var descriptionTextChanged = "Given Description Modificada";
            var project = ProjectReference.From(EntityId.From(1u), Description.From(descriptionText));

            var id = EntityId.From(1u);

            var task = Activity.From(Description.From(descriptionText), id,
                                     EntityId.From(1u), ActivityStatus.From(1));

            //when
            var taskOptionsBuilder = new DbContextOptionsBuilder <ActivityDbContext>();

            taskOptionsBuilder.UseSqlite("Data Source=todoagility_repo_update_test.db;");
            var taskDbContext = new ActivityDbContext(taskOptionsBuilder.Options);
            var repTask       = new ActivityRepository(taskDbContext);

            using var taskDbSession = new ActivityDbSession(taskDbContext, repTask);
            taskDbSession.Repository.Add(task);
            taskDbSession.SaveChanges();

            //then
            var taskSaved  = taskDbSession.Repository.Get(id);
            var updatetask = Activity.CombineWithPatch(taskSaved,
                                                       Activity.Patch.FromDescription(Description.From(descriptionTextChanged)));

            taskDbSession.Repository.Add(updatetask);
            taskDbSession.SaveChanges();

            var taskUpdated = taskDbSession.Repository.Get(id);

            Assert.NotEqual(taskUpdated, task);
        }
        public ActivityProvider(ActivityDbContext dataBase,
                                ILogger <ActivityProvider> logger,
                                IMapper mapper)
        {
            this.dataBase = dataBase;
            this.logger   = logger;
            this.mapper   = mapper;

            Seed();
        }
Example #6
0
        public async Task SeedAsync(ActivityDbContext context, ILogger <ActivityDbContextSeed> logger)
        {
            var policy = CreatePolicy(logger, nameof(ActivityDbContextSeed));

            await policy.ExecuteAsync(async() =>
            {
                using (context)
                {
                    context.Database.Migrate();

                    if (!context.ActivityStatuses.Any())
                    {
                        context.ActivityStatuses.AddRange(ActivityStatus.List());
                    }

                    await context.SaveChangesAsync();
                }
            });
        }
Example #7
0
        public static async Task DispatchDomainEventsAsync(this IMediator mediator, ActivityDbContext ctx)
        {
            var domainEntities = ctx.ChangeTracker
                                 .Entries <Entity>()
                                 .Where(x => x.Entity.DomainEvents != null && x.Entity.DomainEvents.Any());

            var domainEvents = domainEntities
                               .SelectMany(x => x.Entity.DomainEvents)
                               .ToList();

            domainEntities.ToList()
            .ForEach(entity => entity.Entity.ClearDomainEvents());

            var tasks = domainEvents
                        .Select(async(domainEvent) => {
                await mediator.Publish(domainEvent);
            });

            await Task.WhenAll(tasks);
        }
Example #8
0
        public void Add(IOperationDuration operationDuration)
        {
            if (operationDuration == null)
            {
                throw new System.ArgumentNullException(nameof(operationDuration));
            }

            using (ActivityDbContext db = new ActivityDbContext())
            {
                var durationEntity = new OperationDuration
                {
                    Action   = operationDuration.Action,
                    Level    = operationDuration.Level,
                    Duration = operationDuration.Duration
                };

                db.OperationDurations.Add(durationEntity);

                db.SaveChanges();
            }
        }
        public void Check_AddActivityCommandHandler_Succeed()
        {
            var description        = "Given Description";
            var projectId          = 1u;
            var dispatcher         = new DomainEventDispatcher();
            var taskOptionsBuilder = new DbContextOptionsBuilder <ActivityDbContext>();

            taskOptionsBuilder.UseSqlite("Data Source=todoagility_add_test.db;");
            var taskDbContext = new ActivityDbContext(taskOptionsBuilder.Options);
            var repTask       = new ActivityRepository(taskDbContext);

            using var taskDbSession = new DbSession <IActivityRepository>(taskDbContext, repTask);
            taskDbSession.Repository.AddProject(Project.From(EntityId.From(projectId), Description.From(description)));
            taskDbSession.SaveChanges();

            var handler = new AddActivityCommandHandler(dispatcher, taskDbSession);
            var command = new AddActivityCommand(description, projectId);

            handler.Execute(command);

            var task = taskDbSession.Repository.Find(a => a.ProjectId == projectId);

            Assert.NotNull(task);
        }
Example #10
0
 public MenuBuilder(ActivityDbContext context)
 {
     _context = context;
 }
 public DefaultTenantRoleAndUserBuilder(ActivityDbContext context)
 {
     _context = context;
 }
Example #12
0
 public PostService(ActivityDbContext context)
 {
     _context = context;
 }
Example #13
0
 public EfRequestManager(ActivityDbContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }
Example #14
0
 public ActivityRepository(ActivityDbContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }
Example #15
0
 public MainRepository(ActivityDbContext context)
 {
     _context = context;
     _context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
 }
 public ActivityDbSession(ActivityDbContext context, ActivityRepository repository)
     : base(context, repository)
 {
 }
 public InitialDataBuilder(ActivityDbContext context)
 {
     _context = context;
 }
 public TechnologyRepository(ActivityDbContext context) : base(context)
 {
 }
Example #19
0
 public InitialDataBuilder(ActivityDbContext context)
 {
     _context = context;
 }
Example #20
0
 public CategoryRepository(ActivityDbContext dbContext)
 {
     _dbContext = dbContext;
 }
 public PhotoRepository(ActivityDbContext activityDbContext)
 {
     _activityDbContext = activityDbContext;
 }
 public ActivityRepository(ActivityDbContext context) : base(context)
 {
 }
Example #23
0
 public UserService(ActivityDbContext context)
 {
     _context = context;
 }
 public DefaultTenantRoleAndUserBuilder(ActivityDbContext context)
 {
     _context = context;
 }
Example #25
0
 public ActivityRepository(ActivityDbContext activityDbContext)
 {
     _activityDbContext = activityDbContext;
 }
Example #26
0
 public CollectionRepository(ActivityDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Example #27
0
 public MenuBuilder(ActivityDbContext context)
 {
     _context = context;
 }
Example #28
0
 public CustomAuthorize(ActivityDbContext context, ILogger <CustomAuthorize> logger)
 {
     _context = context;
     _logger  = logger;
 }