Example #1
0
        public void ProcProdSched_ReadInvalidQuantityValues()
        {
            // Testing reading an invalid quantity value

            var filepath = TestCommon.TestHelper.TestFileFolder + "\\Neg_ProcessProductionSchedule_InvalidQuantityValue.xml";
            var xmlBytes = System.IO.File.ReadAllBytes(filepath);

            var testObject = new ProcessProductionSchedule(xmlBytes);

            MaterialRequirement materialReq = testObject.ProductionSchedules[0].
                                              ProductionRequests[0].SegmentRequirements[0].MaterialRequirements[0];

            QuantityValue quantityDouble  = materialReq.Quantities[0];
            QuantityValue quantityBoolean = materialReq.Quantities[1];
            QuantityValue quantityInt     = materialReq.Quantities[2];

            // To make sure the raw values have been received as expected:
            Assert.AreEqual("41fs.9", quantityDouble.RawQuantityString);
            Assert.AreEqual("faflse", quantityBoolean.RawQuantityString);
            Assert.AreEqual("0r3", quantityInt.RawQuantityString);

            // Double
            TestCommon.TestHelper.AssertInvalidOperationException(() =>
            {
                quantityDouble.TryParseValueAsXmlDouble();
            },
                                                                  "Failed to parse double");

            // Boolean
            TestCommon.TestHelper.AssertInvalidOperationException(() =>
            {
                quantityBoolean.TryParseValueAsXmlBoolean();
            },
                                                                  "Failed to parse boolean");

            // Int32 (int)
            TestCommon.TestHelper.AssertInvalidOperationException(() =>
            {
                quantityInt.TryParseValueAsXmlInt();
            },
                                                                  "Failed to parse int");

            // Int64 (long)
            TestCommon.TestHelper.AssertInvalidOperationException(() =>
            {
                // Parsing the same value as for Int32
                quantityInt.TryParseValueAsXmlLong();
            },
                                                                  "Failed to parse long");
        }
Example #2
0
        private ProcessProductionSchedule CreateObjectForTestWrite()
        {
            // Applying identifiers (such as "SEG1") to items to enable a
            // verification that this test implementation has same items
            // as those in other environments, particularly Java.

            // SEG1a Creating a segment requirement
            SegmentRequirement segReq1 = new SegmentRequirement
            {
                ProcessSegmentIdentifier = new IdentifierType("1"),
                EarliestStartTime        = ParseDateTimeInUtc("2019-05-09T13:36:02Z"),
                LatestEndTime            = ParseDateTimeInUtc("2019-05-09T13:37:02Z")
            };

            // EQ1 Add equipment requirement
            EquipmentRequirement eqReq = new EquipmentRequirement()
            {
                Quantities = new List <QuantityValue>()
                {
                    new QuantityValue(true)
                }
            };

            segReq1.EquipmentRequirements.Add(eqReq);

            // MAT1 Add material requirement
            MaterialRequirement matReq = new MaterialRequirement()
            {
                MaterialDefinitionIdentifiers = new List <IdentifierType>()
                {
                    new IdentifierType("slag")
                },

                MaterialLotIdentifiers = new List <IdentifierType>()
                {
                    new IdentifierType("my-lot-1")
                },

                MaterialUse = new MaterialUse(MaterialUseType.Produced),

                Quantities = new List <QuantityValue>()
                {
                    new QuantityValue(12.2)
                    {
                        UnitOfMeasure = "t",
                        Key           = new IdentifierType("my-mat-key")
                    }
                },

                AssemblyRequirements = new List <MaterialRequirement>()
                {
                    new MaterialRequirement()
                    {
                        MaterialDefinitionIdentifiers = new List <IdentifierType>()
                        {
                            new IdentifierType("Ni")
                        }
                    }
                }
            };

            segReq1.MaterialRequirements.Add(matReq);

            // SEG1-1 Add nested segment requirement
            segReq1.SegmentRequirements.Add(new SegmentRequirement()
            {
                EarliestStartTime = ParseDateTimeInUtc("2019-08-29T15:31:38Z")
            });

            // PROD1a Create one production request (for the unit "psc3")
            ProductionRequest request1 = new ProductionRequest
            {
                // PROD1-ID Set identifier
                Identifier = new IdentifierType("some-id"),

                // PROD1-HS Set hierarchy scope
                HierarchyScopeObj = new HierarchyScope(
                    new IdentifierType("psc3"),
                    EquipmentElementLevelType.ProcessCell
                    ),

                SegmentRequirements = new List <SegmentRequirement>()
                {
                    // SEG1b Add segment requirement to production request
                    segReq1,

                    // SEG2 Add another (empty) segment requirement
                    new SegmentRequirement()
                }
            };

            // SCH Create schedule object
            ProductionSchedule schedule = new ProductionSchedule()
            {
                ProductionRequests = new List <ProductionRequest>()
                {
                    // PROD1b Add the production request to schedule
                    request1,

                    // PROD2 Adding another (empty) production request
                    new ProductionRequest()
                }
            };

            // PROPS Creating object to be serialised
            ProcessProductionSchedule testObject1 = new ProcessProductionSchedule()
            {
                // PROPS-CR Set creation time
                CreationDateTime = ParseDateTimeInUtc("2019-05-09T12:20:19Z")
            };

            // Add schedule to the test object
            testObject1.ProductionSchedules.Add(schedule);
            return(testObject1);
        }
Example #3
0
        public void ProcProdSched_Write()
        {
            // Serialising, validating and deserialising
            byte[] xmlData = CreateObjectForTestWrite().ToXmlBytes();
            Validate(xmlData);
            ProcessProductionSchedule testObject2 = new ProcessProductionSchedule(xmlData);

            // Assert creation time
            TestCommon.TestHelper.AssertDateTime(ParseDateTimeInUtc("2019-05-09T12:20:19Z"), testObject2.CreationDateTime);

            ProductionSchedule schedule = testObject2.ProductionSchedules[0];

            // Assert request count
            Assert.AreEqual(2, schedule.ProductionRequests.Count);

            // Asserting a production request
            ProductionRequest request1 = schedule.ProductionRequests[0];

            Assert.AreEqual(2, request1.SegmentRequirements.Count);

            // Asserting identifier
            Assert.AreEqual("some-id", request1.Identifier.Value);

            // Asserting a hierarchy scope
            Assert.AreEqual("psc3", request1.HierarchyScopeObj.EquipmentIdentifier.Value);
            Assert.AreEqual(EquipmentElementLevelType.ProcessCell, request1.HierarchyScopeObj.EquipmentElementLevel);

            // Asserting a segment requirement
            SegmentRequirement segReq = request1.SegmentRequirements[0];

            Assert.AreEqual("1", segReq.ProcessSegmentIdentifier.Value);
            AssertDateTime(ParseDateTimeInUtc("2019-05-09T13:36:02Z"), segReq.EarliestStartTime.Value);
            AssertDateTime(ParseDateTimeInUtc("2019-05-09T13:37:02Z"), segReq.LatestEndTime.Value);
            Assert.AreEqual(1, segReq.MaterialRequirements.Count);
            Assert.AreEqual(1, segReq.EquipmentRequirements.Count);

            // Asserting nested segment requirement
            SegmentRequirement segReqNested = segReq.SegmentRequirements[0];

            AssertDateTime(ParseDateTimeInUtc("2019-08-29T15:31:38Z"), segReqNested.EarliestStartTime.Value);

            // Asserting equipment requirement
            EquipmentRequirement eqReq = segReq.EquipmentRequirements[0];

            Assert.AreEqual(1, eqReq.Quantities.Count);
            Assert.IsTrue(eqReq.Quantities[0].TryParseValueAsXmlBoolean());

            MaterialRequirement matReq = segReq.MaterialRequirements[0];

            // Asserting material definition ID
            Assert.AreEqual(1, matReq.MaterialDefinitionIdentifiers.Count);
            Assert.AreEqual("slag", matReq.MaterialDefinitionIdentifiers[0].Value);

            // Asserting a material lot ID
            Assert.AreEqual(1, matReq.MaterialLotIdentifiers.Count);
            Assert.AreEqual("my-lot-1", matReq.MaterialLotIdentifiers[0].Value);

            // Asserting material use
            Assert.AreEqual(MaterialUseType.Produced, matReq.MaterialUse.Value);

            // Asserting a material quantity
            Assert.AreEqual(1, matReq.Quantities.Count);
            QuantityValue quantity = matReq.Quantities[0];

            Assert.AreEqual("12.2", quantity.RawQuantityString);
            Assert.AreEqual(12.2, quantity.TryParseValueAsXmlDouble(), 0.001);
            Assert.AreEqual("t", quantity.UnitOfMeasure);
            Assert.AreEqual(DataType.TypeType.doubleXml, quantity.DataType.Type);
            Assert.AreEqual("my-mat-key", quantity.Key.Value);

            // Asserting an assembly requirement
            Assert.AreEqual(1, matReq.AssemblyRequirements.Count);
            Assert.AreEqual("Ni", matReq.AssemblyRequirements[0].MaterialDefinitionIdentifiers[0].Value);
        }