Пример #1
0
        public void Test_Could_Move_Everywhere()
        {
            Location from = new Location();
            Location to = new Location();

            bool couldMove = _bll.CouldMoveTo(from, to);
            Assert.IsFalse(couldMove);
        }
Пример #2
0
        public void Test_Deny_Create_Same_Door()
        {
            Location from = new Location();
            Location to = new Location();

            _bll.CreateDoorInLocation(from, to, Models.Enums.Directions.North);
            _bll.CreateDoorInLocation(from, to, Models.Enums.Directions.North);
        }
Пример #3
0
        public void Test_Create_First_Location_Ok()
        {
            var location = new Location();
            _bll.CreateLocation(location);

            var locations = _bll.GetAllLocations();

            Assert.AreEqual(1, locations.Count);
        }
Пример #4
0
 public bool CouldMoveTo(Location from, Location to)
 {
     var door = from.Doors.FirstOrDefault(x => x.LocationToGoId == to.LocationId);
     if (door != null)
     {
         // TODO: add conditions if necessary
         return true;
     }
     return false;
 }
Пример #5
0
        public void Test_CouldNot_Move_At_All()
        {
            // No doors in location
            Location from = new Location();
            Location to = new Location();

            bool couldMove = _bll.CouldMoveTo(from, to);

            Assert.IsFalse(couldMove);
        }
Пример #6
0
        public void MoveTo(Hero h, Location from, Location to)
        {
            if (h.CurrentLocationId != from.LocationId)
            {
                throw new ObjectNotHereException("Hero is not in location you want to move from");
            }

            if (_locationBll.CouldMoveTo(from, to) == false)
            {
                throw new CouldNotMoveException("There is no door to desired location");
            }

            h.CurrentLocationId = to.LocationId;
        }
Пример #7
0
        public void Test_Create_First_Door()
        {
            Location from = new Location();
            Location to = new Location();

            bool couldMove = _bll.CouldMoveTo(from, to);

            // No door created
            Assert.IsFalse(couldMove);

            _bll.CreateDoorInLocation(from, to, Models.Enums.Directions.North);

            // Door is created
            couldMove = _bll.CouldMoveTo(from, to);
            Assert.IsTrue(couldMove);

            // Test door is both way
            couldMove = _bll.CouldMoveTo(to, from);
            Assert.IsTrue(couldMove);
        }
        public void Init()
        {
            // TODO: Replace this with fake after real DB is conected
            _locationBll = new LocationBll(new LocationDal());
            _heroBll = new HeroBll(_locationBll);
            _hero = new Hero();

            /*
            *       Hope to get such map
            *               PUB
            *                 |
            *   SCHOOL <->  SQUARE  <-> GYM
            *                 |
            *               HOME
            */

            _home = new Location(1, "Home");
            _square = new Location(2, "Square");
            _school = new Location(3, "School");
            _pub = new Location(4, "Pub");
            _gym = new Location(5, "Gym");
        }
Пример #9
0
        public void CreateDoorInLocation(Location from, Location to, Directions doorsAt)
        {
            // Ensure there is no door at desired direction
            if (from.GetDoorAtDirection(doorsAt) != null)
            {
                throw new DirectionInUseException("There is already door at direction: " + doorsAt);
            }
            // Ensure we could go back in same door and no door exists
            Directions oppositeDirection = GetOppositeDirection(doorsAt);
            if (to.GetDoorAtDirection(oppositeDirection) != null)
            {
                throw new DirectionInUseException("There is door from other location to this");
            }

            var d = new Location.Door();
            d.LocationToGoId = to.LocationId;
            d.Direction = doorsAt;
            from.Doors.Add(d);

            d = new Location.Door();
            d.LocationToGoId = from.LocationId;
            d.Direction = oppositeDirection;
            to.Doors.Add(d);
        }
Пример #10
0
 public void CreateLocation(Location location)
 {
     _locations.Add(location);
 }
Пример #11
0
        public void CreateLocation(Location location)
        {
            if (location == null)
            {
                throw new ArgumentNullException(nameof(location));
            }

            _locationDal.CreateLocation(location);
        }