public void Setup() { zone = new Objects.Zone.Zone(); room = new Mock <IRoom>(); item = new Mock <IItem>(); npc = new Mock <INonPlayerCharacter>(); room.Setup(e => e.Items).Returns(new List <IItem>() { item.Object }); room.Setup(e => e.NonPlayerCharacters).Returns(new List <INonPlayerCharacter>() { npc.Object }); zone.Rooms.Add(1, room.Object); }
public void Setup() { GlobalReference.GlobalValues = new GlobalValues(); zone = new Objects.Zone.Zone(); room = new Mock <IRoom>(); item = new Mock <IItem>(); npc = new Mock <INonPlayerCharacter>(); otherMob = new Mock <IMobileObject>(); inGameDateTime = new Mock <IInGameDateTime>(); gameDateTime = new Mock <IGameDateTime>(); room1 = new Mock <IRoom>(); room2 = new Mock <IRoom>(); exit1 = new Mock <IExit>(); exit2 = new Mock <IExit>(); room.Setup(e => e.Items).Returns(new List <IItem>() { item.Object }); room.Setup(e => e.NonPlayerCharacters).Returns(new List <INonPlayerCharacter>() { npc.Object }); room.Setup(e => e.OtherMobs).Returns(new List <IMobileObject>() { otherMob.Object }); inGameDateTime.Setup(e => e.GameDateTime).Returns(gameDateTime.Object); gameDateTime.Setup(e => e.AddDays(1)).Returns(gameDateTime.Object); room1.Setup(e => e.East).Returns(exit1.Object); room1.Setup(e => e.Id).Returns(1); room2.Setup(e => e.West).Returns(exit2.Object); room2.Setup(e => e.Id).Returns(2); exit1.Setup(e => e.Zone).Returns(1); exit1.Setup(e => e.Room).Returns(2); exit2.Setup(e => e.Zone).Returns(1); exit2.Setup(e => e.Room).Returns(1); zone.Rooms.Add(1, room.Object); GlobalReference.GlobalValues.GameDateTime = inGameDateTime.Object; }
public void World_LoadWorld_ZoneLoads() { world.Zones.Clear(); //remove the item added from above Mock <IFileIO> fileIO = new Mock <IFileIO>(); Mock <ILogger> logger = new Mock <ILogger>(); Mock <ISerialization> xmlSerializer = new Mock <ISerialization>(); Objects.Zone.Zone realZone = new Objects.Zone.Zone(); Mock <IRoom> room = new Mock <IRoom>(); PropertyInfo info = world.GetType().GetProperty("_zoneIdToFileMap", BindingFlags.Instance | BindingFlags.NonPublic); Mock <ISettings> settings = new Mock <ISettings>(); fileIO.Setup(e => e.GetFilesFromDirectory("zonelocation", "*.zone")).Returns(new string[] { "c:\\zone.zone" }); fileIO.Setup(e => e.ReadAllText("c:\\zone.zone")).Returns("serializedZone"); xmlSerializer.Setup(e => e.Deserialize <Objects.Zone.Zone>("serializedZone")).Returns(realZone); realZone.Rooms.Add(1, room.Object); room.Setup(e => e.NonPlayerCharacters).Returns(new List <INonPlayerCharacter>() { npc.Object }); room.Setup(e => e.Items).Returns(new List <IItem>()); settings.Setup(e => e.ZoneDirectory).Returns("zonelocation"); GlobalReference.GlobalValues.FileIO = fileIO.Object; GlobalReference.GlobalValues.Logger = logger.Object; GlobalReference.GlobalValues.Serialization = xmlSerializer.Object; GlobalReference.GlobalValues.Settings = settings.Object; world.LoadWorld(); npc.VerifySet(e => e.Room = room.Object, Times.Once); Assert.AreSame(realZone, world.Zones[0]); string storedFileName = ((Dictionary <int, string>)info.GetValue(world))[0]; Assert.AreEqual("c:\\zone.zone", storedFileName); }
public void Zone_SeralizeDeserialize() { IZone zone = new Objects.Zone.Zone(); IRoom room = new Objects.Room.Room(); IItem item = new Objects.Item.Item(); INonPlayerCharacter npc = new Objects.Mob.NonPlayerCharacter(); IPlayerCharacter pc = new Objects.Mob.PlayerCharacter(); GlobalReference.GlobalValues.Initilize(); zone.Id = 0; room.Id = 0; item.Level = 3; zone.Rooms.Add(0, room); room.Items.Add(item); room.AddMobileObjectToRoom(npc); room.AddMobileObjectToRoom(pc); npc.Items.Add(item); npc.Level = 1; pc.Items.Add(item); pc.Level = 1; GlobalReference.GlobalValues.World.Zones.Add(0, zone); string serializedZone = GlobalReference.GlobalValues.Serialization.Serialize(zone); IZone zone2 = GlobalReference.GlobalValues.Serialization.Deserialize <Objects.Zone.Zone>(serializedZone); //temp work around room being added 2x IRoom room2; zone2.Rooms.TryGetValue(0, out room2); room2.KeyWords.RemoveAt(0); string serializedZone2 = GlobalReference.GlobalValues.Serialization.Serialize(zone2); Assert.AreEqual(serializedZone, serializedZone2); }
public void World_PerformTick_ReloadZones() { world.Zones.Clear(); //clears out the zone added at initialization PropertyInfo info = world.GetType().GetProperty("_zoneIdToFileMap", BindingFlags.Instance | BindingFlags.NonPublic); Mock <IFileIO> fileIo = new Mock <IFileIO>(); Mock <ISerialization> xmlSerialization = new Mock <ISerialization>(); Objects.Zone.Zone deserializeZone = new Objects.Zone.Zone(); ((Dictionary <int, string>)info.GetValue(world)).Add(0, "blah"); gameDateTime.Setup(e => e.InGameDateTime).Returns(new DateTime(1, 2, 3)); world.Zones.Add(0, zone.Object); fileIo.Setup(e => e.ReadAllText("blah")).Returns("seraializedZone"); xmlSerialization.Setup(e => e.Deserialize <Objects.Zone.Zone>("seraializedZone")).Returns(deserializeZone); GlobalReference.GlobalValues.FileIO = fileIo.Object; GlobalReference.GlobalValues.Serialization = xmlSerialization.Object; world.PerformTick(); Assert.AreEqual(1, world.Zones.Count); Assert.AreSame(deserializeZone, world.Zones[0]); }