Esempio n. 1
0
        public void CanMoveFurnitureToAnotherRoom()
        {
            int removeEventsInvokedCount = 0;
            Room room = new Room("bedroom", null, (sender, remoed, newRoom) =>
            {
                removeEventsInvokedCount += 1;
            });

            const string sofaType = "Sofa";
            room.CreateFurniture(sofaType);
            room.CreateFurniture(sofaType);
            const string wardrobeType = "Wardrobe";
            room.CreateFurniture(wardrobeType);
            IList<Furniture> furnitures = room.GetFurnitures();
            Assert.AreEqual(3, furnitures.Count);

            Room anotherRoom = new Room("living room", null, null);
            room.Move(sofaType, anotherRoom);
            Assert.AreEqual(1, removeEventsInvokedCount--, "There are no event invoked when furniture was moved");
            IList<Furniture> anotherRoomfurnitures = anotherRoom.GetFurnitures();
            Assert.AreEqual(2, furnitures.Count);
            Assert.AreEqual(1, anotherRoomfurnitures.Count);

            room.Move(sofaType, anotherRoom);
            Assert.AreEqual(1, removeEventsInvokedCount--, "There are no event invoked when furniture was moved");
            Assert.AreEqual(1, furnitures.Count);
            Assert.AreEqual(2, anotherRoomfurnitures.Count);

            room.Move(wardrobeType, anotherRoom);
            Assert.AreEqual(1, removeEventsInvokedCount--, "There are no event invoked when furniture was moved");
            Assert.AreEqual(0, furnitures.Count);
            Assert.AreEqual(3, anotherRoomfurnitures.Count);
        }
Esempio n. 2
0
        public void CanAddNewFurnitureToRoom()
        {
            int addedEventsInvokedCount = 0;
            Room room = new Room("bedroom", (sender, added) =>
            {
                addedEventsInvokedCount += 1;
            }, null);

            IList<Furniture> furnitures = room.GetFurnitures();
            Assert.AreEqual(0, furnitures.Count);

            const string furnitureType = "Sofa";
            room.CreateFurniture(furnitureType);
            Assert.AreEqual(1, addedEventsInvokedCount--, "There are no event invoked when furniture was added");
            Assert.AreEqual(1, furnitures.Count);
            Assert.AreEqual(furnitureType, furnitures.First().Type);

            room.CreateFurniture(furnitureType);
            Assert.AreEqual(1, addedEventsInvokedCount--, "There are no event invoked when furniture was added");
            Assert.AreEqual(2, furnitures.Count);
            Assert.AreEqual(furnitureType, furnitures.Last().Type);

            const string anotherFurnitureType = "Wardrobe";
            room.CreateFurniture(anotherFurnitureType);
            Assert.AreEqual(1, addedEventsInvokedCount--, "There are no event invoked when furniture was added");
            Assert.AreEqual(3, furnitures.Count);
            Assert.AreEqual(anotherFurnitureType, furnitures.Last().Type);
        }
Esempio n. 3
0
 public Room CreateRoom(string name)
 {
     Room newRoom = new Room(name, (sender, added) => OnChanged(this), (sender, removed, room) => OnChanged(this));
     Rooms.Add(newRoom);
     OnRoomAdded(newRoom);
     return newRoom;
 }
Esempio n. 4
0
 public Room Clone()
 {
     var clonedRoom = new Room(Name, null, null);
     foreach (Furniture furniture in Furniture)
     {
         clonedRoom.Furniture.Add(furniture.Clone());
     }
     return clonedRoom;
 }
Esempio n. 5
0
 public void CanListingRoom()
 {
     Room room = new Room("bedroom", null,null);
     room.CreateFurniture("sofa");
     room.CreateFurniture("chair");
     var listing = room.Listing();
     Assert.IsNotNull(listing);
     Assert.IsTrue(listing.Contains("bedroom"));
     Assert.IsTrue(listing.Contains("sofa"));
     Assert.IsTrue(listing.Contains("chair"));
 }
Esempio n. 6
0
 public void Move(string furnitureType, Room anotherRoom)
 {
     if (this == anotherRoom) return;
     foreach (Furniture furniture in Furniture)
     {
         if (furniture.Type == furnitureType)
         {
             Move(furniture, anotherRoom);
             return;
         }
     }
     throw new NoFurnitureFoundException(furnitureType);
 }
Esempio n. 7
0
 public void CantMoveNotExistentFurniture()
 {
     Room room = new Room("bedroom", null, null);
     Room anotherRoom = new Room("room", null, null);
     room.Move("nonexistent furniture", anotherRoom);
 }
Esempio n. 8
0
 public void NothingHappendWhenMovingFurnitureToSameRoom()
 {
     int addEventsInvokedCount = 0;
     int removeEventsInvokedCount = 0;
     Room room = new Room("bedroom", (sender, added) =>
     {
         addEventsInvokedCount += 1;
     }, (sender, remoed, newRoom) =>
     {
         removeEventsInvokedCount += 1;
     });
     const string sofaType = "Sofa";
     room.CreateFurniture(sofaType);
     room.Move(sofaType, room);
     Assert.AreEqual(1, addEventsInvokedCount);
     Assert.AreEqual(0, removeEventsInvokedCount);
 }
Esempio n. 9
0
 public void MoveAll(Room anotherRoom)
 {
     while (Furniture.Count > 0)
     {
         Furniture furniture = Furniture.First();
         Move(furniture, anotherRoom);
     }
 }
Esempio n. 10
0
 private void OnFurnitureRemoved(Furniture furnitureRemoved, Room newRoom)
 {
     FurnitureRemovedEventHandler handler = FurnitureRemoved;
     if (handler != null) handler(this, furnitureRemoved, newRoom);
 }
Esempio n. 11
0
 private void Move(Furniture furniture, Room anotherRoom)
 {
     //TODO: add transaction
     Furniture.Remove(furniture);
     anotherRoom.Furniture.Add(furniture);
     OnFurnitureRemoved(furniture, anotherRoom);
 }
Esempio n. 12
0
 private void OnRoomRemoved(Room roomRemoved, Room anotherRoom)
 {
     RoomRemovedEventHandler handler = RoomRemoved;
     if (handler != null) handler(this, roomRemoved, anotherRoom);
 }
Esempio n. 13
0
 private void OnRoomAdded(Room roomadded)
 {
     RoomAddedEventHandler handler = RoomAdded;
     if (handler != null) handler(this, roomadded);
 }