public async Task TwoContexts()
        {
            using (var context = new WorkSpeedDbContext()) {
                context.Database.Migrate();
            }

            using (var context1 = new WorkSpeedDbContext()) {
                using (var context2 = new WorkSpeedDbContext()) {
                    // create

                    var employee = new Employee {
                        Id = "AR00001", Name = "Test Employee", IsActive = true
                    };
                    context1.Add(employee);
                    context1.SaveChanges();

                    foreach (var entityEntry in context2.ChangeTracker.Entries <Employee>())
                    {
                        entityEntry.Reload();
                    }

                    var empl = context2.Employees.ToArray();
                    Assert.That(empl[0].Name, Is.EqualTo(employee.Name));
                    Assert.That(empl.Length, Is.EqualTo(1));


                    // update
                    var newName = "John Doe";

                    employee      = context1.Employees.ToArray()[0];
                    employee.Name = newName;
                    context1.SaveChanges();

                    employee = new Employee {
                        Id = "AR00002", Name = "Test Employee", IsActive = true
                    };
                    context1.Add(employee);
                    context1.SaveChanges();

                    var employees = context1.Employees.ToArray();
                    Assert.That(employees.Length, Is.EqualTo(2));


                    foreach (var entityEntry in context2.ChangeTracker.Entries <Employee>())
                    {
                        await entityEntry.ReloadAsync();
                    }

                    empl = context2.Employees.ToArray();
                    Assert.That(empl[0].Name, Is.EqualTo(newName));
                    Assert.That(empl.Length, Is.EqualTo(2));
                }
            }
        }
Beispiel #2
0
        public static (ImportService, ReportService) Create()
        {
            var typeRepo = GetTypeRepository();

            var context = new WorkSpeedDbContext();

            context.Database.Migrate();

            var importService = new ImportService(context, typeRepo);

            var builder       = new ProductivityBuilder();
            var reportService = new ReportService(new WorkSpeedDbContext(), builder);

            return(importService, reportService);
        }
Beispiel #3
0
        private FakeImportService GetFakeImportService()
        {
            _connection = new SqliteConnection("DataSource=:memory:");
            _connection.Open();

            var options   = new DbContextOptionsBuilder <WorkSpeedDbContext>().UseSqlite(_connection).Options;
            var dbContext = new WorkSpeedDbContext(options);

            dbContext.Database.EnsureCreated();

            var stubITypeRepository = new Mock <ITypeRepository>();

            var importServise = new FakeImportService(dbContext, stubITypeRepository.Object);

            return(importServise);
        }
Beispiel #4
0
        private ReportService GetReportService(bool fillEmployees = true)
        {
            _connection = new SqliteConnection("DataSource=:memory:");
            _connection.Open();

            var options = new DbContextOptionsBuilder <WorkSpeedDbContext>().UseSqlite(_connection).Options;

            using (var dbContext = new WorkSpeedDbContext(options)) {
                dbContext.Database.EnsureCreated();

                if (fillEmployees)
                {
                    var shifts       = dbContext.Shifts.ToArray();
                    var appointments = dbContext.Appointments.ToArray();
                    var positions    = dbContext.Positions.ToArray();

                    dbContext.Employees.AddRange(new Employee[] {
                        new Employee {
                            Id = "AR00001", Name = "Mnager", IsActive = true, Shift = shifts[0], Appointment = appointments[7], Position = positions[0]
                        },
                        new Employee {
                            Id = "AR00002", Name = "Manager Assistant 1", IsActive = true, Shift = shifts[0], Appointment = appointments[6], Position = positions[1]
                        },
                        new Employee {
                            Id = "AR00003", Name = "Manager Assistant 2", IsActive = true, Shift = shifts[0], Appointment = appointments[5], Position = positions[2]
                        },
                        new Employee {
                            Id = "AR00004", Name = "Principal Warehouseman 1", IsActive = true, Shift = shifts[0], Appointment = appointments[4], Position = positions[1]
                        },
                        new Employee {
                            Id = "AR00005", Name = "Principal Warehouseman 2", IsActive = true, Shift = shifts[0], Appointment = appointments[4], Position = positions[2]
                        },
                        new Employee {
                            Id = "AR00006", Name = "Principal Warehouseman 3", IsActive = true, Shift = shifts[1], Appointment = appointments[4], Position = positions[1]
                        },
                    });

                    dbContext.SaveChanges();
                }
            };
            var stub = new Mock <IProductivityBuilder>();

            var reportService = new ReportService(new WorkSpeedDbContext(options), stub.Object);

            return(reportService);
        }
Beispiel #5
0
        private FakeReportService GetFakeRaportService( )
        {
            _connection = new SqliteConnection("DataSource=:memory:");
            _connection.Open();

            var options = new DbContextOptionsBuilder <WorkSpeedDbContext>().UseSqlite(_connection).Options;

            using (var dbContext = new WorkSpeedDbContext(options)) {
                dbContext.Database.EnsureCreated();
            }


            var reportService = new FakeReportService(new WorkSpeedDbContext(options), new ProductivityBuilder());

            reportService.ReloadAllCollections();
            _operations = reportService.OperationCollection.ToArray();

            return(reportService);
        }
        GetShiftGrouping(this WorkSpeedDbContext dbContext)
        {
            foreach (var entityEntry in dbContext.ChangeTracker.Entries <Employee>())
            {
                entityEntry.Reload();
            }

            var employees = dbContext.Employees.Include(e => e.Avatar).ToArray();

            var query = (from e in employees
                         group e by e.Shift
                         into s
                         select new
            {
                Shift = s.Key,
                Appointments = from e in s
                               group e by e.Appointment
                               into a
                               select new
                {
                    Appointment = a.Key,
                    Positions = from e in a
                                group e by e.Position
                                into p
                                select new
                    {
                        Position = p.Key,
                        Employees = p
                    }
                }
            }).AsQueryable();

            return(query.AsEnumerable().Select(s => (
                                                   s.Shift,
                                                   s.Appointments?.Select(a =>
                                                                          (a.Appointment,
                                                                           a.Positions.Select(p =>
                                                                                              (p.Position, p.Employees?.ToArray())).ToArray())).ToArray()
                                                   )));
        }
Beispiel #7
0
        public ReportService(WorkSpeedDbContext dbContext, IProductivityBuilder builder) : base(dbContext)
        {
            _productivityBuilder = builder;

            CreateCollections();


            void CreateCollections()
            {
                _employeeProductivityCollections = new ObservableCollection <EmployeeProductivity>();
                EmployeeProductivityCollections  = new ReadOnlyObservableCollection <EmployeeProductivity>(_employeeProductivityCollections);

                _shiftGroupingCollection = new ObservableCollection <ShiftGrouping>();
                ShiftGroupingCollection  = new ReadOnlyObservableCollection <ShiftGrouping>(_shiftGroupingCollection);

                _appointmentCollection = new ObservableCollection <Appointment>();
                AppointmentCollection  = new ReadOnlyObservableCollection <Appointment>(_appointmentCollection);

                _rankCollection = new ObservableCollection <Rank>();
                RankCollection  = new ReadOnlyObservableCollection <Rank>(_rankCollection);

                _positionCollection = new ObservableCollection <Position>();
                PositionCollection  = new ReadOnlyObservableCollection <Position>(_positionCollection);

                _shiftCollection = new ObservableCollection <Shift>();
                ShiftCollection  = new ReadOnlyObservableCollection <Shift>(_shiftCollection);

                _shortBreakCollection = new ObservableCollection <ShortBreakSchedule>();
                ShortBreakCollection  = new ReadOnlyObservableCollection <ShortBreakSchedule>(_shortBreakCollection);

                _operationCollection = new ObservableCollection <Operation>();
                OperationCollection  = new ReadOnlyObservableCollection <Operation>(_operationCollection);

                _categoryCollection = new ObservableCollection <Category>();
                CategoryCollection  = new ReadOnlyObservableCollection <Category>(_categoryCollection);
            }
        }
 public static IQueryable <ShortBreakSchedule> GetShortBreakSchedules(this WorkSpeedDbContext dbContext)
 => dbContext.ShortBreakSchedules.AsQueryable();
 public static IEnumerable <Category> GetCategories(this WorkSpeedDbContext dbContext)
 => dbContext.CategorySets.Include(c => c.CategoryCategorySets).ThenInclude(ccs => ccs.Category).First().CategoryCategorySets.Select(ccs => ccs.Category);
 public static Position GetDefaultPosition(this WorkSpeedDbContext dbContext)
 => dbContext.Positions.First(s => s.Id == 1);
 public static IQueryable <Shift> GetShifts(this WorkSpeedDbContext dbContext)
 => dbContext.Shifts.AsQueryable();
Beispiel #12
0
 public WarehouseService()
 {
     _dbContext = new WorkSpeedDbContext();
 }
Beispiel #13
0
 public FakeImportService(WorkSpeedDbContext dbContext, ITypeRepository typeRepository) : base(dbContext, typeRepository)
 {
 }
 public static IQueryable <Operation> GetOperations(this WorkSpeedDbContext dbContext, ISet <OperationGroups> group)
 => dbContext.Operations.Where(o => group.Contains(o.Group)).AsQueryable();
 public static IQueryable <Employee> GetInactiveEmployees(this WorkSpeedDbContext dbContext)
 => dbContext.Employees.Include(e => e.Shift).Include(e => e.Appointment).Include(e => e.Position).Where(e => !e.IsActive).AsQueryable();
 public static ShortBreakSchedule GetDefaultShortBreakSchedule(this WorkSpeedDbContext dbContext)
 => dbContext.ShortBreakSchedules.First(s => s.Id == 1);
 public static Avatar GetDefaultAvatar(this WorkSpeedDbContext dbContext)
 => dbContext.Avatars.First(a => a.Id == 1);
 public static Shift  GetDefaultShift(this WorkSpeedDbContext dbContext)
 => dbContext.Shifts.First(s => s.Id == 1);
 public static Appointment  GetDefaultAppointment(this WorkSpeedDbContext dbContext)
 => dbContext.Appointments.First(s => s.Id == 1);
 public static Rank GetDefaultRank(this WorkSpeedDbContext dbContext)
 => dbContext.Ranks.First(s => s.Number == 3);
Beispiel #21
0
 public Service(WorkSpeedDbContext dbContext)
 {
     _dbContext = dbContext;
 }
 public void CanCreateDatabase()
 {
     using (var context = new WorkSpeedDbContext()) {
         context.Database.Migrate();
     }
 }
 public static IQueryable <Operation> GetOperations(this WorkSpeedDbContext dbContext)
 => dbContext.Operations.AsQueryable();
 public static IQueryable <Address> GetAddresses(this WorkSpeedDbContext dbContext)
 => dbContext.Addresses.AsQueryable();
        public static IEnumerable <IGrouping <Employee, EmployeeActionBase> > GetEmployeeActions(this WorkSpeedDbContext dbContext, DateTime start, DateTime end)
        {
            foreach (var entityEntry in dbContext.ChangeTracker.Entries <Employee>())
            {
                entityEntry.Reload();
            }

            foreach (var entityEntry in dbContext.ChangeTracker.Entries <Product>())
            {
                entityEntry.Reload();
            }


            var doubleAddressActions = dbContext.DoubleAddressActions
                                       .Include(a => a.Employee)
                                       .ThenInclude(e => e.Avatar)
                                       .Include(a => a.Operation)
                                       .Include(a => a.DoubleAddressDetails)
                                       .ThenInclude(d => d.Product)
                                       .Where(a => a.StartTime >= start && a.StartTime <end && a.Duration> TimeSpan.Zero)
                                       .AsQueryable();

            var receptionActions = dbContext.ReceptionActions
                                   .Include(a => a.Employee)
                                   .ThenInclude(e => e.Avatar)
                                   .Include(a => a.Operation)
                                   .Include(a => a.ReceptionActionDetails)
                                   .ThenInclude(d => d.Product)
                                   .Where(a => a.StartTime >= start && a.StartTime <end && a.Duration> TimeSpan.Zero)
                                   .AsQueryable();

            var inventoryActions = dbContext.InventoryActions
                                   .Include(a => a.Employee)
                                   .ThenInclude(e => e.Avatar)
                                   .Include(a => a.Operation)
                                   .Include(a => a.InventoryActionDetails)
                                   .ThenInclude(d => d.Product)
                                   .Where(a => a.StartTime >= start && a.StartTime <end && a.Duration> TimeSpan.Zero)
                                   .AsQueryable();

            var shipmentActions = dbContext.ShipmentActions
                                  .Include(a => a.Employee)
                                  .ThenInclude(e => e.Avatar)
                                  .Include(a => a.Operation)
                                  .Where(a => a.StartTime >= start && a.StartTime <end && a.Duration> TimeSpan.Zero)
                                  .AsQueryable();

            var otherActions = dbContext.OtherActions
                               .Include(a => a.Employee)
                               .ThenInclude(e => e.Avatar)
                               .Include(a => a.Operation)
                               .Where(a => a.StartTime >= start && a.StartTime <end && a.Duration> TimeSpan.Zero)
                               .AsQueryable();

            var set = new HashSet <EmployeeActionBase>();

            set.UnionWith(doubleAddressActions);
            set.UnionWith(receptionActions);
            set.UnionWith(inventoryActions);
            set.UnionWith(shipmentActions);
            set.UnionWith(otherActions);

            return(set.OrderByDescending(s => s.StartTime).GroupBy(s => s.Employee));
        }
 public static IQueryable <OtherAction> GetOtherActions(this WorkSpeedDbContext dbContext, DateTime periodStart, DateTime periodEnd)
 => dbContext.OtherActions.Where(a => a.StartTime >= periodStart && a.StartTime <= periodEnd);
Beispiel #27
0
 public ProductivityService()
 {
     _context = new WorkSpeedDbContext();
 }
 public static IQueryable <Product> GetProducts(this WorkSpeedDbContext dbContext)
 => dbContext.Products.AsQueryable();
 public static IQueryable <Operation> GetOperations(this WorkSpeedDbContext dbContext, OperationGroups group)
 => dbContext.Operations.Where(o => o.Group == group).AsQueryable();
 public static IQueryable <Employee> GetEmployees(this WorkSpeedDbContext dbContext)
 => dbContext.Employees.AsQueryable();