public void EmployeesLoad_StolenskyGok()
        {
            var navigation          = Substitute.For <INavigationManager>();
            var interactive         = Substitute.For <IInteractiveMessage>();
            var progressStep        = Substitute.For <IProgressBarDisplayable>();
            var progressInterceptor = Substitute.For <ProgressInterceptor>();
            var dataparser          = new DataParserEmployee(new PersonNames(), new SizeService(), new PhoneFormatter(PhoneFormat.RussiaOnlyHyphenated));
            var setting             = new SettingsMatchEmployeesViewModel();
            var model = new ImportModelEmployee(dataparser, setting);

            using (var employeesLoad = new ExcelImportViewModel(model, UnitOfWorkFactory, navigation, interactive, progressInterceptor)) {
                employeesLoad.ProgressStep = progressStep;
                employeesLoad.FileName     = "Samples/Excel/cardkey_list.xlsx";
                Assert.That(employeesLoad.Sheets.Count, Is.GreaterThan(0));
                employeesLoad.SelectedSheet = employeesLoad.Sheets.First();
                Assert.That(employeesLoad.SensitiveSecondStepButton, Is.True, "Кнопка второго шага должна быть доступна");
                employeesLoad.SecondStep();
                Assert.That(employeesLoad.SensitiveThirdStepButton, Is.True, "Кнопка третьего шага должна быть доступна");
                employeesLoad.ThirdStep();
                Assert.That(employeesLoad.SensitiveSaveButton, Is.True, "Кнопка сохранить должна быть доступна");
                employeesLoad.Save();

                var uow       = employeesLoad.UoW;
                var employees = uow.GetAll <EmployeeCard>().ToList();
                Assert.That(employees.Count, Is.EqualTo(9));
                var sergey = employees.First(x => x.PersonnelNumber == "58391");
                Assert.That(sergey.CardKey, Is.EqualTo("80313E3A538A04"));
                Assert.That(sergey.LastName, Is.EqualTo("Волчихин"));
                Assert.That(sergey.FirstName, Is.EqualTo("Сергей"));
                Assert.That(sergey.Patronymic, Is.EqualTo("Владимирович"));
                Assert.That(sergey.Sex, Is.EqualTo(Sex.M));
            }
        }
        public void EmployeesLoad_osmbtDepartments()
        {
            NewSessionWithSameDB();
            var navigation          = Substitute.For <INavigationManager>();
            var interactive         = Substitute.For <IInteractiveMessage>();
            var progressStep        = Substitute.For <IProgressBarDisplayable>();
            var progressInterceptor = Substitute.For <ProgressInterceptor>();
            var dataparser          = new DataParserEmployee(new PersonNames(), new SizeService(), new PhoneFormatter(PhoneFormat.RussiaOnlyHyphenated));
            var setting             = new SettingsMatchEmployeesViewModel();

            //Так же проверяем что табельные номера вида 00002 превратятся в "2"
            setting.ConvertPersonnelNumber = true;
            var model = new ImportModelEmployee(dataparser, setting);

            using (var rootUow = UnitOfWorkFactory.CreateWithoutRoot())
            {
                var existEmployee = new EmployeeCard
                {
                    PersonnelNumber = "5213",
                    LastName        = "Старая фамилия",
                    FirstName       = "Старое имя",
                    Comment         = "Старый комментарий"
                };
                rootUow.Save(existEmployee);
                rootUow.Commit();

                using (var employeesLoad = new ExcelImportViewModel(model, UnitOfWorkFactory, navigation, interactive, progressInterceptor)) {
                    var uow          = employeesLoad.UoW;
                    var employeesold = uow.GetAll <EmployeeCard>().ToList();
                    Assert.That(employeesold.Count, Is.EqualTo(1));

                    employeesLoad.ProgressStep = progressStep;
                    employeesLoad.FileName     = "Samples/Excel/osmbt.xls";
                    Assert.That(employeesLoad.Sheets.Count, Is.GreaterThan(0));
                    employeesLoad.SelectedSheet = employeesLoad.Sheets.First();
                    Assert.That(employeesLoad.SensitiveSecondStepButton, Is.True, "Кнопка второго шага должна быть доступна");
                    employeesLoad.SecondStep();
                    Assert.That(employeesLoad.SensitiveThirdStepButton, Is.True, "Кнопка третьего шага должна быть доступна");
                    employeesLoad.ThirdStep();
                    Assert.That(employeesLoad.SensitiveSaveButton, Is.True, "Кнопка сохранить должна быть доступна");
                    employeesLoad.Save();

                    var employees = uow.GetAll <EmployeeCard>().ToList();
                    Assert.That(employees.Count, Is.EqualTo(2));
                    var artem = employees.First(x => x.PersonnelNumber == "5213");
                    Assert.That(artem.FirstName, Is.EqualTo("Артем"));
                    Assert.That(artem.LastName, Is.EqualTo("Беляев"));
                    Assert.That(artem.Comment, Is.EqualTo("Старый комментарий"));                     //Фамилия и имя заменились, комментарий остался старым.
                    Assert.That(artem.Subdivision.Name, Is.EqualTo("500100 Цех керамического кирпича"));
                    Assert.That(artem.Department.Name, Is.EqualTo("Участок Е1 Бригада 7  (Е1)"));

                    //Проверяем что не дублируем должности и подразделения.
                    var igor = employees.First(x => x.PersonnelNumber == "4103");
                    Assert.That(igor.Subdivision.Name, Is.EqualTo("500100 Цех керамического кирпича"));
                    Assert.That(igor.Post.Name, Is.EqualTo("Заведующий хозяйством"));
                    Assert.That(igor.Department.Name, Is.EqualTo("Участок 500100"));
                }
            }
        }
        public void EmployeesLoad_Vostok1c()
        {
            //В файле дата хранится в виде строки, поэтому для прохождения теста, нужна русская культура
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("ru-RU");
            var navigation          = Substitute.For <INavigationManager>();
            var interactive         = Substitute.For <IInteractiveMessage>();
            var progressStep        = Substitute.For <IProgressBarDisplayable>();
            var progressInterceptor = Substitute.For <ProgressInterceptor>();
            var dataparser          = new DataParserEmployee(new PersonNames(), new SizeService(), new PhoneFormatter(PhoneFormat.RussiaOnlyHyphenated));
            var setting             = new SettingsMatchEmployeesViewModel();

            //Так же проверяем что табельные номера вида 00002 превратятся в "2"
            setting.ConvertPersonnelNumber = true;
            var model = new ImportModelEmployee(dataparser, setting);

            using (var employeesLoad = new ExcelImportViewModel(model, UnitOfWorkFactory, navigation, interactive, progressInterceptor)) {
                employeesLoad.ProgressStep = progressStep;
                employeesLoad.FileName     = "Samples/Excel/vostok_1c_employee.xls";
                Assert.That(employeesLoad.Sheets.Count, Is.GreaterThan(0));
                employeesLoad.SelectedSheet = employeesLoad.Sheets.First();
                Assert.That(employeesLoad.SensitiveSecondStepButton, Is.True, "Кнопка второго шага должна быть доступна");
                employeesLoad.SecondStep();
                Assert.That(employeesLoad.SensitiveThirdStepButton, Is.True, "Кнопка третьего шага должна быть доступна");
                employeesLoad.ThirdStep();
                Assert.That(employeesLoad.SensitiveSaveButton, Is.True, "Кнопка сохранить должна быть доступна");
                employeesLoad.Save();

                var uow       = employeesLoad.UoW;
                var employees = uow.GetAll <EmployeeCard>().ToList();
                Assert.That(employees.Count, Is.EqualTo(4));
                var olga = employees.First(x => x.PersonnelNumber == "1");
                Assert.That(olga.LastName, Is.EqualTo("Гриднева"));
                Assert.That(olga.FirstName, Is.EqualTo("Ольга"));
                Assert.That(olga.Patronymic, Is.EqualTo("Николаевна"));
                Assert.That(olga.HireDate, Is.EqualTo(new DateTime(2020, 3, 10)));
                Assert.That(olga.Sex, Is.EqualTo(Sex.F));
                Assert.That(olga.Subdivision.Name, Is.EqualTo("500006 Отдел главного энергетика"));
                Assert.That(olga.Post.Name, Is.EqualTo("Ведущий инженер"));
                Assert.That(olga.Post.Subdivision.Name, Is.EqualTo("500006 Отдел главного энергетика"));

                //Проверяем что должности из разных подразделений не сливаются.
                var natalia = employees.First(x => x.PersonnelNumber == "2");
                Assert.That(natalia.Subdivision.Name, Is.EqualTo("500007 Отдел главного механика"));
                Assert.That(natalia.Post.Name, Is.EqualTo("Ведущий инженер"));
                Assert.That(natalia.Post.Subdivision.Name, Is.EqualTo("500007 Отдел главного механика"));

                //Проверяем что не дублируем должности и подразделения.
                var igor = employees.First(x => x.PersonnelNumber == "3");
                var ury  = employees.First(x => x.PersonnelNumber == "5");
                Assert.That(igor.Subdivision.Name, Is.EqualTo("500300 Цех санитарных керамических изделий"));
                Assert.That(igor.Post.Name, Is.EqualTo("Изготовитель капов (из эпоксидной смолы)."));
                Assert.That(igor.Post.Subdivision.Name, Is.EqualTo("500300 Цех санитарных керамических изделий"));
                Assert.That(igor.Subdivision.Id, Is.EqualTo(ury.Subdivision.Id));
                Assert.That(igor.Post.Id, Is.EqualTo(ury.Post.Id));
                Assert.That(igor.Post.Subdivision.Id, Is.EqualTo(ury.Post.Subdivision.Id));
            }
        }
        public void EmployeesLoad_DateWorks()
        {
            var navigation          = Substitute.For <INavigationManager>();
            var interactive         = Substitute.For <IInteractiveMessage>();
            var progressStep        = Substitute.For <IProgressBarDisplayable>();
            var progressInterceptor = Substitute.For <ProgressInterceptor>();
            var dataparser          = new DataParserEmployee(new PersonNames(), new SizeService(), new PhoneFormatter(PhoneFormat.RussiaOnlyHyphenated));
            var setting             = new SettingsMatchEmployeesViewModel();
            var model = new ImportModelEmployee(dataparser, setting);

            using (var employeesLoad = new ExcelImportViewModel(model, UnitOfWorkFactory, navigation, interactive, progressInterceptor)) {
                var importModel = employeesLoad.ImportModel as ImportModelEmployee;
                employeesLoad.ProgressStep = progressStep;
                employeesLoad.FileName     = "Samples/Excel/dismissed_employees.xls";
                Assert.That(employeesLoad.Sheets.Count, Is.GreaterThan(0));
                employeesLoad.SelectedSheet = employeesLoad.Sheets.First();
                Assert.That(employeesLoad.SensitiveSecondStepButton, Is.True, "Кнопка второго шага должна быть доступна");
                employeesLoad.SecondStep();
                importModel.Columns[1].DataType = DataTypeEmployee.DismissDate;                 //Вторая колонка дата увольнения.
                Assert.That(employeesLoad.SensitiveThirdStepButton, Is.True, "Кнопка третьего шага должна быть доступна");
                employeesLoad.ThirdStep();
                Assert.That(employeesLoad.SensitiveSaveButton, Is.True, "Кнопка сохранить должна быть доступна");
                employeesLoad.Save();

                var uow       = employeesLoad.UoW;
                var employees = uow.GetAll <EmployeeCard>().ToList();

                Assert.That(employees.Count, Is.EqualTo(2));
                var anastasia = employees.First(x => x.FirstName == "Анастасия");
                Assert.That(anastasia.LastName, Is.EqualTo("Устинова"));
                Assert.That(anastasia.Patronymic, Is.EqualTo("Владимировна"));
                Assert.That(anastasia.HireDate, Is.EqualTo(new DateTime(2006, 4, 4)));
                Assert.That(anastasia.Sex, Is.EqualTo(Sex.F));
                Assert.That(anastasia.DismissDate, Is.EqualTo(new DateTime(2021, 3, 31)));

                var natalia = employees.First(x => x.FirstName == "Наталья");
                Assert.That(natalia.HireDate, Is.EqualTo(new DateTime(2020, 12, 11)));
                Assert.That(natalia.Sex, Is.EqualTo(Sex.F));
                Assert.That(natalia.DismissDate, Is.EqualTo(new DateTime(2021, 1, 13)));
            }
        }
        public void EmployeesLoad_EmptyRows_Sizes_A2Case()
        {
            var navigation          = Substitute.For <INavigationManager>();
            var interactive         = Substitute.For <IInteractiveMessage>();
            var progressStep        = Substitute.For <IProgressBarDisplayable>();
            var progressInterceptor = Substitute.For <ProgressInterceptor>();
            var dataParser          = new DataParserEmployee(new PersonNames(), new SizeService(), new PhoneFormatter(PhoneFormat.RussiaOnlyHyphenated));
            var setting             = new SettingsMatchEmployeesViewModel();
            var model = new ImportModelEmployee(dataParser, setting);

            using (var employeesLoad = new ExcelImportViewModel(model, UnitOfWorkFactory, navigation, interactive, progressInterceptor))
            {
                var uow        = employeesLoad.UoW;
                var heightType = new SizeType
                {
                    Name = "РостТип", Position = 1, UseInEmployee = true, CategorySizeType = CategorySizeType.Height
                };
                uow.Save(heightType);
                var sizeType = new SizeType
                {
                    Name = "РазмерТип", Position = 2, CategorySizeType = CategorySizeType.Size, UseInEmployee = true
                };
                uow.Save(sizeType);
                var shoesType = new SizeType
                {
                    Name = "ОбувьТип", Position = 3, CategorySizeType = CategorySizeType.Size, UseInEmployee = true
                };
                uow.Save(shoesType);
                var height = new Size {
                    Name = "170-176", SizeType = heightType, UseInEmployee = true
                };
                uow.Save(height);
                var size = new Size {
                    Name = "48-50", SizeType = sizeType, UseInEmployee = true
                };
                uow.Save(size);
                var shoes = new Size {
                    Name = "38", SizeType = shoesType, UseInEmployee = true
                };
                uow.Save(shoes);
                uow.Commit();

                employeesLoad.ProgressStep = progressStep;
                employeesLoad.FileName     = "Samples/Excel/empty_first_row_a2.xls";
                Assert.That(employeesLoad.Sheets.Count, Is.GreaterThan(0));
                employeesLoad.SelectedSheet = employeesLoad.Sheets.First();
                Assert.That(employeesLoad.SensitiveSecondStepButton, Is.True, "Кнопка второго шага должна быть доступна");
                employeesLoad.SecondStep();
                Assert.That(employeesLoad.SensitiveThirdStepButton, Is.True, "Кнопка третьего шага должна быть доступна");
                employeesLoad.ThirdStep();
                Assert.That(employeesLoad.SensitiveSaveButton, Is.True, "Кнопка сохранить должна быть доступна");
                employeesLoad.Save();
                uow.Commit();

                var employees = uow.GetAll <EmployeeCard>().ToList();

                Assert.That(employees.Count, Is.EqualTo(5));
                var nikolay = employees.First(x => x.FirstName == "Николай");
                Assert.That(nikolay.Sizes.FirstOrDefault(x => x.SizeType == heightType)?.Size?.Id, Is.EqualTo(height.Id));
                Assert.That(nikolay.Sizes.FirstOrDefault(x => x.SizeType == sizeType)?.Size?.Id, Is.EqualTo(size.Id));
                Assert.That(nikolay.Sizes.FirstOrDefault(x => x.SizeType == shoesType)?.Size?.Id, Is.EqualTo(shoes.Id));

                //Проверяем что должности не задублировались
                var posts = uow.GetAll <Post>();
                Assert.That(posts.Count, Is.EqualTo(3));
            }
        }