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);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
                }
            });
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 10
0
 public MenuBuilder(ActivityDbContext context)
 {
     _context = context;
 }
 public DefaultTenantRoleAndUserBuilder(ActivityDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 12
0
 public PostService(ActivityDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 13
0
 public EfRequestManager(ActivityDbContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }
Ejemplo n.º 14
0
 public ActivityRepository(ActivityDbContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }
Ejemplo n.º 15
0
 public MainRepository(ActivityDbContext context)
 {
     _context = context;
     _context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
 }
Ejemplo n.º 16
0
 public ActivityDbSession(ActivityDbContext context, ActivityRepository repository)
     : base(context, repository)
 {
 }
Ejemplo n.º 17
0
 public InitialDataBuilder(ActivityDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 18
0
 public TechnologyRepository(ActivityDbContext context) : base(context)
 {
 }
Ejemplo n.º 19
0
 public InitialDataBuilder(ActivityDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 20
0
 public CategoryRepository(ActivityDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Ejemplo n.º 21
0
 public PhotoRepository(ActivityDbContext activityDbContext)
 {
     _activityDbContext = activityDbContext;
 }
Ejemplo n.º 22
0
 public ActivityRepository(ActivityDbContext context) : base(context)
 {
 }
Ejemplo n.º 23
0
 public UserService(ActivityDbContext context)
 {
     _context = context;
 }
 public DefaultTenantRoleAndUserBuilder(ActivityDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 25
0
 public ActivityRepository(ActivityDbContext activityDbContext)
 {
     _activityDbContext = activityDbContext;
 }
Ejemplo n.º 26
0
 public CollectionRepository(ActivityDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Ejemplo n.º 27
0
 public MenuBuilder(ActivityDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 28
0
 public CustomAuthorize(ActivityDbContext context, ILogger <CustomAuthorize> logger)
 {
     _context = context;
     _logger  = logger;
 }