Ejemplo n.º 1
0
 private BiscuitViewModel ConvertBiscuitDtoToViewModel(BiscuitDto dto)
 {
     return(new BiscuitViewModel
     {
         Id = dto.Id,
         Name = dto.Name
     });
 }
        public BiscuitDto UpdateBiscuit(BiscuitDto biscuitToUpdate)
        {
            var filter = Builders <Biscuit> .Filter.Eq(biscuit => biscuit.Id, biscuitToUpdate.Id);

            var update = Builders <Biscuit> .Update
                         .Set(biscuit => biscuit.Name, biscuitToUpdate.Name)
                         .Set(biscuit => biscuit.Description, biscuitToUpdate.Description)
                         .Set(biscuit => biscuit.Price, biscuitToUpdate.Price);

            var result = _database.GetCollection <Biscuit>("Biscuit").FindOneAndUpdate(filter, update);

            return(new BiscuitDto(result));
        }
        public void BiscuitDto_DtoSetFromEntity()
        {
            var entity = new Biscuit
            {
                Id          = 102,
                Name        = "Tasty biscuit",
                Description = "test description",
                Price       = 12.99
            };

            var result = new BiscuitDto(entity);

            Assert.Equal(entity.Id, result.Id);
            Assert.Equal(entity.Name, result.Name);
            Assert.Equal(entity.Description, result.Description);
            Assert.Equal(entity.Price, result.Price);
        }
        public void ConvertToEntity_SetsEntityCorrectly()
        {
            var dto = new BiscuitDto
            {
                Id          = 1312,
                Name        = "Dto biscuit",
                Description = "test description",
                Price       = 1.99
            };

            var result = dto.ConvertToEntity();

            Assert.Equal(dto.Id, result.Id);
            Assert.Equal(dto.Name, result.Name);
            Assert.Equal(dto.Description, result.Description);
            Assert.Equal(dto.Price, result.Price);
        }
        public void AddBiscuit(BiscuitDto biscuitToAdd)
        {
            var biscuitEntity = biscuitToAdd.ConvertToEntity();

            _database.GetCollection <Biscuit>("Biscuit").InsertOne(biscuitEntity);
        }