public void Validate_ShouldFail_WhenNoTagNosGiven()
        {
            var command = new AutoScopeTagsCommand(
                new List <string>(),
                _projectName,
                _stepId,
                null,
                null);

            var result = _dut.Validate(command);

            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.IsTrue(result.Errors[0].ErrorMessage.StartsWith("At least 1 tag must be given!"));
        }
        public void Validate_ShouldFail_WhenNoTagNosNotUnique()
        {
            var command = new AutoScopeTagsCommand(
                new List <string> {
                "X", "x"
            },
                _projectName,
                _stepId,
                null,
                null);

            var result = _dut.Validate(command);

            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.IsTrue(result.Errors[0].ErrorMessage.StartsWith("Tags must be unique!"));
        }
        public void Validate_ShouldFailWith1Error_WhenErrorsInDifferentRules()
        {
            _tagValidatorMock.Setup(r => r.ExistsAsync(_tagNo2, _projectName, default)).Returns(Task.FromResult(true));

            var command = new AutoScopeTagsCommand(
                new List <string> {
                _tagNo1, _tagNo1, _tagNo2
            },
                _projectName,
                _stepId,
                null,
                null);

            var result = _dut.Validate(command);

            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
        }
        public void Constructor_ShouldSetProperties_WithRequirements()
        {
            var dut = new AutoScopeTagsCommand(
                new List <string> {
                "TagNoA"
            },
                "ProjectNameA",
                2,
                "RemarkA",
                "SA_A");

            Assert.AreEqual("ProjectNameA", dut.ProjectName);
            Assert.AreEqual("RemarkA", dut.Remark);
            Assert.AreEqual("SA_A", dut.StorageArea);
            Assert.AreEqual(2, dut.StepId);
            Assert.AreEqual(1, dut.TagNos.Count());
            Assert.AreEqual("TagNoA", dut.TagNos.First());
        }
        public void Setup_OkState()
        {
            _tagValidatorMock = new Mock <ITagValidator>();

            _stepValidatorMock = new Mock <IStepValidator>();
            _stepValidatorMock.Setup(r => r.ExistsAsync(_stepId, default)).Returns(Task.FromResult(true));

            _projectValidatorMock = new Mock <IProjectValidator>();

            _command = new AutoScopeTagsCommand(
                new List <string> {
                _tagNo1, _tagNo2
            },
                _projectName,
                _stepId,
                null,
                null);

            _dut = new AutoScopeTagsCommandValidator(
                _tagValidatorMock.Object,
                _stepValidatorMock.Object,
                _projectValidatorMock.Object);
        }
        public void Setup()
        {
            // Arrange
            var tagFunctionCode1 = "TagFunctionCode1";
            var registerCode1    = "RegisterCodeCode1";
            var tagFunctionCode2 = "TagFunctionCode2";
            var registerCode2    = "RegisterCodeCode2";

            _modeRepositoryMock = new Mock <IModeRepository>();
            _modeMock           = new Mock <Mode>();
            _modeMock.SetupGet(m => m.Plant).Returns(TestPlant);
            _modeMock.SetupGet(x => x.Id).Returns(ModeId);
            _modeRepositoryMock
            .Setup(r => r.GetByIdAsync(ModeId))
            .Returns(Task.FromResult(_modeMock.Object));

            // Arrange
            step = new Step(TestPlant, "S", _modeMock.Object, new Responsible(TestPlant, "RC", "RD"));
            step.SetProtectedIdForTesting(StepId);

            _journeyRepositoryMock = new Mock <IJourneyRepository>();
            _journeyRepositoryMock
            .Setup(x => x.GetStepByStepIdAsync(StepId))
            .Returns(Task.FromResult(step));

            _projectRepositoryMock = new Mock <IProjectRepository>();
            _projectRepositoryMock
            .Setup(x => x.Add(It.IsAny <Project>()))
            .Callback <Project>(project =>
            {
                _projectAddedToRepository = project;
            });

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

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

            rdMock2a.SetupGet(x => x.Id).Returns(ReqDefId2a);
            rdMock2a.SetupGet(x => x.Plant).Returns(TestPlant);
            var rdMock2b = new Mock <RequirementDefinition>();

            rdMock2b.SetupGet(x => x.Id).Returns(ReqDefId2b);
            rdMock2b.SetupGet(x => x.Plant).Returns(TestPlant);

            _rtRepositoryMock
            .Setup(r => r.GetRequirementDefinitionsByIdsAsync(new List <int> {
                ReqDefId1, ReqDefId2a
            }))
            .Returns(Task.FromResult(new List <RequirementDefinition> {
                rdMock1.Object, rdMock2a.Object
            }));

            var tf1 = new TagFunction(TestPlant, tagFunctionCode1, "TF1", registerCode1);

            tf1.AddRequirement(new TagFunctionRequirement(TestPlant, Interval1, rdMock1.Object));
            var tf2 = new TagFunction(TestPlant, tagFunctionCode2, "TF2", registerCode2);

            tf2.AddRequirement(new TagFunctionRequirement(TestPlant, Interval2, rdMock2a.Object));
            var voidedTFRequirement = new TagFunctionRequirement(TestPlant, Interval2, rdMock2b.Object);

            voidedTFRequirement.IsVoided = true;
            tf2.AddRequirement(voidedTFRequirement);

            var rdMock3 = new Mock <RequirementDefinition>();

            rdMock3.SetupGet(x => x.Id).Returns(ReqDefId3);
            rdMock3.SetupGet(x => x.Plant).Returns(TestPlant);
            var tf3 = new TagFunction(TestPlant, "TagFunctionCode3", "TF3", "RegisterCodeCode3");

            tf3.AddRequirement(new TagFunctionRequirement(TestPlant, Interval1, rdMock1.Object));
            tf3.AddRequirement(new TagFunctionRequirement(TestPlant, Interval2, rdMock2a.Object));
            tf3.AddRequirement(new TagFunctionRequirement(TestPlant, 3, rdMock3.Object));

            _tfRepositoryMock = new Mock <ITagFunctionRepository>();
            _tfRepositoryMock
            .Setup(x => x.GetAllNonVoidedWithRequirementsAsync())
            .Returns(Task.FromResult(new List <TagFunction> {
                tf1, tf2, tf3
            }));

            _mainTagDetails1 = new PCSTagDetails
            {
                AreaCode              = "AreaCode1",
                AreaDescription       = "AreaDescription1",
                CallOffNo             = "CalloffNo1",
                CommPkgNo             = "CommPkgNo1",
                Description           = "Description1",
                DisciplineCode        = "DisciplineCode1",
                DisciplineDescription = "DisciplineDescription1",
                McPkgNo            = "McPkgNo1",
                PurchaseOrderNo    = "PurchaseOrderNo1",
                TagFunctionCode    = tagFunctionCode1,
                RegisterCode       = registerCode1,
                TagNo              = TestTagNo1,
                ProjectDescription = TestProjectDescription
            };
            _mainTagDetails2 = new PCSTagDetails
            {
                AreaCode              = "AreaCode2",
                AreaDescription       = "AreaDescription2",
                CallOffNo             = "CalloffNo2",
                CommPkgNo             = "CommPkgNo2",
                Description           = "Description2",
                DisciplineCode        = "DisciplineCode2",
                DisciplineDescription = "DisciplineDescription1",
                McPkgNo            = "McPkgNo2",
                PurchaseOrderNo    = "PurchaseOrderNo2",
                TagFunctionCode    = tagFunctionCode2,
                RegisterCode       = registerCode2,
                TagNo              = TestTagNo2,
                ProjectDescription = TestProjectDescription
            };

            IList <PCSTagDetails> mainTagDetailList = new List <PCSTagDetails> {
                _mainTagDetails1, _mainTagDetails2
            };

            _tagApiServiceMock = new Mock <ITagApiService>();
            _tagApiServiceMock
            .Setup(x => x.GetTagDetailsAsync(TestPlant, TestProjectName, new List <string> {
                TestTagNo1, TestTagNo2
            }))
            .Returns(Task.FromResult(mainTagDetailList));

            _command = new AutoScopeTagsCommand(
                new List <string> {
                TestTagNo1, TestTagNo2
            },
                TestProjectName,
                step.Id,
                "Remark",
                "SA");

            _dut = new AutoScopeTagsCommandHandler(
                _projectRepositoryMock.Object,
                _journeyRepositoryMock.Object,
                _modeRepositoryMock.Object,
                _tfRepositoryMock.Object,
                _rtRepositoryMock.Object,
                UnitOfWorkMock.Object,
                PlantProviderMock.Object,
                _tagApiServiceMock.Object);
        }