public void TestGameLumpAddItem() { var reader = FileReader.OpenStream("testdata/map.bsp"); reader.BaseStream.Seek(sizeof(int) * 2 + (int)LumpType.GameLump * (sizeof(int) * 3 + 4), SeekOrigin.Begin); var newItem = new GameLumpItem(3, 4, 5, new byte[] { 1, 3, 3, 7 }); var lump = new GameLump(reader); var originalLumpCount = lump.LumpItems.Count; lump.LumpItems.Add(newItem); Assert.Equal(originalLumpCount + 1, lump.LumpItems.Count); // Write the LumpItems table into the Data byte array, then parse the data array back into the LumpItems table // Will throw InvalidOperation since we edited the LumpItems but didn't call UpdateOffsets Assert.Throws <InvalidOperationException>(() => lump.Data); lump.UpdateOffsets(lump.Offset); var rawData = lump.Data; lump.Data = rawData; Assert.Equal(originalLumpCount + 1, lump.LumpItems.Count); Assert.Equal(lump.LumpItems[originalLumpCount], newItem); }
public void TestGameLumpItemEquality() { var item1 = new GameLumpItem(3, 4, 5, new byte[] { 1, 3, 3, 7 }); var item2 = new GameLumpItem(3, 4, 5, new byte[] { 1, 3, 3, 7 }); var item3 = new GameLumpItem(5, 4, 5, new byte[] { 1, 3, 3, 7 }); Assert.Equal(item1, item2); Assert.NotEqual(item2, item3); Assert.IsType <int>(item1.GetHashCode()); }