public async Task <ActionResult <int> > CreateAreaTag(
            [FromHeader(Name = CurrentPlantMiddleware.PlantHeader)]
            [Required]
            [StringLength(PlantEntityBase.PlantLengthMax, MinimumLength = PlantEntityBase.PlantLengthMin)]
            string plant,
            [FromBody] CreateAreaTagDto dto)
        {
            var requirements = dto.Requirements?
                               .Select(r =>
                                       new RequirementForCommand(r.RequirementDefinitionId, r.IntervalWeeks));

            var command = new CreateAreaTagCommand(
                dto.ProjectName,
                dto.AreaTagType.ConvertToTagType(),
                dto.DisciplineCode,
                dto.AreaCode,
                dto.PurchaseOrderCalloffCode,
                dto.TagNoSuffix,
                dto.StepId,
                requirements,
                dto.Description,
                dto.Remark,
                dto.StorageArea);

            var result = await _mediator.Send(command);

            return(this.FromResult(result));
        }
Beispiel #2
0
        public void Setup_OkState()
        {
            _tagValidatorMock = new Mock <ITagValidator>();

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

            _projectValidatorMock = new Mock <IProjectValidator>();

            _rdValidatorMock = new Mock <IRequirementDefinitionValidator>();
            _rdValidatorMock.Setup(r => r.ExistsAsync(_rdId, default)).Returns(Task.FromResult(true));
            _rdValidatorMock.Setup(r => r.UsageCoversBothForSupplierAndOtherAsync(new List <int> {
                _rdId
            }, default)).Returns(Task.FromResult(true));
            _rdValidatorMock.Setup(r => r.UsageCoversForOtherThanSuppliersAsync(new List <int> {
                _rdId
            }, default)).Returns(Task.FromResult(true));
            _rdValidatorMock.Setup(r => r.UsageCoversForSuppliersAsync(new List <int> {
                _rdId
            }, default)).Returns(Task.FromResult(true));

            _createPreAreaTagCommand = new CreateAreaTagCommand(
                _projectName,
                TagType.PreArea,
                "D",
                "A",
                null,
                null,
                _stepId,
                new List <RequirementForCommand>
            {
                new RequirementForCommand(_rdId, 1)
            },
                "Desc",
                "Remark",
                "SA");

            _createPoAreaTagCommand = new CreateAreaTagCommand(
                _projectName,
                TagType.PoArea,
                "D",
                "A",
                null,
                null,
                _stepId,
                new List <RequirementForCommand>
            {
                new RequirementForCommand(_rdId, 1)
            },
                "Desc",
                "Remark",
                "SA");

            _dut = new CreateAreaTagCommandValidator(
                _tagValidatorMock.Object,
                _stepValidatorMock.Object,
                _projectValidatorMock.Object,
                _rdValidatorMock.Object);
        }
Beispiel #3
0
        public void Validate_ShouldFail_WhenRequirementsNotUnique()
        {
            _rdValidatorMock
            .Setup(r => r.UsageCoversBothForSupplierAndOtherAsync(
                       new List <int> {
                _rdId, _rdId
            }, default))
            .Returns(Task.FromResult(true));

            var command = new CreateAreaTagCommand(
                _projectName,
                TagType.PreArea,
                "DisciplineA",
                "AreaA",
                null,
                null,
                _stepId,
                new List <RequirementForCommand>
            {
                new RequirementForCommand(_rdId, 1),
                new RequirementForCommand(_rdId, 2)
            },
                "DescriptionA",
                "RemarkA",
                "SA_A");

            var result = _dut.Validate(command);

            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.IsTrue(result.Errors[0].ErrorMessage.StartsWith("Requirement definitions must be unique!"));
        }
Beispiel #4
0
        public void Constructor_ShouldSetProperties_WithRequirements()
        {
            var dut = new CreateAreaTagCommand(
                "ProjectNameA",
                TagType.PreArea,
                "DisciplineA",
                "AreaA",
                null,
                null,
                2,
                new List <RequirementForCommand> {
                new RequirementForCommand(11, 12)
            },
                "DescriptionA",
                "RemarkA",
                "SA_A");

            Assert.AreEqual("ProjectNameA", dut.ProjectName);
            Assert.AreEqual("DisciplineA", dut.DisciplineCode);
            Assert.AreEqual("AreaA", dut.AreaCode);
            Assert.AreEqual("DescriptionA", dut.Description);
            Assert.AreEqual("RemarkA", dut.Remark);
            Assert.AreEqual("SA_A", dut.StorageArea);
            Assert.AreEqual(2, dut.StepId);
            Assert.AreEqual(1, dut.Requirements.Count());
            var requirement = dut.Requirements.First();

            Assert.AreEqual(11, requirement.RequirementDefinitionId);
            Assert.AreEqual(12, requirement.IntervalWeeks);
        }
Beispiel #5
0
        public void Constructor_ShouldSetProperties_WithNullLists()
        {
            var dut = new CreateAreaTagCommand("ProjectNameA",
                                               TagType.PreArea,
                                               "DiscA",
                                               "AreaA",
                                               null,
                                               null,
                                               2,
                                               null,
                                               null,
                                               null,
                                               null);

            Assert.IsNotNull(dut.Requirements);
            Assert.AreEqual(0, dut.Requirements.Count());
            Assert.IsNull(dut.Description);
            Assert.IsNull(dut.Remark);
            Assert.IsNull(dut.StorageArea);
        }
        public void Setup()
        {
            // Arrange
            _stepMock = new Mock <Step>();
            _stepMock.SetupGet(s => s.Id).Returns(StepId);
            _stepMock.SetupGet(s => s.Plant).Returns(TestPlant);

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

            _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 rdMock2 = new Mock <RequirementDefinition>();

            rdMock2.SetupGet(x => x.Id).Returns(ReqDefId2);
            rdMock2.SetupGet(x => x.Plant).Returns(TestPlant);
            _rtRepositoryMock
            .Setup(r => r.GetRequirementDefinitionsByIdsAsync(new List <int> {
                ReqDefId1, ReqDefId2
            }))
            .Returns(Task.FromResult(new List <RequirementDefinition> {
                rdMock1.Object, rdMock2.Object
            }));

            _projectApiServiceMock = new Mock <IProjectApiService>();
            _projectApiServiceMock.Setup(s => s.TryGetProjectAsync(TestPlant, TestProjectName))
            .Returns(Task.FromResult(new PCSProject {
                Description = "ProjectDescription"
            }));

            var disciplineCode = "D";

            _disciplineApiServiceMock = new Mock <IDisciplineApiService>();
            _disciplineApiServiceMock.Setup(s => s.TryGetDisciplineAsync(TestPlant, disciplineCode))
            .Returns(Task.FromResult(new PCSDiscipline
            {
                Code        = disciplineCode,
                Description = DisciplineDescription
            }));

            var areaCode = "A";

            _areaApiServiceMock = new Mock <IAreaApiService>();
            _areaApiServiceMock.Setup(s => s.TryGetAreaAsync(TestPlant, areaCode))
            .Returns(Task.FromResult(new PCSArea
            {
                Code        = areaCode,
                Description = AreaDescription
            }));

            _createPreAreaCommand = new CreateAreaTagCommand(
                TestProjectName,
                TagType.PreArea,
                disciplineCode,
                areaCode,
                "notused",
                null,
                StepId,
                new List <RequirementForCommand>
            {
                new RequirementForCommand(ReqDefId1, Interval1),
                new RequirementForCommand(ReqDefId2, Interval2),
            },
                null,
                "Remark",
                "SA");
            _createSiteAreaCommand = new CreateAreaTagCommand(
                TestProjectName,
                TagType.SiteArea,
                disciplineCode,
                areaCode,
                "notused",
                null,
                StepId,
                new List <RequirementForCommand>
            {
                new RequirementForCommand(ReqDefId1, Interval1),
                new RequirementForCommand(ReqDefId2, Interval2),
            },
                null,
                "Remark",
                "SA");
            _createPoAreaWithPurchasedOrderCommand = new CreateAreaTagCommand(
                TestProjectName,
                TagType.PoArea,
                disciplineCode,
                areaCode,
                TestPurchaseOrder,
                null,
                StepId,
                new List <RequirementForCommand>
            {
                new RequirementForCommand(ReqDefId1, Interval1),
                new RequirementForCommand(ReqDefId2, Interval2),
            },
                null,
                "Remark",
                "SA");
            _createPoAreaWithCalloffCommand = new CreateAreaTagCommand(
                TestProjectName,
                TagType.PoArea,
                disciplineCode,
                areaCode,
                $"{TestPurchaseOrder}/{TestCalloff}",
                null,
                StepId,
                new List <RequirementForCommand>
            {
                new RequirementForCommand(ReqDefId1, Interval1),
                new RequirementForCommand(ReqDefId2, Interval2),
            },
                null,
                "Remark",
                "SA");

            _dut = new CreateAreaTagCommandHandler(
                _projectRepositoryMock.Object,
                _journeyRepositoryMock.Object,
                _rtRepositoryMock.Object,
                UnitOfWorkMock.Object,
                PlantProviderMock.Object,
                _projectApiServiceMock.Object,
                _disciplineApiServiceMock.Object,
                _areaApiServiceMock.Object);
        }