示例#1
0
 public WelderViewType()
 {
    this.welder = new Welder();
    this.welder.IsActive = true;
    CheckName();
    CheckCertificate();
 }
        private bool SeedOptional()
        {
            //Required seed hasn't been performed for Master worksration type, but data are used in optional seed
            if (viewModel.Project.WorkstationType == WorkstationType.Master)
            {
                SeedRequired();
            }

            firstSetupRepo.BeginTransaction();
            #region PlateManufacturers
            PlateManufacturer[] plateManufacturers = 
            {
                new PlateManufacturer {Name = "Алапаевский металлургический завод", IsActive = true, IsNative = true, Project = viewModel.Project},
                new PlateManufacturer {Name = "Альметьевский трубный завод", IsActive = true, IsNative = true, Project = viewModel.Project},
                new PlateManufacturer {Name = "Борский трубный завод", IsActive = true, IsNative = true, Project = viewModel.Project},
                new PlateManufacturer {Name = "Волжский трубный завод", IsActive = true, IsNative = true, Project = viewModel.Project},
                new PlateManufacturer {Name = "Волгоградский трубный завод", IsActive = true, IsNative = true, Project = viewModel.Project},
                new PlateManufacturer {Name = "Гурьевский металлургический завод", IsActive = true, IsNative = true, Project = viewModel.Project},
                new PlateManufacturer {Name = "Завод Точлит", IsActive = true}
            };
            Array.ForEach(plateManufacturers, s => firstSetupRepo.PlateManRepo.Save(s));
            #endregion
            firstSetupRepo.Commit();
            firstSetupRepo.BeginTransaction();
            #region Heat
            List<Heat> heats = new List<Heat>();
            for(int i = 0; i < HEATCOUNT; i++)
            {
                heats.Add
                    (
                    new Heat ()
                    {
                        Number = RndString(8),
                        SteelGrade = RndString(6),
                        PlateManufacturer = plateManufacturers[rnd.Next(plateManufacturers.Length - 1)],
                        IsActive = true                      
                    }
                    );
                firstSetupRepo.HeatRepo.Save(heats[i]);
            }

            #endregion
            firstSetupRepo.Commit();
            firstSetupRepo.BeginTransaction();
            #region PurchaseOrder
            List<PurchaseOrder> orders = new List<PurchaseOrder>
            {
                new PurchaseOrder {Number = RndString(5),Date = DateTime.Now.AddMonths(-rnd.Next(10)),IsActive=true},
                new PurchaseOrder {Number = RndString(5),Date = DateTime.Now.AddMonths(-rnd.Next(10)),IsActive=true},
                new PurchaseOrder {Number = RndString(5),Date = DateTime.Now.AddMonths(-rnd.Next(10)),IsActive=true},
                new PurchaseOrder {Number = RndString(5),Date = DateTime.Now.AddMonths(-rnd.Next(10)),IsActive=true},
                new PurchaseOrder {Number = RndString(5),Date = DateTime.Now.AddMonths(-rnd.Next(10)),IsActive=true}
            };
            orders.ForEach(s => firstSetupRepo.PurchaseRepo.Save(s));
            #endregion
            firstSetupRepo.Commit();
            firstSetupRepo.BeginTransaction();
            #region MillPipe
            List<Pipe> pipes = new List<Pipe>();
            for(int i = 0; i < PIPECOUNT; i++)
            {
                var plate = new Plate
                    {
                        Number = RndString(8),
                        Thickness = rnd.Next(2000),
                        Heat = heats[rnd.Next(heats.Count - 1)],
                        IsActive = true
                    };
                firstSetupRepo.PlateRepo.Save(plate);

                var pipe = new Pipe
                {
                    Number = RndString(8),
                    Plate = plate,
                    Mill = viewModel.MillName,
                    Diameter = types[0].Diameter,
                    WallThickness = types[0].Thickness,
                    Type = types[rnd.Next(1)],
                    PurchaseOrder = orders[orders.Count - 1],
                    Project = viewModel.Project,
                    Status = PipeMillStatus.Produced,
                    ProductionDate = DateTime.Now.AddDays(-rnd.Next(20)),
                    IsActive = true
                };
                pipe.RecalculateWeight();

                var results = new List<PipeTestResult>();
                foreach(var item in tests.Where(x => x.pipeType == pipe.Type))
                {
                    var testResult = new PipeTestResult
                    {
                        Operation = item,
                        Pipe = pipe,
                        Status = PipeTestResultStatus.Scheduled
                    };
                    results.Add(testResult);
                    firstSetupRepo.PipeTestResultRepo.Save(testResult);
                }
                pipe.PipeTestResult = results;
                pipes.Add(pipe);
                if(pipes.Count % 2 == 0)
                {
                    foreach(var item in pipe.PipeTestResult)
                    {
                        item.Status = PipeTestResultStatus.Accepted;
                        if(item.Operation.Category.Type == FixedCategory.Length)
                        {
                            item.Value = PIPELENGHT.ToString();
                        }
                    }
                    pipe.Length = PIPELENGHT;
                    pipe.Status = PipeMillStatus.Stocked;
                    pipe.ConstructionStatus = PartConstructionStatus.Pending;
                    pipe.IsAvailableToJoint = true;
                    pipe.ToExport = true;
                    pipe.WallThickness = 12;
                    pipe.RecalculateWeight();

                }


                firstSetupRepo.PipeRepo.Save(pipe);
            };
            #endregion
            firstSetupRepo.Commit();
            firstSetupRepo.BeginTransaction();
            #region Inspector
            List<Inspector> inspectors = new List<Inspector>();
            for(int i = 0; i < INSPECTORCOUNT; i++)
            {
                var insp = new Inspector
                    {
                        Name = new PersonName
                        {
                            FirstName = RndName(fNames),
                            LastName = RndName(lNames),
                            MiddleName = RndName(mNames),
                        },
                        IsActive = true
                    };
                insp.Certificates = CreateInspectorCertificates(insp, inspetorCertTypes);
                inspectors.Add(insp);
                firstSetupRepo.InspectorRepo.Save(insp);
            }
            #endregion
            firstSetupRepo.Commit();
            firstSetupRepo.BeginTransaction();
            #region Welder
            List<Welder> welders = new List<Welder>();

            for(int i = 0; i < WELDERCOUNT; i++)
            {
                var welder = new Welder
                    {
                        Grade = rnd.Next(6),
                        Name = new PersonName
                        {
                            FirstName = RndName(fNames),
                            LastName = RndName(lNames),
                            MiddleName = RndName(mNames),
                        },
                        Stamp = RndString(12),
                        Certificate = new Certificate
                        {
                            Number = RndString(14),
                            ExpirationDate = DateTime.Now.AddDays(rnd.Next(60)),
                            IsActive = true
                        },
                        IsActive = true
                    };
                welders.Add(welder);
                firstSetupRepo.WelderRepo.Save(welder);
            }
            #endregion
            firstSetupRepo.Commit();
            firstSetupRepo.BeginTransaction();
            #region ComponentType
            ComponentType[] componentTypes = 
            {
                new ComponentType{Name = "Заглушка",ConnectorsCount = 1, IsActive = true},
                new ComponentType{Name = "Переходник",ConnectorsCount = 2, IsActive = true},
                new ComponentType{Name = "Т - Соединение",ConnectorsCount = 3, IsActive = true},
                new ComponentType{Name = "Тройник",ConnectorsCount = 3, IsActive = true}
            };
            foreach(var item in componentTypes)
            {
                firstSetupRepo.ComponentTypeRepo.Save(item);
            }
            #endregion
            firstSetupRepo.Commit();
            firstSetupRepo.BeginTransaction();
            #region Component
            List<Domain.Entity.Construction.Component> components = new List<Domain.Entity.Construction.Component>();

            foreach(var type in componentTypes)
            {
                for(int i = 0; i < COMPONENTCOUNT; i++)
                {
                    var component = CreateComponent(type);
                    firstSetupRepo.ComponentRepo.Save(component);
                    components.Add(component);
                }
            }

            #endregion
            firstSetupRepo.Commit();
            firstSetupRepo.BeginTransaction();
            #region Release
            List<Prizm.Domain.Entity.Mill.ReleaseNote> releases = new List<Prizm.Domain.Entity.Mill.ReleaseNote>();
            for(int i = 0; i < RELEASECOUNT; i++)
            {
                Prizm.Domain.Entity.Mill.ReleaseNote release = new Prizm.Domain.Entity.Mill.ReleaseNote
                {
                    Number = RndString(10),
                    Shipped = false,
                    Date = DateTime.Now.AddDays(-rnd.Next(10)),
                    IsActive = true
                };
                release.Railcars = CreateRailcars(rnd.Next(2, 5));
                firstSetupRepo.ReleaseRepo.Save(release);
            }
            #endregion
            firstSetupRepo.Commit();

            return false;
        }
        public void TestSaveSettings()
        {
            var notify = new Mock<IUserNotify>();

            var repoPipeSize = new Mock<IMillPipeSizeTypeRepository>();
            var repoPipeTests = new Mock<IPipeTestRepository>();
            var repoWelders = new Mock<IWelderRepository>();
            var repoInspectors = new Mock<IInspectorRepository>();
            var repoManufacturers = new Mock<IPlateManufacturerRepository>();
            var repoProjectSetting = new Mock<IProjectRepository>();
            var repoUsers = new Mock<IUserRepository>();
            var repoRoles = new Mock<IRoleRepository>();
            var repoPerms = new Mock<IPermissionRepository>();
            var repoCategory = new Mock<ICategoryRepository>();
            var repoJointOperation = new Mock<IJointOperationRepository>();
            var repoCertificateType = new Mock<ICertificateTypeRepository>();
            var repoComponentType = new Mock<IComponentTypeRepository>();
            var repoSeamType = new Mock<ISeamTypeRepository>();

            var testProjectSetting = new Project() { IsNative = true};
            var testSizeType = new PipeMillSizeType() 
            { 
                IsNative = true, 
                Project = testProjectSetting,
                Diameter = 10,
                Thickness = 5,
                SeamType = new SeamType(),
                Length = 20,
            };
            foreach (PipeTest t in testSizeType.PipeTests)
            {
                t.Code = "Code";
                t.Name = "Name";
                t.ControlType = PipeTestControlType.Monitor;
                t.ResultType = PipeTestResultType.Boolean;
            }
            var testWelder = new Welder() { Certificate = new Certificate() { ExpirationDate = DateTime.Now} };
            var testManufacturer = new PlateManufacturer() { IsNative = true, Project = testProjectSetting};
            var testInspector = new Inspector();
            var testUser = new User();
            var testRole = new Role();
            var testPerm = new Permission() { Name = "CreateJoint" };
            var modifiableView = new Mock<IModifiable>();
            var jointOperations = new JointOperation();
            var ctx = new Mock<ISecurityContext>();

            repoPipeSize.Setup(_ => _.GetAll()).Returns(new List<PipeMillSizeType>() { testSizeType });
            repoWelders.Setup(_ => _.GetAll()).Returns(new List<Welder>() { testWelder });
            repoManufacturers.Setup(_ => _.GetAll()).Returns(new List<PlateManufacturer>() { testManufacturer });
            repoProjectSetting.Setup(_ => _.GetSingle()).Returns(testProjectSetting);
            repoInspectors.Setup(_ => _.GetAll()).Returns(new List<Inspector>() { testInspector });
            repoUsers.Setup(_ => _.GetAll()).Returns(new List<User>() { testUser });
            repoRoles.Setup(_ => _.GetAll()).Returns(new List<Role>() { testRole });
            repoPerms.Setup(_ => _.GetAll()).Returns(new List<Permission>() { testPerm });
            repoJointOperation.Setup(_ => _.GetAll()).Returns(new List<JointOperation>() { jointOperations });
            repoCategory.Setup(x => x.GetAll()).Returns(new List<Category>() { new Category() });
            repoCertificateType.Setup(x => x.GetAll()).Returns(new List<InspectorCertificateType>() { new InspectorCertificateType() });
            repoComponentType.Setup(x => x.GetAll()).Returns(new List<ComponentType>() { new ComponentType() });


            Mock<ISettingsRepositories> settingsRepos = new Mock<ISettingsRepositories>();
            settingsRepos.SetupGet(_ => _.PipeSizeTypeRepo).Returns(repoPipeSize.Object);
            settingsRepos.SetupGet(_ => _.PipeTestRepo).Returns(repoPipeTests.Object);
            settingsRepos.SetupGet(_ => _.WelderRepo).Returns(repoWelders.Object);
            settingsRepos.SetupGet(_ => _.PlateManufacturerRepo).Returns(repoManufacturers.Object);
            settingsRepos.SetupGet(_ => _.ProjectRepo).Returns(repoProjectSetting.Object);
            settingsRepos.SetupGet(_ => _.InspectorRepo).Returns(repoInspectors.Object);
            settingsRepos.SetupGet(_ => _.UserRepo).Returns(repoUsers.Object);
            settingsRepos.SetupGet(_ => _.RoleRepo).Returns(repoRoles.Object);
            settingsRepos.SetupGet(_ => _.PermissionRepo).Returns(repoPerms.Object);
            settingsRepos.SetupGet(_ => _.JointRepo).Returns(repoJointOperation.Object);
            settingsRepos.SetupGet(x => x.СategoryRepo).Returns(repoCategory.Object);
            settingsRepos.SetupGet(x => x.CertificateTypeRepo).Returns(repoCertificateType.Object);
            settingsRepos.SetupGet(x => x.ComponentTypeRepo).Returns(repoComponentType.Object);
            settingsRepos.SetupGet(x => x.SeamTypeRepo).Returns(repoSeamType.Object);

            var viewModel = new SettingsViewModel(settingsRepos.Object, notify.Object, ctx.Object);
            viewModel.ModifiableView = modifiableView.Object;
            viewModel.LoadData();
            viewModel.ModifiableView = modifiableView.Object;
            var validatable = new Mock<IValidatable>();
            validatable.Setup(x => x.Validate()).Returns(true);
            viewModel.validatableView = validatable.Object;

            var command = new SaveSettingsCommand(viewModel, settingsRepos.Object, notify.Object, ctx.Object);

            command.Execute();

            settingsRepos.Verify(_ => _.BeginTransaction(), Times.Once());
            repoPipeSize.Verify(_ => _.SaveOrUpdate(testSizeType), Times.Once());
            settingsRepos.Verify(_ => _.Commit(), Times.Once());
            repoPipeSize.Verify(_ => _.Evict(testSizeType), Times.Once());
            repoWelders.Verify(_ => _.SaveOrUpdate(testWelder), Times.Once());
            repoWelders.Verify(_ => _.Evict(testWelder), Times.Once());
            repoManufacturers.Verify(_ => _.SaveOrUpdate(testManufacturer), Times.Once());
            repoManufacturers.Verify(_ => _.Evict(testManufacturer), Times.Once());
            repoProjectSetting.Verify(_ => _.SaveOrUpdate(testProjectSetting), Times.Once());
            repoProjectSetting.Verify(_ => _.Evict(testProjectSetting), Times.Once());
            repoInspectors.Verify(_ => _.SaveOrUpdate(testInspector), Times.Once());
            repoInspectors.Verify(_ => _.Evict(testInspector), Times.Once());
            repoUsers.Verify(_ => _.SaveOrUpdate(testUser), Times.Once());
            repoUsers.Verify(_ => _.Evict(testUser), Times.Once());
            repoRoles.Verify(_ => _.SaveOrUpdate(testRole), Times.Once());
            repoRoles.Verify(_ => _.Evict(testRole), Times.Once());
        }
示例#4
0
 public WelderViewType(Welder welder)
 {
    this.welder = welder;
 }
示例#5
0
        private bool SeedOptional()
        {
            //Required seed hasn't been performed for Master worksration type, but data are used in optional seed
            if (viewModel.Project.WorkstationType == WorkstationType.Master)
            {
                SeedRequired();
            }
            firstSetupRepo.BeginTransaction();
            #region SeamTypes
            seamTypes = new List<SeamType>
            {
                new SeamType{Name = "Бесшовный", IsActive = true, IsNative = true, Project = viewModel.Project},
                new SeamType{Name = "Прямой", IsActive = true, IsNative = true, Project = viewModel.Project},
                new SeamType{Name = "Спиралевидный", IsActive = true, IsNative = true, Project = viewModel.Project},
            };
            foreach (var item in seamTypes)
            {
                firstSetupRepo.SeemTypeRepo.Save(item);
            }
            #endregion
            firstSetupRepo.Commit();

            firstSetupRepo.BeginTransaction();
            #region InspectorCertificateTypes
            inspetorCertTypes = new List<InspectorCertificateType>
            {
                new InspectorCertificateType {Name = "Покрытия (Coating)",IsActive = true},
                new InspectorCertificateType {Name = "РК (RT)",IsActive = true},
                new InspectorCertificateType {Name = "ВИК (VT)",IsActive = true},
                new InspectorCertificateType {Name = "УК (UT)",IsActive = true},
                new InspectorCertificateType {Name = "НАКС (Welding Engineer)",IsActive = true},
                new InspectorCertificateType {Name = "МК (MT)",IsActive = true}
            };
            inspetorCertTypes.ForEach(s => firstSetupRepo.CertificateTypeRepo.Save(s));
            #endregion
            firstSetupRepo.Commit();

            firstSetupRepo.BeginTransaction();
            #region PipeMillSyzeType
            types = new List<PipeMillSizeType>
            {
                new PipeMillSizeType
                {
                    Type = "1500 X 100500 X 50 - бесшовный",
                    IsActive = true,
                    Length = 9090,
                    Diameter = 1212,
                    Thickness = 12,
                    SeamType = seamTypes[0],
                    IsNative = true,
                    Project = viewModel.Project
                },
                new PipeMillSizeType
                {
                    Type = "1500 X 100500 X 50 - Прямой",
                    IsActive = true,
                    Length = 9090,
                    Diameter = 1212,
                    Thickness = 12,
                    SeamType = seamTypes[1],
                    IsNative = true,
                    Project = viewModel.Project
                },
            };
            types.ForEach(s => firstSetupRepo.SizeTypeRepo.Save(s));
            #endregion
            firstSetupRepo.Commit();

            firstSetupRepo.BeginTransaction();
            #region PipeTestCategory
            categories = new List<Category>
            {
                #region creating pipe test category
                new Category { Name = "Категория - 1", Fixed = false, Type = FixedCategory.Undefined, IsActive = true},
                new Category { Name = "Категория - 2", Fixed = false, Type = FixedCategory.Undefined, IsActive = true},
                new Category { Name = "Измерение длины", IsActive = true , Fixed=true, ResultType="int", Type=FixedCategory.Length},
                new Category { Name = "Контроль сварки", IsActive = true, Fixed = true, ResultType = "int", Type = FixedCategory.Weld },
                new Category { Name = "Контроль внешнего покрытия", IsActive = true, Fixed = true, ResultType = "int", Type = FixedCategory.ExternalCoat },
                new Category { Name = "Контроль внутреннего покрытия", IsActive = true, Fixed = true, ResultType = "int", Type = FixedCategory.InternalCoat }
	            #endregion
            };
            foreach (var category in categories)
            {
                firstSetupRepo.CategoryRepo.Save(category);
            }
            #endregion
            firstSetupRepo.Commit();

            firstSetupRepo.BeginTransaction();
            #region PipeTest
            tests = new List<PipeTest>
            {
                #region creating pipetests for first pipe size type
                new PipeTest 
                {
                    Code = "01",
                    Name = "Входной контроль листа",
                    Category = categories[0],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[0],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "02",
                    Name = "Сварка технологического шва",
                    Category = categories[3],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[0],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "03",
                    Name = "Сварка наружного шва",
                    Category = categories[3],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[0],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "04",
                    Name = "Сварка внутреннего шва",
                    Category = categories[3],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[0],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "05",
                    Name = "Экспандирование",
                    Category = categories[0],
                    ControlType = PipeTestControlType.Review,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[0],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "06",
                    Name = "Обработка торцов",
                    Category = categories[0],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[0],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "07",
                    Name = "Гидроиспытание",
                    Category = categories[0],
                    ControlType = PipeTestControlType.Witness,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[0],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "08",
                    Name = "Рентген сварного шва",
                    Category = categories[1],
                    ControlType = PipeTestControlType.Witness,
                    ResultType = PipeTestResultType.String,
                    pipeType = types[0],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "09",
                    Name = "АУЗК сварного шва",
                    Category = categories[1],
                    ControlType = PipeTestControlType.Witness,
                    ResultType = PipeTestResultType.String,
                    pipeType = types[0],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "10",
                    Name = "РУЗК концов сварного шва",
                    Category = categories[1],
                    ControlType = PipeTestControlType.Witness,
                    ResultType = PipeTestResultType.String,
                    pipeType = types[0],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "11",
                    Name = "МПК фаски",
                    Category = categories[1],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.String,
                    pipeType = types[0],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "12",
                    Name = "Наружный диаметр",
                    Category = categories[1],
                    ControlType = PipeTestControlType.Witness,
                    ResultType = PipeTestResultType.Diapason,
                    MinExpected = 1217,
                    MaxExpected = 1221,
                    pipeType = types[0],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "13",
                    Name = "Длина трубы",
                    Category = categories[2],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Diapason,
                    MinExpected = 9000,
                    MaxExpected = 12400,
                    pipeType = types[0],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "21",
                    Name = "Нанесение наружного покрытия",
                    Category = categories[4],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[0],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "31",
                    Name = "Нанесение внутреннего покрытия",
                    Category = categories[5],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[0],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "41",
                    Name = "Складирование",
                    Category = categories[0],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[0],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                }, 
	            #endregion

                #region creating pipetests for second pipe size type
                new PipeTest 
                {
                    Code = "01",
                    Name = "Входной контроль листа",
                    Category = categories[0],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[1],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "02",
                    Name = "Сварка технологического шва",
                    Category = categories[3],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[1],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "03",
                    Name = "Сварка наружного шва",
                    Category = categories[3],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[1],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "04",
                    Name = "Сварка внутреннего шва",
                    Category = categories[3],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[1],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "05",
                    Name = "Экспандирование",
                    Category = categories[0],
                    ControlType = PipeTestControlType.Review,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[1],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "06",
                    Name = "Обработка торцов",
                    Category = categories[0],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[1],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "07",
                    Name = "Гидроиспытание",
                    Category = categories[0],
                    ControlType = PipeTestControlType.Witness,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[1],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "08",
                    Name = "Рентген сварного шва",
                    Category = categories[1],
                    ControlType = PipeTestControlType.Witness,
                    ResultType = PipeTestResultType.String,
                    pipeType = types[1],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "09",
                    Name = "АУЗК сварного шва",
                    Category = categories[1],
                    ControlType = PipeTestControlType.Witness,
                    ResultType = PipeTestResultType.String,
                    pipeType = types[1],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "10",
                    Name = "РУЗК концов сварного шва",
                    Category = categories[1],
                    ControlType = PipeTestControlType.Witness,
                    ResultType = PipeTestResultType.String,
                    pipeType = types[1],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "11",
                    Name = "МПК фаски",
                    Category = categories[1],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.String,
                    pipeType = types[1],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "12",
                    Name = "Наружный диаметр",
                    Category = categories[1],
                    ControlType = PipeTestControlType.Witness,
                    ResultType = PipeTestResultType.Diapason,
                    MinExpected = 1217,
                    MaxExpected = 1221,
                    pipeType = types[1],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "13",
                    Name = "Длина трубы",
                    Category = categories[2],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Diapason,
                    MinExpected = 9000,
                    MaxExpected = 12400,
                    pipeType = types[1],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "21",
                    Name = "Нанесение наружного покрытия",
                    Category = categories[4],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[1],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "31",
                    Name = "Нанесение внутреннего покрытия",
                    Category = categories[5],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[1],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                },

                new PipeTest 
                {
                    Code = "41",
                    Name = "Складирование",
                    Category = categories[0],
                    ControlType = PipeTestControlType.Monitor,
                    ResultType = PipeTestResultType.Boolean,
                    pipeType = types[1],
                    IsActive = true,
                    FrequencyType = InspectionFrequencyType.R
                } 
                #endregion
            };

            foreach (var test in tests)
            {
                firstSetupRepo.TestRepo.Save(test);
            }
            #endregion
            firstSetupRepo.Commit();

            firstSetupRepo.BeginTransaction();
            #region PlateManufacturers
            PlateManufacturer[] plateManufacturers = 
            {
                new PlateManufacturer {Name = "Алапаевский металлургический завод", IsActive = true, IsNative = true, Project = viewModel.Project},
                new PlateManufacturer {Name = "Альметьевский трубный завод", IsActive = true, IsNative = true, Project = viewModel.Project},
                new PlateManufacturer {Name = "Борский трубный завод", IsActive = true, IsNative = true, Project = viewModel.Project},
                new PlateManufacturer {Name = "Волжский трубный завод", IsActive = true, IsNative = true, Project = viewModel.Project},
                new PlateManufacturer {Name = "Волгоградский трубный завод", IsActive = true, IsNative = true, Project = viewModel.Project},
                new PlateManufacturer {Name = "Гурьевский металлургический завод", IsActive = true, IsNative = true, Project = viewModel.Project},
                new PlateManufacturer {Name = "Завод Точлит", IsActive = true}
            };
            Array.ForEach(plateManufacturers, s => firstSetupRepo.PlateManRepo.Save(s));
            #endregion
            firstSetupRepo.Commit();
            firstSetupRepo.BeginTransaction();
            #region Heat
            List<Heat> heats = new List<Heat>();
            for(int i = 0; i < HEATCOUNT; i++)
            {
                heats.Add
                    (
                    new Heat ()
                    {
                        Number = RndString(8),
                        SteelGrade = RndString(6),
                        PlateManufacturer = plateManufacturers[rnd.Next(plateManufacturers.Length - 1)],
                        IsActive = true                      
                    }
                    );
                firstSetupRepo.HeatRepo.Save(heats[i]);
            }

            #endregion
            firstSetupRepo.Commit();
            firstSetupRepo.BeginTransaction();
            #region PurchaseOrder
            List<PurchaseOrder> orders = new List<PurchaseOrder>
            {
                new PurchaseOrder {Number = RndString(5),Date = DateTime.Now.AddMonths(-rnd.Next(10)),IsActive=true},
                new PurchaseOrder {Number = RndString(5),Date = DateTime.Now.AddMonths(-rnd.Next(10)),IsActive=true},
                new PurchaseOrder {Number = RndString(5),Date = DateTime.Now.AddMonths(-rnd.Next(10)),IsActive=true},
                new PurchaseOrder {Number = RndString(5),Date = DateTime.Now.AddMonths(-rnd.Next(10)),IsActive=true},
                new PurchaseOrder {Number = RndString(5),Date = DateTime.Now.AddMonths(-rnd.Next(10)),IsActive=true}
            };
            orders.ForEach(s => firstSetupRepo.PurchaseRepo.Save(s));
            #endregion
            firstSetupRepo.Commit();
            firstSetupRepo.BeginTransaction();
            #region MillPipe
            List<Pipe> pipes = new List<Pipe>();
            for(int i = 0; i < PIPECOUNT; i++)
            {
                var plate = new Plate
                    {
                        Number = RndString(8),
                        Thickness = rnd.Next(2000),
                        Heat = heats[rnd.Next(heats.Count - 1)],
                        IsActive = true
                    };
                firstSetupRepo.PlateRepo.Save(plate);

                var pipe = new Pipe
                {
                    Number = RndString(8),
                    Plate = plate,
                    Mill = viewModel.MillName,
                    Diameter = types[0].Diameter,
                    WallThickness = types[0].Thickness,
                    Type = types[rnd.Next(1)],
                    PurchaseOrder = orders[orders.Count - 1],
                    Project = viewModel.Project,
                    Status = PipeMillStatus.Produced,
                    ProductionDate = DateTime.Now.AddDays(-rnd.Next(20)),
                    IsActive = true
                };
                pipe.RecalculateWeight();

                var results = new List<PipeTestResult>();
                foreach(var item in tests.Where(x => x.pipeType == pipe.Type))
                {
                    var testResult = new PipeTestResult
                    {
                        Operation = item,
                        Pipe = pipe,
                        Status = PipeTestResultStatus.Scheduled
                    };
                    results.Add(testResult);
                    firstSetupRepo.PipeTestResultRepo.Save(testResult);
                }
                pipe.PipeTestResult = results;
                pipes.Add(pipe);
                if(pipes.Count % 2 == 0)
                {
                    foreach(var item in pipe.PipeTestResult)
                    {
                        item.Status = PipeTestResultStatus.Accepted;
                        if(item.Operation.Category.Type == FixedCategory.Length)
                        {
                            item.Value = PIPELENGHT.ToString();
                        }
                    }
                    pipe.Length = PIPELENGHT;
                    pipe.Status = PipeMillStatus.Stocked;
                    pipe.ConstructionStatus = PartConstructionStatus.Pending;
                    pipe.IsAvailableToJoint = true;
                    pipe.ToExport = true;
                    pipe.WallThickness = 12;
                    pipe.RecalculateWeight();

                }


                firstSetupRepo.PipeRepo.Save(pipe);
            };
            #endregion
            firstSetupRepo.Commit();
            firstSetupRepo.BeginTransaction();
            #region Inspector
            List<Inspector> inspectors = new List<Inspector>();
            for(int i = 0; i < INSPECTORCOUNT; i++)
            {
                var insp = new Inspector
                    {
                        Name = new PersonName
                        {
                            FirstName = RndName(fNames),
                            LastName = RndName(lNames),
                            MiddleName = RndName(mNames),
                        },
                        IsActive = true
                    };
                insp.Certificates = CreateInspectorCertificates(insp, inspetorCertTypes);
                inspectors.Add(insp);
                firstSetupRepo.InspectorRepo.Save(insp);
            }
            #endregion
            firstSetupRepo.Commit();
            firstSetupRepo.BeginTransaction();
            #region Welder
            List<Welder> welders = new List<Welder>();

            for(int i = 0; i < WELDERCOUNT; i++)
            {
                var welder = new Welder
                    {
                        Grade = rnd.Next(6),
                        Name = new PersonName
                        {
                            FirstName = RndName(fNames),
                            LastName = RndName(lNames),
                            MiddleName = RndName(mNames),
                        },
                        Stamp = RndString(12),
                        Certificate = new Certificate
                        {
                            Number = RndString(14),
                            ExpirationDate = DateTime.Now.AddDays(rnd.Next(60)),
                            IsActive = true
                        },
                        IsActive = true
                    };
                welders.Add(welder);
                firstSetupRepo.WelderRepo.Save(welder);
            }
            #endregion
            firstSetupRepo.Commit();
            firstSetupRepo.BeginTransaction();
            #region ComponentType
            ComponentType[] componentTypes = 
            {
                new ComponentType{Name = "Заглушка",ConnectorsCount = 1, IsActive = true},
                new ComponentType{Name = "Переходник",ConnectorsCount = 2, IsActive = true},
                new ComponentType{Name = "Т - Соединение",ConnectorsCount = 3, IsActive = true},
                new ComponentType{Name = "Тройник",ConnectorsCount = 3, IsActive = true}
            };
            foreach(var item in componentTypes)
            {
                firstSetupRepo.ComponentTypeRepo.Save(item);
            }
            #endregion
            firstSetupRepo.Commit();
            firstSetupRepo.BeginTransaction();
            #region Component
            List<Domain.Entity.Construction.Component> components = new List<Domain.Entity.Construction.Component>();

            foreach(var type in componentTypes)
            {
                for(int i = 0; i < COMPONENTCOUNT; i++)
                {
                    var component = CreateComponent(type);
                    firstSetupRepo.ComponentRepo.Save(component);
                    components.Add(component);
                }
            }

            #endregion
            firstSetupRepo.Commit();
            firstSetupRepo.BeginTransaction();
            #region Release
            List<Prizm.Domain.Entity.Mill.ReleaseNote> releases = new List<Prizm.Domain.Entity.Mill.ReleaseNote>();
            for(int i = 0; i < RELEASECOUNT; i++)
            {
                Prizm.Domain.Entity.Mill.ReleaseNote release = new Prizm.Domain.Entity.Mill.ReleaseNote
                {
                    Number = RndString(10),
                    Shipped = false,
                    Date = DateTime.Now.AddDays(-rnd.Next(10)),
                    IsActive = true
                };
                release.Railcars = CreateRailcars(rnd.Next(2, 5));
                firstSetupRepo.ReleaseRepo.Save(release);
            }
            #endregion
            firstSetupRepo.Commit();

            return false;
        }
        public void TestJointNewEdit()
        {
            var modifiableView = new Mock<IModifiable>();
            var notify = new Mock<IUserNotify>();
            var repoJoint = new Mock<IJointRepository>();
            var repoJointTestResult = new Mock<IJointTestResultRepository>();
            var repoJointWeldResult = new Mock<IJointWeldResultRepository>();
            var repoJointOperation =  new Mock< IJointOperationRepository>();
            var repoInspector = new Mock<IInspectorRepository>();
            var repoWelder = new Mock<IWelderRepository>();
            var repoAdo = new Mock<IMillReportsRepository>();
            var securityCtx = new Mock<ISecurityContext>();
            var repoSpool = new Mock<ISpoolRepository>();
            var repoPipe = new Mock<IPipeRepository>();
            var repoComponent = new Mock<IComponentRepository>();

            var joint = new Prizm.Domain.Entity.Construction.Joint() { Status = Domain.Entity.Construction.JointStatus.Withdrawn};
            BindingList<JointOperation> operations = new BindingList<JointOperation>(); 

            Mock<IConstructionRepository> repoConstruction = new Mock<IConstructionRepository>();
            repoConstruction.SetupGet(_ => _.RepoJoint).Returns(repoJoint.Object);
            repoConstruction.SetupGet(_ => _.RepoJointTestResult).Returns(repoJointTestResult.Object);
            repoConstruction.SetupGet(_ => _.RepoJointWeldResult).Returns(repoJointWeldResult.Object);
            repoConstruction.SetupGet(_ => _.RepoJointOperation).Returns(repoJointOperation.Object);
            repoConstruction.SetupGet(_ => _.RepoInspector).Returns(repoInspector.Object);
            repoConstruction.SetupGet(_ => _.RepoWelder).Returns(repoWelder.Object);
            repoConstruction.SetupGet(_ => _.RepoSpool).Returns(repoSpool.Object);
            repoConstruction.SetupGet(_ => _.RepoPipe).Returns(repoPipe.Object);
            repoConstruction.SetupGet(_ => _.RepoComponent).Returns(repoComponent.Object);
            repoJointOperation.Setup(_ => _.GetControlOperations()).Returns(operations);
            repoJointOperation.Setup(_ => _.GetRepairOperations()).Returns(operations);
            repoJoint.Setup(_ => _.GetActiveByNumber(joint)).Returns(new List<Prizm.Domain.Entity.Construction.Joint>());
            repoSpool.Setup(_ => _.Get(It.IsAny<Guid>())).Returns(new Domain.Entity.Construction.Spool());
            repoAdo.Setup(x => x.GetPipelineElements()).Returns(new System.Data.DataTable());

            modifiableView.SetupGet(x => x.IsModified).Returns(false);

            var viewModel = new JointNewEditViewModel(repoConstruction.Object, notify.Object, Guid.Empty, repoAdo.Object, securityCtx.Object);
            viewModel.Joint = joint;
            viewModel.FirstElement = new PartData();
            viewModel.SecondElement = new PartData();
            viewModel.ModifiableView = modifiableView.Object;
            var validatable = new Mock<IValidatable>();
            validatable.Setup(x => x.Validate()).Returns(true);
            viewModel.ValidatableView = validatable.Object;
            viewModel.Joint.LoweringDate = DateTime.Now;
            viewModel.Joint.Number = string.Empty;

            var welder = new Welder();
            var weldResult = new JointWeldResult();
            weldResult.Welders.Add(welder);
            weldResult.IsCompleted = true;

            viewModel.JointWeldResults.Add(weldResult);


            var command = new SaveJointCommand(repoConstruction.Object,viewModel, notify.Object, securityCtx.Object);
            command.Execute();
            repoConstruction.Verify(_ => _.BeginTransaction(), Times.Once());
            repoJoint.Verify(_ => _.SaveOrUpdate(It.IsAny<Prizm.Domain.Entity.Construction.Joint>()), Times.Once());
            repoConstruction.Verify(_ => _.Commit(), Times.Once());
            repoJoint.Verify(_ => _.Evict(It.IsAny<Prizm.Domain.Entity.Construction.Joint>()), Times.Once());
        }