public void PolishingPlcIntegrationTest()
        {
            PolishingSimulatorPlcCommunication simulator = PolishingSimulatorPlcCommunication.Create();

            IPolishLinePlc target = new PolishLinePlc(simulator);
            target.Open();

            bool barcodeError = false;
            Magazine magazine = SimulatorHelper.GetDefaultMagazine();

            CompareObjects(simulator, barcodeError, magazine);

            bool isMagazineArrived = target.IsMagazineArrived();
            IPolishingFullStatus status = target.GetFullStatus();
            CompareObjects(simulator, isMagazineArrived, status);

            for (int i = 0; i < 10000; i++)
            {
                // "PLC" randomly clear memory
                if (_random.NextDouble() > 0.40)
                {
                    switch (_random.Next(1, 2))
                    {
                        case 1:
                            magazine = SimulatorHelper.GetDefaultMagazine();
                            simulator.MagazineId = magazine.Id;
                            simulator.Plates[0].Id = magazine.Plates[0].Id;
                            simulator.Plates[0].Recipe = magazine.Plates[0].Recipe;
                            simulator.Plates[1].Id = magazine.Plates[1].Id;
                            simulator.Plates[1].Recipe = magazine.Plates[1].Recipe;
                            simulator.Plates[2].Id = magazine.Plates[2].Id;
                            simulator.Plates[2].Recipe = magazine.Plates[2].Recipe;
                            simulator.Plates[3].Id = magazine.Plates[3].Id;
                            simulator.Plates[3].Recipe = magazine.Plates[3].Recipe;
                            break;
                    }
                }

                // "Information system" randomly write to memory
                if (_random.NextDouble() > 0.50)
                {
                    switch (_random.Next(1, 3))
                    {
                        case 1:
                            barcodeError = (_random.NextDouble() > 0.5) ? true : false;
                            target.WriteBarcodeError(barcodeError);
                            CompareObjects(simulator, barcodeError, magazine);
                            break;
                        case 2:
                            magazine = new Magazine { Id = SimulatorHelper.GetRandomString(8) };
                            magazine.NewPlates(SimulatorHelper.GetPlateList(4));
                            target.ProcessRecipe(magazine);
                            CompareObjects(simulator, barcodeError, magazine);
                            break;
                    }
                }

                ChangeStatusData(simulator);
                isMagazineArrived = target.IsMagazineArrived();
                status = target.GetFullStatus();
                CompareObjects(simulator, isMagazineArrived, status);
            }
        }
Ejemplo n.º 2
0
        public void WriteBarcodeError2Test()
        {
            Mock<ICommunication> plcComm = PlcHelper.GetPlcCommunicationMock();
            PolishLinePlc target = new PolishLinePlc(plcComm.Object);

            target.Open();
            target.WriteBarcodeError(false);

            plcComm.Verify(x => x.Write(It.IsAny<string>()), Times.Exactly(1));
            plcComm.Verify(x => x.Write(PlcHelper.GetBoolWriteCommand(false, 0x121)), Times.Exactly(1));
        }