コード例 #1
0
        protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions)
        {
            using (var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                _requirementTypeWithoutDefinition = new RequirementType(TestPlant, "T", "Title", RequirementTypeIcon.Area, 1);
                context.RequirementTypes.Add(_requirementTypeWithoutDefinition);
                context.SaveChangesAsync().Wait();

                _requirementType            = AddRequirementTypeWith1DefWithoutField(context, "T0", "D0", RequirementTypeIcon.Other, 999);
                _requirementDefWithoutField = _requirementType.RequirementDefinitions.Single();

                _requirementDefWithInfo = new RequirementDefinition(TestPlant, "D1", 2, RequirementUsage.ForAll, 1);
                _requirementType.AddRequirementDefinition(_requirementDefWithInfo);

                _requirementDefWithNumber = new RequirementDefinition(TestPlant, "D2", 2, RequirementUsage.ForAll, 1);
                _requirementType.AddRequirementDefinition(_requirementDefWithNumber);

                _requirementDefWithCheckbox = new RequirementDefinition(TestPlant, "D3", 2, RequirementUsage.ForAll, 1);
                _requirementType.AddRequirementDefinition(_requirementDefWithCheckbox);

                _requirementDefWithAttachment = new RequirementDefinition(TestPlant, "D4", 2, RequirementUsage.ForAll, 1);
                _requirementType.AddRequirementDefinition(_requirementDefWithAttachment);

                context.SaveChangesAsync().Wait();

                _infoField       = AddInfoField(context, _requirementDefWithInfo, "LabelA");
                _numberField     = AddNumberField(context, _requirementDefWithNumber, "LabelB", "UnitA", true);
                _checkboxField   = AddCheckBoxField(context, _requirementDefWithCheckbox, "LabelC");
                _attachmentField = AddAttachmentField(context, _requirementDefWithAttachment, "LabelD");
            }
        }
コード例 #2
0
        protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions)
        {
            using (var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                _reqType1 = AddRequirementTypeWith1DefWithoutField(context, "T1", "D1", _reqIconOther, 999);

                _reqDefForAll          = _reqType1.RequirementDefinitions.First();
                _reqDefVoided          = new RequirementDefinition(TestPlant, "D2", 2, RequirementUsage.ForAll, 2);
                _reqDefVoided.IsVoided = true;
                _reqDefForOther        = new RequirementDefinition(TestPlant, "D3", 2, RequirementUsage.ForOtherThanSuppliers, 3);
                _reqDefForSupplier     = new RequirementDefinition(TestPlant, "D4", 2, RequirementUsage.ForSuppliersOnly, 4);
                _reqType1.AddRequirementDefinition(_reqDefVoided);
                _reqType1.AddRequirementDefinition(_reqDefForOther);
                _reqType1.AddRequirementDefinition(_reqDefForSupplier);
                context.SaveChangesAsync().Wait();

                AddNumberField(context, _reqDefForAll, _numberLabel, _numberUnit, true);
                var f = AddNumberField(context, _reqDefForAll, "NUMBER", "mm", true);
                f.IsVoided = true;
                context.SaveChangesAsync().Wait();

                var reqType2 = AddRequirementTypeWith1DefWithoutField(context, "T2", "D2", _reqIconOther, 7);
                reqType2.IsVoided = true;
                context.SaveChangesAsync().Wait();
                AddRequirementTypeWith1DefWithoutField(context, "T3", "D3", _reqIconOther, 10000);
                AddRequirementTypeWith1DefWithoutField(context, "T4", "D4", _reqIconOther, 1);
            }
        }
コード例 #3
0
        private (Project, Action) CreateAction(PreservationContext context, string projectName, bool closeProject)
        {
            var plantId = _plantProvider.Plant;
            var mode    = new Mode(plantId, "M1", false);

            context.Modes.Add(mode);

            var responsible = new Responsible(plantId, "Resp1", "Resp1-Desc");

            context.Responsibles.Add(responsible);
            context.SaveChangesAsync().Wait();

            var journey = new Journey(plantId, "J1");
            var step    = new Step(plantId, "S1", mode, responsible);

            journey.AddStep(step);
            context.Journeys.Add(journey);
            context.SaveChangesAsync().Wait();

            var requirementType = new RequirementType(plantId, "RT", "RT title", RequirementTypeIcon.Other, 1);

            context.RequirementTypes.Add(requirementType);

            var requirementDefinition = new RequirementDefinition(plantId, "RD", 2, RequirementUsage.ForAll, 1);

            requirementType.AddRequirementDefinition(requirementDefinition);
            context.SaveChangesAsync().Wait();

            var project = new Project(plantId, projectName, $"{projectName} Desc")
            {
                IsClosed = closeProject
            };

            context.Projects.Add(project);

            var tag = new Tag(
                plantId,
                TagType.Standard,
                "Tag A",
                "Tag desc",
                step,
                new List <TagRequirement> {
                new TagRequirement(plantId, 2, requirementDefinition)
            });

            project.AddTag(tag);
            context.SaveChangesAsync().Wait();

            var action = new Action(plantId, "A", "D", null);

            tag.AddAction(action);

            var attachment = new ActionAttachment(plantId, Guid.Empty, "fil.txt");

            action.AddAttachment(attachment);

            context.SaveChangesAsync().Wait();
            return(project, action);
        }
        protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions)
        {
            using var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider);

            _uri = new Uri("http://whatever/file.txt");
            _attachmentOptionsMock = new Mock <IOptionsMonitor <AttachmentOptions> >();
            var options = new AttachmentOptions
            {
                BlobContainer = BlobContainer
            };

            _attachmentOptionsMock
            .Setup(x => x.CurrentValue)
            .Returns(options);

            var journey = AddJourneyWithStep(context, "J1", "S", AddMode(context, "M1", false), AddResponsible(context, "R1"));

            var reqDef          = AddRequirementTypeWith1DefWithoutField(context, "T1", "D1", RequirementTypeIcon.Other).RequirementDefinitions.Single();
            var attachmentField = new Field(TestPlant, "Label", FieldType.Attachment, 0);

            reqDef.AddField(attachmentField);
            context.SaveChangesAsync().Wait();

            var requirement = new TagRequirement(TestPlant, 2, reqDef);

            var tag = new Tag(TestPlant,
                              TagType.Standard,
                              "TagNo",
                              "Description",
                              journey.Steps.ElementAt(0),
                              new List <TagRequirement> {
                requirement
            });

            context.Tags.Add(tag);
            tag.StartPreservation();
            context.SaveChangesAsync().Wait();

            _tagId = tag.Id;

            _requirementId     = requirement.Id;
            _attachmentFieldId = attachmentField.Id;

            var fieldValueAttachment = new FieldValueAttachment(TestPlant, Guid.Empty, "FilA.txt");

            requirement.RecordAttachment(fieldValueAttachment, _attachmentFieldId, reqDef);
            context.SaveChangesAsync().Wait();

            var fullBlobPath = fieldValueAttachment.GetFullBlobPath(BlobContainer);

            _blobStorageMock = new Mock <IBlobStorage>();
            _blobStorageMock
            .Setup(b => b.GetDownloadSasUri(fullBlobPath, It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>()))
            .Returns(_uri);
        }
        public async Task Handler_ShouldReturnTagRequirementsWithNumbers_AfterRecordingNumberFields()
        {
            var numberFieldWithNaId     = _thirdNumberFieldId;
            var numberFieldWithDoubleId = _secondNumberFieldId;
            var number = 1282.91;

            using (var context = new PreservationContext(_dbContextOptions, _plantProviderMock.Object, _eventDispatcher, _currentUserProvider))
            {
                var tag = context.Tags.Include(t => t.Requirements).Single();
                tag.StartPreservation();
                context.SaveChangesAsync().Wait();

                var requirementDefinition = context.RequirementDefinitions.Include(rd => rd.Fields)
                                            .Single(rd => rd.Id == _requirementDefinitionWithThreeNumberShowPrevId);
                var requirement = context.TagRequirements.Single(r => r.Id == _requirementWithThreeNumberShowPrevId);

                requirement.RecordNumberIsNaValues(
                    new List <int>
                {
                    numberFieldWithNaId
                },
                    requirementDefinition);
                requirement.RecordNumberValues(
                    new Dictionary <int, double?>
                {
                    { numberFieldWithDoubleId, number }
                },
                    requirementDefinition);
                context.SaveChangesAsync().Wait();
            }

            using (var context = new PreservationContext(_dbContextOptions, _plantProviderMock.Object, _eventDispatcher, _currentUserProvider))
            {
                var query = new GetTagRequirementsQuery(_tagId, false, false);
                var dut   = new GetTagRequirementsQueryHandler(context);

                var result = await dut.Handle(query, default);

                Assert.IsNotNull(result);
                Assert.AreEqual(ResultType.Ok, result.ResultType);

                var requirementWithThreeNumberShowPrev = result.Data.Single(r => r.Id == _requirementWithThreeNumberShowPrevId);
                Assert.AreEqual(3, requirementWithThreeNumberShowPrev.Fields.Count);

                var fieldWithNa = requirementWithThreeNumberShowPrev.Fields.Single(f => f.Id == numberFieldWithNaId);
                AssertNaNumberInCurrentValue(fieldWithNa);

                var fieldWithDouble = requirementWithThreeNumberShowPrev.Fields.Single(f => f.Id == numberFieldWithDoubleId);
                AssertNumberInCurrentValue(fieldWithDouble, number);
            }
        }
コード例 #6
0
        protected RequirementType AddRequirementTypeWith1DefWithoutField(PreservationContext context, string typeCode, string defTitle, RequirementTypeIcon icon, int sortKey = 0)
        {
            var requirementType = new RequirementType(TestPlant, typeCode, $"Title{typeCode}", icon, sortKey);

            context.RequirementTypes.Add(requirementType);
            context.SaveChangesAsync().Wait();

            var requirementDefinition = new RequirementDefinition(TestPlant, defTitle, 2, RequirementUsage.ForAll, 1);

            requirementType.AddRequirementDefinition(requirementDefinition);
            context.SaveChangesAsync().Wait();

            return(requirementType);
        }
コード例 #7
0
        protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions)
        {
            using (var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher,
                                                         _currentUserProvider))
            {
                var journey = AddJourneyWithStep(context, "J1", "S", AddMode(context, "M1", false), AddResponsible(context, "R1"));
                _requirementType = AddRequirementTypeWith1DefWithoutField(context, "RT", "RD", RequirementTypeIcon.Other, 1);
                _requirementDefinitionWithoutOneField =
                    _requirementType.RequirementDefinitions.Single();
                _infoField = AddInfoField(context, _requirementDefinitionWithoutOneField, "I");

                // be sure to use different intervals in the TagRequirement and RequirementDefinition to be able to Assert on correct value for dto.IntervalWeeks
                _interval = _requirementDefinitionWithoutOneField.DefaultIntervalWeeks * 2;

                var requirementWithoutField = new TagRequirement(TestPlant, _interval, _requirementDefinitionWithoutOneField);

                var tag = new Tag(TestPlant,
                                  TagType.Standard,
                                  "TagNo",
                                  "Description",
                                  journey.Steps.ElementAt(0),
                                  new List <TagRequirement>
                {
                    requirementWithoutField
                });
                context.Tags.Add(tag);

                Assert.IsNull(requirementWithoutField.ActivePeriod);
                // All TagRequirements get an active Period when starting
                tag.StartPreservation();
                Assert.IsNotNull(requirementWithoutField.ActivePeriod);

                context.SaveChangesAsync().Wait();
                _tagId = tag.Id;
                _requirementWithoutFieldId = requirementWithoutField.Id;

                var activePeriodForRequirementWithOutField =
                    tag.Requirements.Single(r => r.Id == requirementWithoutField.Id).ActivePeriod;

                Assert.IsNull(activePeriodForRequirementWithOutField.PreservationRecord);
                requirementWithoutField.SetComment(_comment);
                // Active Period gets a Preservation Record and the current Active Period be a new active Period when preserving
                tag.Preserve(new Mock <Person>().Object, _requirementWithoutFieldId);
                Assert.IsNotNull(activePeriodForRequirementWithOutField.PreservationRecord);

                context.SaveChangesAsync().Wait();
                _preservationRecordGuid = activePeriodForRequirementWithOutField.PreservationRecord.ObjectGuid;
                _preservationRecordId   = activePeriodForRequirementWithOutField.PreservationRecord.Id;
            }
        }
        public async Task Handler_ShouldReturnPreviousValues_AfterRecordingNumberFieldsAndPreserving()
        {
            var number = 1.91;

            using (var context = new PreservationContext(_dbContextOptions, _plantProviderMock.Object, _eventDispatcher, _currentUserProvider))
            {
                var tag = context.Tags.Include(t => t.Requirements).Single();
                tag.StartPreservation();
                context.SaveChangesAsync().Wait();

                var requirementDefinition = context.RequirementDefinitions.Include(rd => rd.Fields)
                                            .Single(rd => rd.Id == _requirementDefinitionWithThreeNumberShowPrevId);
                var requirement = context.TagRequirements.Single(r => r.Id == _requirementWithThreeNumberShowPrevId);

                requirement.RecordNumberValues(
                    new Dictionary <int, double?>
                {
                    { _firstNumberFieldId, number },
                    { _secondNumberFieldId, number },
                    { _thirdNumberFieldId, number }
                },
                    requirementDefinition);
                context.SaveChangesAsync().Wait();

                _timeProvider.ElapseWeeks(_interval);
                tag.Preserve(new Mock <Person>().Object);
                context.SaveChangesAsync().Wait();
            }

            using (var context = new PreservationContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var query = new GetTagRequirementsQuery(_tagId, false, false);
                var dut   = new GetTagRequirementsQueryHandler(context);

                var result = await dut.Handle(query, default);

                Assert.IsNotNull(result);
                Assert.AreEqual(ResultType.Ok, result.ResultType);

                var requirementWithThreeNumberShowPrev = result.Data.Single(r => r.Id == _requirementWithThreeNumberShowPrevId);
                Assert.AreEqual(3, requirementWithThreeNumberShowPrev.Fields.Count);

                foreach (var fieldDto in requirementWithThreeNumberShowPrev.Fields)
                {
                    AssertNumberInPreviousValue(fieldDto, number);
                }
            }
        }
コード例 #9
0
        public async Task HasOtherStepWithAutoTransferMethodAsync_ShouldReturnFalse_WhenSameStepHasSameAutoTransferMethod()
        {
            int stepId;
            var autoTransferMethod = AutoTransferMethod.OnRfccSign;

            using (var context = new PreservationContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var journey = context.Journeys.Single(j => j.Id == _journey1WithStepId);
                var step    = new Step(TestPlant, "S2", AddMode(context, "M2", false), AddResponsible(context, "R2"))
                {
                    AutoTransferMethod = autoTransferMethod
                };
                journey.AddStep(step);
                context.SaveChangesAsync().Wait();

                stepId = step.Id;
            }

            using (var context = new PreservationContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var dut    = new JourneyValidator(context);
                var result = await dut.HasOtherStepWithAutoTransferMethodAsync(_journey1WithStepId, stepId, autoTransferMethod, default);

                Assert.IsFalse(result);
            }
        }
コード例 #10
0
        protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions)
        {
            using (var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var project = AddProject(context, "P", "Project description");
                var journey = AddJourneyWithStep(context, "J", "S1", AddMode(context, "M1", false), AddResponsible(context, "R1"));
                var rd      = AddRequirementTypeWith1DefWithoutField(context, "Rot", "D", RequirementTypeIcon.Other).RequirementDefinitions.First();

                _tagWithNoHistory = new Tag(TestPlant, TagType.Standard, "TagNo", "Tag description", journey.Steps.First(),
                                            new List <TagRequirement> {
                    new TagRequirement(TestPlant, 2, rd)
                });
                project.AddTag(_tagWithNoHistory);

                _tagWithHistory = new Tag(TestPlant, TagType.Standard, "TagNo1", "Tag description1", journey.Steps.First(),
                                          new List <TagRequirement> {
                    new TagRequirement(TestPlant, 2, rd)
                });
                project.AddTag(_tagWithHistory);

                _historyVoidTag   = new History(TestPlant, "D", _tagWithHistory.ObjectGuid, ObjectType.Tag, EventType.TagVoided);
                _historyCreateTag = new History(TestPlant, "D1", _tagWithHistory.ObjectGuid, ObjectType.Tag, EventType.TagCreated);

                context.History.Add(_historyVoidTag);
                context.History.Add(_historyCreateTag);

                context.SaveChangesAsync().Wait();

                _query = new GetHistoryQuery(_tagWithHistory.Id);
            }
        }
コード例 #11
0
        private static void SeedTagAttachment(PreservationContext dbContext, Tag tag)
        {
            var attachment = new TagAttachment(tag.Plant, KnownTestData.TagAttachmentBlobStorageId, "Fil1.txt");

            tag.AddAttachment(attachment);
            dbContext.SaveChangesAsync().Wait();
        }
コード例 #12
0
        public void Setup()
        {
            _plantCacheMock.Setup(p => p.GetPlantTitleAsync(_plantA.Id)).Returns(Task.FromResult(_plantA.Title));
            _plantCacheMock.Setup(p => p.GetPlantTitleAsync(_plantB.Id)).Returns(Task.FromResult(_plantB.Title));

            var currentUserProviderMock = new Mock <ICurrentUserProvider>();

            currentUserProviderMock.Setup(x => x.GetCurrentUserOid()).Returns(_currentUserOid);
            _currentUserProvider = currentUserProviderMock.Object;

            var eventDispatcher = new Mock <IEventDispatcher>();

            _eventDispatcher = eventDispatcher.Object;

            _timeProvider = new ManualTimeProvider(new DateTime(2020, 2, 1, 0, 0, 0, DateTimeKind.Utc));
            TimeService.SetProvider(_timeProvider);

            _dbContextOptions = new DbContextOptionsBuilder <PreservationContext>()
                                .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                .Options;

            using (var context = new PreservationContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                // ensure current user exists in db
                _currentUser = new Person(_currentUserOid, "Ole", "Lukkøye");
                context.Persons.Add(_currentUser);
                context.SaveChangesAsync().Wait();

                _plantProvider.SetPlant(_plantA.Id);
                (_projectA, _actionA) = CreateAction(context, "PrA", false);
                _plantProvider.SetPlant(_plantB.Id);
                (_projectB, _actionB) = CreateAction(context, "PrB", true);
                _plantProvider.SetCrossPlantQuery();
            }
        }
        public async Task Handler_ShouldReturnTagRequirements_AfterPreservationStarted()
        {
            using (var context = new PreservationContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var tag = context.Tags.Include(t => t.Requirements).Single();
                tag.StartPreservation();
                context.SaveChangesAsync().Wait();
            }

            using (var context = new PreservationContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                _timeProvider.ElapseWeeks(_requestTimeAfterPreservationStartedInWeeks);

                var query = new GetTagRequirementsQuery(_tagId, false, false);
                var dut   = new GetTagRequirementsQueryHandler(context);

                var result = await dut.Handle(query, default);

                Assert.IsNotNull(result);
                Assert.AreEqual(ResultType.Ok, result.ResultType);

                foreach (var requirement in result.Data)
                {
                    Assert.IsTrue(requirement.NextDueTimeUtc.HasValue);
                    Assert.IsNotNull(requirement.NextDueTimeUtc.Value);
                    Assert.IsNotNull(requirement.NextDueAsYearAndWeek);
                    Assert.AreEqual(_interval, requirement.IntervalWeeks);
                    Assert.AreEqual(_interval - _requestTimeAfterPreservationStartedInWeeks, requirement.NextDueWeeks);
                }

                AssertRequirements(result.Data);
            }
        }
        protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions)
        {
            _blobStorageMock       = new Mock <IBlobStorage>();
            _uri                   = new Uri("http://whatever/file.txt");
            _attachmentOptionsMock = new Mock <IOptionsMonitor <AttachmentOptions> >();
            var options = new AttachmentOptions
            {
                BlobContainer = BlobContainer
            };

            _attachmentOptionsMock
            .Setup(x => x.CurrentValue)
            .Returns(options);

            using var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider);

            _testDataSet = AddTestDataSet(context);

            var tag = _testDataSet.Project1.Tags.First();

            _attachment = new TagAttachment(TestPlant, Guid.NewGuid(), "FileA");
            tag.AddAttachment(_attachment);

            context.SaveChangesAsync().Wait();

            _tagId        = tag.Id;
            _attachmentId = _attachment.Id;

            var fullBlobPath = _attachment.GetFullBlobPath(BlobContainer);

            _blobStorageMock
            .Setup(b => b.GetDownloadSasUri(fullBlobPath, It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>()))
            .Returns(_uri);
        }
        public async Task Handler_ShouldReturnTagRequirements_IsInUse_AfterPreservationStarted()
        {
            using (var context = new PreservationContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var tag = context.Tags.Include(t => t.Requirements).Single();
                tag.StartPreservation();
                context.SaveChangesAsync().Wait();
            }

            using (var context = new PreservationContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var query = new GetTagRequirementsQuery(_tagId, false, false);
                var dut   = new GetTagRequirementsQueryHandler(context);

                var result = await dut.Handle(query, default);

                Assert.IsNotNull(result);
                Assert.AreEqual(ResultType.Ok, result.ResultType);

                foreach (var requirement in result.Data)
                {
                    Assert.IsTrue(requirement.IsInUse);
                }
            }
        }
コード例 #16
0
        private static void SeedActionAttachment(PreservationContext dbContext, Action action)
        {
            var attachment = new ActionAttachment(action.Plant, KnownTestData.ActionAttachmentBlobStorageId, "Fil2.txt");

            action.AddAttachment(attachment);
            dbContext.SaveChangesAsync().Wait();
        }
コード例 #17
0
        public async Task Handler_ShouldReturnModifiedAction()
        {
            DateTime?modifiedTime;

            using (var context = new PreservationContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var openAction = context.Actions.Single(a => a.Id == _openActionId);
                openAction.Title = "Changed title";
                _timeProvider.Elapse(new TimeSpan(1, 1, 1, 1));
                context.SaveChangesAsync().Wait();
                modifiedTime = openAction.ModifiedAtUtc;
            }

            using (var context = new PreservationContext(_dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                var query = new GetActionDetailsQuery(_tagId, _openActionId);
                var dut   = new GetActionDetailsQueryHandler(context);

                var result = await dut.Handle(query, default);

                Assert.IsNotNull(result);
                Assert.AreEqual(ResultType.Ok, result.ResultType);

                var actionDetailDto = result.Data;

                AssertModifiedAction(actionDetailDto, _testDataSet.CurrentUser, modifiedTime);
            }
        }
コード例 #18
0
        private static void SeedAttachmentField(PreservationContext dbContext, RequirementDefinition reqDef)
        {
            var attachmentField = new Field(reqDef.Plant, Guid.NewGuid().ToString(), FieldType.Attachment, 10);

            reqDef.AddField(attachmentField);
            dbContext.SaveChangesAsync().Wait();
        }
コード例 #19
0
        protected override void SetupNewDatabase(DbContextOptions <PreservationContext> dbContextOptions)
        {
            using (var context = new PreservationContext(dbContextOptions, _plantProvider, _eventDispatcher, _currentUserProvider))
            {
                _testDataSet = AddTestDataSet(context);

                var tf = AddTagFunction(context, _tagFunctionCode, _registerCode);
                var rt = AddRequirementTypeWith1DefWithoutField(context, "ROT", "R", RequirementTypeIcon.Other);
                tf.AddRequirement(new TagFunctionRequirement(TestPlant, 4, rt.RequirementDefinitions.First()));

                context.SaveChangesAsync().Wait();

                _tagApiServiceMock = new Mock <ITagApiService>();
                _apiTags           = new List <PCSTagOverview>
                {
                    new PCSTagOverview
                    {
                        TagNo                = _testDataSet.Project1.Tags.First().TagNo,
                        CommPkgNo            = "CommPkgNo1",
                        Description          = "Desc1",
                        Id                   = 1,
                        McPkgNo              = "McPkgNo1",
                        PurchaseOrderTitle   = "PoNo1",
                        TagFunctionCode      = _tagFunctionCode,
                        RegisterCode         = _registerCode,
                        MccrResponsibleCodes = "R1"
                    },
                    new PCSTagOverview
                    {
                        TagNo                = "TagNo2",
                        CommPkgNo            = "CommPkgNo2",
                        Description          = "Desc2",
                        Id                   = 2,
                        McPkgNo              = "McPkgNo2",
                        PurchaseOrderTitle   = "PoNo1/CallOff1",
                        TagFunctionCode      = _tagFunctionCode,
                        RegisterCode         = _registerCode,
                        MccrResponsibleCodes = "R2"
                    },
                    new PCSTagOverview
                    {
                        TagNo                = "TagNo3",
                        CommPkgNo            = "CommPkgNo3",
                        Description          = "Desc3",
                        Id                   = 3,
                        McPkgNo              = "McPkgNo3",
                        PurchaseOrderTitle   = "PoNo1/CallOff2",
                        TagFunctionCode      = _tagFunctionCode,
                        RegisterCode         = _registerCode,
                        MccrResponsibleCodes = "R3"
                    }
                };
                _tagApiServiceMock
                .Setup(x => x.SearchTagsByTagFunctionsAsync(TestPlant, _testDataSet.Project1.Name, new List <string> {
                    _tagFunctionCodeRegisterCodePair
                }))
                .Returns(Task.FromResult(_apiTags));
                _query = new SearchTagsByTagFunctionQuery(_testDataSet.Project1.Name);
            }
        }
コード例 #20
0
        protected Responsible AddResponsible(PreservationContext context, string code)
        {
            var responsible = new Responsible(TestPlant, code, $"{code}-Desc");

            context.Responsibles.Add(responsible);
            context.SaveChangesAsync().Wait();
            return(responsible);
        }
コード例 #21
0
        protected Tag AddTag(PreservationContext context, Project parentProject, TagType tagType, string tagNo, string description, Step step, IEnumerable <TagRequirement> requirements)
        {
            var tag = new Tag(TestPlant, tagType, tagNo, description, step, requirements);

            parentProject.AddTag(tag);
            context.SaveChangesAsync().Wait();
            return(tag);
        }
コード例 #22
0
        protected Field AddNumberField(PreservationContext context, RequirementDefinition rd, string label, string unit, bool showPrevious)
        {
            var field = new Field(TestPlant, label, FieldType.Number, 0, unit, showPrevious);

            rd.AddField(field);
            context.SaveChangesAsync().Wait();
            return(field);
        }
コード例 #23
0
        protected Field AddAttachmentField(PreservationContext context, RequirementDefinition rd, string label)
        {
            var field = new Field(TestPlant, label, FieldType.Attachment, 0);

            rd.AddField(field);
            context.SaveChangesAsync().Wait();
            return(field);
        }
コード例 #24
0
        private static Step SeedStep(PreservationContext dbContext, Journey journey, string title, Mode mode, Responsible responsible)
        {
            var step = new Step(journey.Plant, title, mode, responsible);

            journey.AddStep(step);
            dbContext.SaveChangesAsync().Wait();
            return(step);
        }
コード例 #25
0
        protected Journey AddJourney(PreservationContext context, string journeyTitle)
        {
            var journey = new Journey(TestPlant, journeyTitle);

            context.Journeys.Add(journey);
            context.SaveChangesAsync().Wait();
            return(journey);
        }
コード例 #26
0
        protected Mode AddMode(PreservationContext context, string title, bool forSupplier)
        {
            var mode = new Mode(TestPlant, title, forSupplier);

            context.Modes.Add(mode);
            context.SaveChangesAsync().Wait();
            return(mode);
        }
コード例 #27
0
        protected Person AddPerson(PreservationContext context, Guid oid, string firstName, string lastName)
        {
            var person = new Person(oid, firstName, lastName);

            context.Persons.Add(person);
            context.SaveChangesAsync().Wait();
            return(person);
        }
コード例 #28
0
        private static Responsible SeedResponsible(PreservationContext dbContext, string plant)
        {
            var responsibleRepository = new ResponsibleRepository(dbContext);
            var responsible           = new Responsible(plant, KnownTestData.ResponsibleCode, KnownTestData.ResponsibleDescription);

            responsibleRepository.Add(responsible);
            dbContext.SaveChangesAsync().Wait();
            return(responsible);
        }
コード例 #29
0
        private static RequirementDefinition SeedReqDef(PreservationContext dbContext, RequirementType reqType, string title)
        {
            var reqDef =
                new RequirementDefinition(reqType.Plant, title, 4, RequirementUsage.ForAll, 10);

            reqType.AddRequirementDefinition(reqDef);
            dbContext.SaveChangesAsync().Wait();
            return(reqDef);
        }
コード例 #30
0
        private static Mode SeedMode(PreservationContext dbContext, string plant, string title, bool forSupplier)
        {
            var modeRepository = new ModeRepository(dbContext);
            var mode           = new Mode(plant, title, forSupplier);

            modeRepository.Add(mode);
            dbContext.SaveChangesAsync().Wait();
            return(mode);
        }