Пример #1
0
        private static void CheckEntityDtoWithItems(TypeModel model, string message)
        {
            var entity = new EntityDTO()
            {
                Id = 1
            };
            var healthComponent = new HealthDTO()
            {
                CurrentHealth = 100, Owner = entity, Name = "Health", Id = 2
            };

            entity.Components.Add(healthComponent);
            var locationComponent = new PhysicalLocationDTO()
            {
                X = 1, Y = 2, Owner = entity, Name = "PhysicalLocation", Id = 3
            };

            entity.Components.Add(locationComponent);

            MemoryStream memstream2 = new MemoryStream();

            model.Serialize(memstream2, entity);
            memstream2.Seek(0, SeekOrigin.Begin);
            var result2 = (EntityDTO)model.Deserialize(memstream2, null, typeof(EntityDTO));

            Assert.AreEqual(1, result2.Id, message + ":Id");
            Assert.AreEqual(2, result2.Components.Count, message + ":Count");
            // These two tests are lame and will not be used for long
            Assert.AreEqual(typeof(HealthDTO), result2.Components.First().GetType(), message + ":First");
            Assert.AreEqual(typeof(PhysicalLocationDTO), result2.Components.Last().GetType(), message + ":Last");
        }
Пример #2
0
        private static void CheckEntityDtoWithItems(TypeModel model, string message) {
            var entity = new EntityDTO() { Id = 1 };
            var healthComponent = new HealthDTO() { CurrentHealth = 100, Owner = entity, Name = "Health", Id = 2 };
            entity.Components.Add(healthComponent);
            var locationComponent = new PhysicalLocationDTO() { X = 1, Y = 2, Owner = entity, Name = "PhysicalLocation", Id = 3 };
            entity.Components.Add(locationComponent);

            MemoryStream memstream2 = new MemoryStream();
            model.Serialize(memstream2, entity);
            memstream2.Seek(0, SeekOrigin.Begin);
            var result2 = (EntityDTO)model.Deserialize(memstream2, null, typeof(EntityDTO));

            Assert.AreEqual(1, result2.Id, message + ":Id");
            Assert.AreEqual(2, result2.Components.Count, message + ":Count");
            // These two tests are lame and will not be used for long
            Assert.AreEqual(typeof(HealthDTO), result2.Components.First().GetType(), message + ":First");
            Assert.AreEqual(typeof(PhysicalLocationDTO), result2.Components.Last().GetType(), message + ":Last");
        }