Example #1
0
 public static Magazine GetDefaultMagazine()
 {
     List<ICarrierPlate> plates = new List<ICarrierPlate>();
     for (int i = 0; i < 4; i++)
     {
         plates.Add(new CarrierPlate { Id = "", Capacity = 5, Recipe = 1 });
     }
     Magazine magazine = new Magazine { Id = "" };
     magazine.NewPlates(plates);
     return magazine;
 }
        private void CompareObjects(PolishingSimulatorPlcCommunication simulator, bool barcodeError, Magazine magazine)
        {
            // IS error flag
            Assert.AreEqual<bool>(simulator.BarcodeError, barcodeError);

            // Magazine ID
            Assert.AreEqual<string>(simulator.MagazineId, magazine.Id);

            // Plates ID's
            Assert.AreEqual<string>(simulator.Plates[0].Id, magazine.Plates[0].Id);
            Assert.AreEqual<string>(simulator.Plates[1].Id, magazine.Plates[1].Id);
            Assert.AreEqual<string>(simulator.Plates[2].Id, magazine.Plates[2].Id);
            Assert.AreEqual<string>(simulator.Plates[3].Id, magazine.Plates[3].Id);

            // Plates recipe's
            Assert.AreEqual<int>(simulator.Plates[0].Recipe, magazine.Plates[0].Recipe);
            Assert.AreEqual<int>(simulator.Plates[1].Recipe, magazine.Plates[1].Recipe);
            Assert.AreEqual<int>(simulator.Plates[2].Recipe, magazine.Plates[2].Recipe);
            Assert.AreEqual<int>(simulator.Plates[3].Recipe, magazine.Plates[3].Recipe);
        }
        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);
            }
        }