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); }
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); }
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; }
public Room Clone() { var clonedRoom = new Room(Name, null, null); foreach (Furniture furniture in Furniture) { clonedRoom.Furniture.Add(furniture.Clone()); } return clonedRoom; }
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")); }
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); }
public void CantMoveNotExistentFurniture() { Room room = new Room("bedroom", null, null); Room anotherRoom = new Room("room", null, null); room.Move("nonexistent furniture", anotherRoom); }
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); }
public void MoveAll(Room anotherRoom) { while (Furniture.Count > 0) { Furniture furniture = Furniture.First(); Move(furniture, anotherRoom); } }
private void OnFurnitureRemoved(Furniture furnitureRemoved, Room newRoom) { FurnitureRemovedEventHandler handler = FurnitureRemoved; if (handler != null) handler(this, furnitureRemoved, newRoom); }
private void Move(Furniture furniture, Room anotherRoom) { //TODO: add transaction Furniture.Remove(furniture); anotherRoom.Furniture.Add(furniture); OnFurnitureRemoved(furniture, anotherRoom); }
private void OnRoomRemoved(Room roomRemoved, Room anotherRoom) { RoomRemovedEventHandler handler = RoomRemoved; if (handler != null) handler(this, roomRemoved, anotherRoom); }
private void OnRoomAdded(Room roomadded) { RoomAddedEventHandler handler = RoomAdded; if (handler != null) handler(this, roomadded); }