public void Setup()
        {
            // Arrange
            _stepMock1 = new Mock <Step>();
            _stepMock1.SetupGet(s => s.Id).Returns(StepId1);
            _stepMock1.SetupGet(s => s.Plant).Returns(TestPlant);
            _stepMock2 = new Mock <Step>();
            _stepMock2.SetupGet(s => s.Id).Returns(StepId2);
            _stepMock2.SetupGet(s => s.Plant).Returns(TestPlant);

            _rtRepositoryMock = new Mock <IRequirementTypeRepository>();
            var rdMock1 = new Mock <RequirementDefinition>();

            rdMock1.SetupGet(x => x.Id).Returns(ReqDefId1);
            rdMock1.SetupGet(x => x.Plant).Returns(TestPlant);
            var rdMock2 = new Mock <RequirementDefinition>();

            rdMock2.SetupGet(x => x.Id).Returns(ReqDefId2);
            rdMock2.SetupGet(x => x.Plant).Returns(TestPlant);
            _rtRepositoryMock
            .Setup(r => r.GetRequirementDefinitionByIdAsync(ReqDefId2))
            .Returns(Task.FromResult(rdMock2.Object));

            var reqId = 111;

            _tagRequirement1OnStandardTag1 = new TagRequirement(TestPlant, ThreeWeekInterval, rdMock1.Object);
            _tagRequirement1OnStandardTag1.SetProtectedIdForTesting(++reqId);
            _standardTagWithOneRequirement = new Tag(TestPlant, TagType.Standard, "T1", Description, _stepMock1.Object, new List <TagRequirement>
            {
                _tagRequirement1OnStandardTag1
            });
            _tagRequirement1OnStandardTag2 = new TagRequirement(TestPlant, TwoWeekInterval, rdMock1.Object);
            _tagRequirement1OnStandardTag2.SetProtectedIdForTesting(++reqId);
            _tagRequirement2OnStandardTag2 = new TagRequirement(TestPlant, ThreeWeekInterval, rdMock2.Object);
            _tagRequirement2OnStandardTag2.SetProtectedIdForTesting(++reqId);
            _standardTagWithTwoRequirements = new Tag(TestPlant, TagType.Standard, "T2", "D", _stepMock1.Object, new List <TagRequirement>
            {
                _tagRequirement1OnStandardTag2,
                _tagRequirement2OnStandardTag2
            });
            _tagRequirement1OnAreaTag = new TagRequirement(TestPlant, ThreeWeekInterval, rdMock1.Object);
            _tagRequirement1OnAreaTag.SetProtectedIdForTesting(++reqId);
            _areaTagWithOneRequirement = new Tag(TestPlant, TagType.PoArea, "T3", Description, _stepMock1.Object, new List <TagRequirement>
            {
                _tagRequirement1OnAreaTag
            });

            _journeyRepositoryMock = new Mock <IJourneyRepository>();
            _journeyRepositoryMock
            .Setup(x => x.GetStepByStepIdAsync(StepId1))
            .Returns(Task.FromResult(_stepMock1.Object));
            _journeyRepositoryMock
            .Setup(x => x.GetStepByStepIdAsync(StepId2))
            .Returns(Task.FromResult(_stepMock2.Object));

            _projectRepositoryMock = new Mock <IProjectRepository>();
            _projectRepositoryMock.Setup(p => p.GetTagByTagIdAsync(StandardTagId1)).Returns(Task.FromResult(_standardTagWithOneRequirement));
            _projectRepositoryMock.Setup(p => p.GetTagByTagIdAsync(StandardTagId2)).Returns(Task.FromResult(_standardTagWithTwoRequirements));
            _projectRepositoryMock.Setup(p => p.GetTagByTagIdAsync(AreaTagId)).Returns(Task.FromResult(_areaTagWithOneRequirement));

            _dut = new UpdateTagStepAndRequirementsCommandHandler(
                _projectRepositoryMock.Object,
                _journeyRepositoryMock.Object,
                _rtRepositoryMock.Object,
                UnitOfWorkMock.Object,
                PlantProviderMock.Object);

            Assert.AreEqual(1, _standardTagWithOneRequirement.Requirements.Count);
        }
        public void Setup()
        {
            var responsible = new Responsible(TestPlant, "C", "D");

            var supplierMode = new Mode(TestPlant, "SUP", true);

            supplierMode.SetProtectedIdForTesting(SupplierModeId);
            _supplierStep = new Step(TestPlant, "SUP", supplierMode, responsible);
            _supplierStep.SetProtectedIdForTesting(SupplierStepId);

            var otherMode = new Mode(TestPlant, "OTHER", false);

            otherMode.SetProtectedIdForTesting(OtherModeId);
            _otherStep = new Step(TestPlant, "OTHER", otherMode, responsible);
            _otherStep.SetProtectedIdForTesting(OtherStepId);

            var rdForSupplier = new RequirementDefinition(TestPlant, "ForSupp", Interval, RequirementUsage.ForSuppliersOnly, 1);
            var rdForOther    = new RequirementDefinition(TestPlant, "ForOther", Interval, RequirementUsage.ForOtherThanSuppliers, 2);

            _requirementForSupplier = new TagRequirement(TestPlant, Interval, rdForSupplier);
            _requirementForSupplier.SetProtectedIdForTesting(RequirementForSupplierId);

            _requirementForOther = new TagRequirement(TestPlant, Interval, rdForOther);
            _requirementForOther.SetProtectedIdForTesting(RequirementForOtherId);

            _tagInSupplierStep = new Tag(TestPlant, TagType.Standard, "", "", _supplierStep, new List <TagRequirement>
            {
                _requirementForSupplier
            });
            _tagInSupplierStep.SetProtectedIdForTesting(TagInSupplierStepId);
            _tagInOtherStep = new Tag(TestPlant, TagType.Standard, "", "", _otherStep, new List <TagRequirement>
            {
                _requirementForOther
            });
            _tagInOtherStep.SetProtectedIdForTesting(TagInOtherStepId);

            _projectRepoMock = new Mock <IProjectRepository>();
            _projectRepoMock.Setup(r => r.GetTagByTagIdAsync(TagInSupplierStepId)).Returns(Task.FromResult(_tagInSupplierStep));
            _projectRepoMock.Setup(r => r.GetTagByTagIdAsync(TagInOtherStepId)).Returns(Task.FromResult(_tagInOtherStep));
            _personRepoMock = new Mock <IPersonRepository>();
            _personRepoMock
            .Setup(p => p.GetByOidAsync(It.Is <Guid>(x => x == CurrentUserOid)))
            .Returns(Task.FromResult(new Person(CurrentUserOid, "Test", "User")));

            _commandForSupplierRequirement = new PreserveCommand(TagInSupplierStepId, RequirementForSupplierId);
            _commandForOtherRequirement    = new PreserveCommand(TagInOtherStepId, RequirementForOtherId);

            _timeProvider.Elapse(TimeSpan.FromDays(-1));
            _tagInSupplierStep.StartPreservation();
            _tagInOtherStep.StartPreservation();

            _timeProvider.SetTime(_utcNow);

            _initialPreservationPeriodForSupplierRequirement = _requirementForSupplier.PreservationPeriods.Single();
            _initialPreservationPeriodForOtherRequirement    = _requirementForOther.PreservationPeriods.Single();

            _dut = new PreserveCommandHandler(
                _projectRepoMock.Object,
                _personRepoMock.Object,
                UnitOfWorkMock.Object,
                CurrentUserProviderMock.Object);
        }