Пример #1
0
        public void ShouldGetFormattedMessageOfAvaialbeBoxes()
        {
            var cabinet = new Cabinet(2);
            var bag = new Bag();
            cabinet.Store(bag);
            var message = cabinet.ReportEmptyBox(new EmptyBoxReporter());

            Assert.AreEqual(message, string.Format("Cabinet{0}:{1}\n", cabinet.GetHashCode(), cabinet.AvailableBoxes()));
            Console.Out.WriteLine(message);
        }
Пример #2
0
        public void ShouldStoreBagInTheSecondAvailableCabinetIfFirstIsFull()
        {
            var cabinet1 = new Cabinet(1);
            cabinet1.Store(new Bag());
            var cabinet2 = new Cabinet(1);
            var cabinets = new List<Cabinet> {cabinet1, cabinet2};

            var robot = new Robot(cabinets, new SequentialSelector(cabinets));
            var ticket = robot.Store(new Bag());

            Assert.IsNotNull(ticket);
            Assert.AreEqual(0, cabinet2.AvailableBoxes());
        }
Пример #3
0
        public void ShouldManagerManageOtherMangers()
        {
            var cabinet1 = new Cabinet(2);
            var manager1 = new Manager(new List<IStoreable> {cabinet1});

            var manager = new Manager(new List<IStoreable> {manager1});

            var storedBag = new Bag();
            var ticket = manager.Store(storedBag);
            Assert.AreEqual(1, cabinet1.AvailableBoxes());

            var pickedBag = manager.Pick(ticket);
            Assert.AreSame(storedBag, pickedBag);
        }
Пример #4
0
        public void ShouldStoreBagToCabinetWithHighestVacancyRate()
        {
            var cabinet1 = new Cabinet(2);
            cabinet1.Store(new Bag());

            var cabinet2 = new Cabinet(5);
            cabinet2.Store(new Bag());
            cabinet2.Store(new Bag());
            cabinet2.Store(new Bag());

            var cabinets = new List<Cabinet> { cabinet1, cabinet2 };
            var superRobot = new Robot(cabinets, new HighestVacancyRateSelector(cabinets));
            superRobot.Store(new Bag());

            Assert.AreEqual(0, cabinet1.AvailableBoxes());
            Assert.AreEqual(2, cabinet2.AvailableBoxes());
        }
Пример #5
0
        public void ShouldGetFormattedAvailbeBoxesMessagesForAllCabinets()
        {
            var cabinet1 = new Cabinet(1);
            cabinet1.Store(new Bag());
            var cabinet2 = new Cabinet(1);
            var cabinets = new List<Cabinet> { cabinet1, cabinet2 };

            var robot = new Robot(cabinets, new HighestVacancyRateSelector(cabinets));
            robot.Store(new Bag());
            var message = robot.ReportEmptyBox(new EmptyBoxReporter());

            Assert.AreEqual(message, string.Format("SuperRobot{0}\n  Cabinet{1}:{2}\n  Cabinet{3}:{4}\n",
                                                   robot.GetHashCode(),
                                                   cabinet1.GetHashCode(), cabinet1.AvailableBoxes(),
                                                   cabinet2.GetHashCode(), cabinet2.AvailableBoxes()
                                         ));
        }
Пример #6
0
        public void ShouldManageMutipleRobots()
        {
            var cabinet1 = new Cabinet(10);
            var cabinets1 = new List<Cabinet> {cabinet1};
            var robot = new Robot(cabinets1, new SequentialSelector(cabinets1));

            var cabinet2 = new Cabinet(5);
            var cabinets2 = new List<Cabinet> {cabinet2};
            var smartRobot = new Robot(cabinets2, new MostAvailableSelector(cabinets2));

            var cabinet3 = new Cabinet(4);
            var cabinets3 = new List<Cabinet> {cabinet3};
            var superRobot = new Robot(cabinets3, new HighestVacancyRateSelector(cabinets3));

            var manager = new Manager(new List<IStoreable> {robot, smartRobot, superRobot});

            manager.Store(new Bag());

            Assert.AreEqual(9, cabinet1.AvailableBoxes());
        }
Пример #7
0
        public void ShouldGetFormattedAvailbeBoxesMessagesFromAllManagedCabinets()
        {
            var cabinet1 = new Cabinet(10);
            var cabinets1 = new List<Cabinet> {cabinet1};
            var robot = new Robot(cabinets1, new SequentialSelector(cabinets1));
            var cabinet2 = new Cabinet(2);
            var manager = new Manager(new List<IStoreable> {robot, cabinet2});
            manager.Store(new Bag());

            var message = manager.ReportEmptyBox(new EmptyBoxReporter());

            Assert.AreEqual(string.Format("Manager{0}\n" +
                                                   "  Robot{1}\n" +
                                                   "    Cabinet{2}:{3}\n"+
                                                   "  Cabinet{4}:{5}\n",
                                                   manager.GetHashCode(),
                                                   robot.GetHashCode(),
                                                   cabinet1.GetHashCode(), cabinet1.AvailableBoxes(),
                                                   cabinet2.GetHashCode(), cabinet2.AvailableBoxes()

                                         ), message);
        }
Пример #8
0
 public void ShouldReturnAvailableBoxNumber()
 {
     var cabinet = new Cabinet(1);
     Assert.AreEqual(1, cabinet.AvailableBoxes());
 }
Пример #9
0
        public void ShouldStoreBagWithDirectlyByCabinet()
        {
            var cabinet = new Cabinet(10);
            var manager = new Manager(new List<IStoreable> {cabinet});
            var storedBag = new Bag();

            var ticket = manager.Store(storedBag);

            Assert.AreEqual(9, cabinet.AvailableBoxes());

            var pickedBag = manager.Pick(ticket);
            Assert.AreSame(storedBag, pickedBag);
        }
Пример #10
0
        public void ShouldStoreBagByAnyRobot()
        {
            var cabinet = new Cabinet(10);
            var cabinets1 = new List<Cabinet> {cabinet};
            var robot = new Robot(cabinets1, new SequentialSelector(cabinets1));
            var manager = new Manager(new List<IStoreable> {robot});

            var storedBag = new Bag();
            var ticket = manager.Store(storedBag);

            Assert.AreEqual(9, cabinet.AvailableBoxes());
            Assert.AreSame(storedBag, manager.Pick(ticket));
        }
Пример #11
0
        public void ShouldStoreBagSuccessfullyInFirstAvailableBox()
        {
            var cabinet1 = new Cabinet(1);
            var cabinet2 = new Cabinet(1);
            var cabinets = new List<Cabinet> {cabinet1, cabinet2};

            var robot = new Robot(cabinets, new SequentialSelector(cabinets));
            var ticket = robot.Store(new Bag());

            Assert.IsNotNull(ticket);
            Assert.AreEqual(0, cabinet1.AvailableBoxes());
        }