public CharacterEditModel(Character character)
 {
     Id = character.Id;
     Name = character.Name;
     Type = character.Type;
     Price = character.Price;
     Active = character.Active;
     Deleted = character.Deleted;
 }
 internal CharacterListItemModel(Character character)
 {
     name = character.Name;
     price = character.Price;
     created = character.Created;
     type = character.Type;
     active = character.Active;
     deleted = character.Deleted;
 }
 public void Load_should_return_same_character_that_is_in_storage()
 {
     var character = new Character { Name = "Zeratul" };
     var characterDao = new Mock<ICharacterDao>();
     characterDao.Setup(x => x.Load(It.IsAny<string>())).Returns(character);
     ICharacterPresentationService service = new CharacterPresentationService(characterDao.Object);
     var result = service.Load("Zeratul");
     Assert.IsNotNull(result);
     Assert.AreSame(character.Name, result.Name);
 }
 public void List_should_return_same_items_that_are_in_storage()
 {
     var character = new Character {Name = "Zeratul"};
     var characterDao = new Mock<ICharacterDao>();
     characterDao.Setup(x => x.Load()).Returns(new List<Character> { character });
     ICharacterPresentationService service = new CharacterPresentationService(characterDao.Object);
     var result = service.List();
     Assert.AreEqual(1, result.Count);
     Assert.AreSame(character.Name, result.First().Name);
 }
        public void Recover_should_set_character_deleted_to_false()
        {
            var character = new Character { Name = "Zeratul", Deleted = true };
            var characterDao = new Mock<ICharacterDao>();
            characterDao.Setup(x => x.Load(It.IsAny<string>())).Returns(character);

            ICharacterOperationService operationService = new CharacterOperationService(null, characterDao.Object);
            operationService.Recover("Zeratul");

            characterDao.Verify(x => x.Save(It.Is<Character>(c => !c.Deleted && ReferenceEquals(character.Name, c.Name))), Times.Once);
        }
        internal static void MapTo(this CharacterEditModel model, ref Character entity)
        {
            if (model.Id == Guid.Empty)
            {
                entity.Id = Guid.NewGuid();
                entity.Created = DateTime.Now;
            }

            entity.Name = model.Name;
            entity.Price = model.Price;
            entity.Type = model.Type;
            entity.Active = model.Active;
        }
 void ICharacterDao.Save(Character character)
 {
     repository.Save(character);
 }
        public void Save_should_update_character()
        {
            var validationService = new Mock<IValidationService>();
            validationService.Setup(x => x.Validate(It.IsAny<CharacterEditModel>())).Returns(new List<ValidationError>());

            var character = new Character();
            var characterDao = new Mock<ICharacterDao>();
            characterDao.Setup(x => x.Load(It.IsAny<Guid>())).Returns(character);

            ICharacterOperationService operationService = new CharacterOperationService(validationService.Object, characterDao.Object);
            var model = new CharacterEditModel { Id = Guid.NewGuid() };
            var result = operationService.Save(model);
            Assert.IsTrue(result.IsValid);
            characterDao.Verify(x => x.Load(model.Id), Times.Once);
            characterDao.Verify(x => x.Save(It.Is<Character>(c => ReferenceEquals(c, character) && ReferenceEquals(c.Name, model.Name))), Times.Once);
        }