public void AddRoomsTest()
        {
            CampfireState target = CampfireState.Instance;

            target.SetNameAndToken("fred", "9876543210");
            target.AddRoom(1, "Room1", 12);
            target.AddRoom(101, "Room2", 0);

            List <Room> newRooms = new List <Room>();
            Room        rm;

            rm = new Room(3, "Room3");        // new room
            newRooms.Add(rm);

            rm = new Room(101, "Room2");        // duplicate
            newRooms.Add(rm);

            rm = new Room(1, "RoomOne");        // existing room, new name
            newRooms.Add(rm);

            target.AddRooms(newRooms);

            Assert.AreEqual(3, target.Rooms.Count);
            Assert.IsTrue(target.Rooms.Count(r => r.Id == 1 && r.Name == "RoomOne") == 1, "verify renamed room");
            Assert.IsTrue(target.Rooms.Count(r => r.Id == 3 && r.Name == "Room3") == 1, "verify new room");

            CampfireState newCampfireInfo = CampfireState_Accessor.Restore(BackingStorePath);

            Match(target, newCampfireInfo);
        }
        public void Work_FetchNewMessagesForAllRoomsTest()
        {
            CampfireState   campInfo = CampfireState.Instance;
            MockCampfireAPI api      = new MockCampfireAPI();

            List <Message> msgs;

            // Create a new room (at the API level)
            int roomId1 = 123;
            int roomId2 = 1001;
            int userId1 = 100;
            int userId2 = 200;

            api.FakeUsers.Add(new User("Peter", "*****@*****.**", userId1));
            api.FakeUsers.Add(new User("Casey", "*****@*****.**", userId2));

            Room rm1 = new Room(roomId1, "room #1");

            // The room must exist in the API and in cmapfireState
            api.FakeRooms.Add(rm1);
            campInfo.AddRoom(rm1.Id, rm1.Name, 0);

            // add a couple fake messages to room1
            msgs = new List <Message>();
            msgs.Add(new Message(1, Message.MType.EnterMessage, roomId1, userId1, ""));
            msgs.Add(new Message(2, Message.MType.TextMessage, roomId1, userId1, "Hello everyone"));
            api.MessagesInRoom.Add(roomId1, msgs);

            // add room 2
            Room rm2 = new Room(roomId2, "room #2");

            api.FakeRooms.Add(rm2);
            campInfo.AddRoom(rm2.Id, rm2.Name, 0);

            // add a couple fake messages to room1
            msgs = new List <Message>();
            msgs.Add(new Message(3, Message.MType.EnterMessage, roomId2, userId2, ""));
            msgs.Add(new Message(4, Message.MType.TextMessage, roomId2, userId2, "message from user 2"));
            msgs.Add(new Message(5, Message.MType.TextMessage, roomId2, userId1, "message from user 1"));
            api.MessagesInRoom.Add(roomId2, msgs);

            // The process step should now pick up the change and incorporate into campfileState
            MessageProcessor_Accessor.Work_ProcessNewMessagesForAllRooms(campInfo, api);

            // In the "Entered" queue there should be 2 entries
            MessageProcessor_Accessor.ProcessMessages_ProcessQueuedMessages(campInfo, api);
            Assert.AreEqual(2, campInfo.Users.Count);
            Assert.IsTrue(campInfo.Users.Any(u => u.Id == userId1));
            Assert.IsTrue(campInfo.Users.Any(u => u.Id == userId2));

            // In the Text Message queue there should be 3 entries
            MessageProcessor_Accessor.ProcessMessages_ProcessQueuedMessages(campInfo, api);
        }
        public void SaveRestoreTest_RoomsOnly()
        {
            CampfireState target = CampfireState.Instance;

            target.AddRoom(1, "Room1", 12);
            target.AddRoom(101, "Room2", 0);

            Assert.AreEqual(0, target.Users.Count);
            Assert.AreEqual(2, target.Rooms.Count);

            CampfireState newCampfireInfo = CampfireState_Accessor.Restore(BackingStorePath);

            Match(target, newCampfireInfo);
        }
        public void UpdateLastMessageIdTest()
        {
            CampfireState target = CampfireState.Instance;

            target.SetNameAndToken("fred", "9876543210");
            target.AddRoom(1, "Room1", 12);
            target.AddRoom(101, "Room2", 0);

            target.UpdateLastMessageId(101, 1234);

            CampfireState.RoomInfo room = target.Rooms.First(r => r.Id == 101);
            Assert.AreEqual(1234, room.LastMessageId);

            CampfireState newCampfireInfo = CampfireState_Accessor.Restore(BackingStorePath);

            room = newCampfireInfo.Rooms.First(r => r.Id == 101);
            Assert.AreEqual(1234, room.LastMessageId);
        }