Beispiel #1
0
        public void FromFoodDto_MapFoodFromDtoToModel()
        {
            Guid   id           = new Guid("0f8fad5b-d9cb-469f-a165-70867728950e");
            string name         = "Test food";
            int    kcal         = 100;
            float  protein      = 5.5f;
            bool   isVegetarian = true;

            FoodDto foodDto = new FoodDto()
            {
                Id           = id,
                Name         = name,
                Kcal         = kcal,
                Protein      = protein,
                IsVegetarian = isVegetarian
            };

            DtoModelMapper mapper = new DtoModelMapper();

            Food food = mapper.FromFoodDto(foodDto);

            Assert.AreEqual(id, food.Id, "Copied 'Id' has invalid value");
            Assert.AreEqual(name, food.Name, "Copied 'name' has invalid value");
            Assert.AreEqual(kcal, food.Kcal, "Copied 'kcal' has invalid value");
            Assert.AreEqual(protein, food.Protein, "Copied 'protein' has invalid value");
            Assert.AreEqual(isVegetarian, food.IsVegetarian, "Copied 'is vegetarian' has invalid value");
        }
Beispiel #2
0
        public CartService(IFoodRepository foodRepository, IUserRepository userRepository, DtoModelMapper dtoModelMapper)
        {
            _userRepository = userRepository;
            _foodRepository = foodRepository;

            _dtoModelMapper = dtoModelMapper;
        }
Beispiel #3
0
        public CartService()
        {
            _userRepository = new UserRepository(DataStore.Instance.State.Users);
            _foodRepository = new FoodRepository(DataStore.Instance.State.Foods);

            _dtoModelMapper = new DtoModelMapper();
        }
Beispiel #4
0
        public override async Task <IQueryable <ChangeSetDto> > GetAll(CancellationToken cancellationToken)
        {
            // We can declare a view for following sql query in database and then map our dto directly to view using ef db context:
            // select *, (case (((select count(1) from Deliveries as Delivery where ChangeSet.Id = Delivery.ChangeSetId ))) when (select count(1) from Customers) then 1 else 0 end) as IsDeliveredToAll from ChangeSets as ChangeSet
            // or we can use ef core execute sql which returns IQueryable
            // Note: _changeSetsRepository.GetAll(changeSet => new ChangeSetDto { Id = changeSet.Id , ... , IsDeliveredToAll = changeSet.Deliveries.Count() == customersQuery.Count() }); results into problematic sql.

            // The downside of following code are its database round trips.

            int customersCount = await CustomersRepository.GetAll().CountAsync(cancellationToken);

            return(DtoModelMapper.FromModelQueryToDtoQuery(_changeSetsRepository.GetAll(), parameters: new { customersCount = customersCount }));
        }
Beispiel #5
0
        public void ToInformationDto_MapInformationFromModelToDto()
        {
            Guid   id        = new Guid("0f8fad5b-d9cb-469f-a165-70867728950e");
            string content   = "Content test";
            bool   isDeleted = false;

            Information information = new Information()
            {
                Id        = id,
                IsDeleted = isDeleted,
                Content   = content
            };

            DtoModelMapper mapper = new DtoModelMapper();

            InformationDto informationDto = mapper.ToInformationDto(information);

            Assert.AreEqual(id, informationDto.Id, "Copied 'Id' has invalid value");
            Assert.AreEqual(content, informationDto.Content, "Copied 'content' has invalid value");
            Assert.AreEqual(isDeleted, informationDto.IsDeleted, "Copied 'is deleted' has invalid value");
        }
Beispiel #6
0
        public void ToUserDto_MapUserFromModelToDto()
        {
            Guid   id        = new Guid("0f8fad5b-d9cb-469f-a165-70867728950e");
            string login     = "******";
            string firstName = "John";
            string phone     = "123123123";

            User user = new User()
            {
                Id        = id,
                Login     = login,
                FirstName = firstName,
                Phone     = phone
            };

            DtoModelMapper mapper = new DtoModelMapper();

            UserDto userDto = mapper.ToUserDto(user);

            Assert.AreEqual(id, userDto.Id, "Copied 'Id' has invalid value");
            Assert.AreEqual(login, userDto.Login, "Copied 'login' has invalid value");
            Assert.AreEqual(firstName, userDto.FirstName, "Copied 'first name' has invalid value");
            Assert.AreEqual(phone, userDto.Phone, "Copied 'phone' has invalid value");
        }
 protected virtual TModel FromDtoToModel(TDto dto)
 {
     return(DtoModelMapper.FromDtoToModel(dto));
 }
 public virtual async Task <IQueryable <TDto> > GetAll(CancellationToken cancellationToken)
 {
     return(DtoModelMapper.FromModelQueryToDtoQuery(await Repository.GetAllAsync(cancellationToken)));
 }
 public InformationService(IInformationRepository informationRepository, DtoModelMapper modelMapper)
 {
     _informationRepository = informationRepository;
     _modelMapper           = modelMapper;
 }
        public InformationService()
        {
            _informationRepository = new InformationRepository(DataStore.Instance.State.Informations);

            _modelMapper = new DtoModelMapper();
        }
Beispiel #11
0
 public FoodService(IFoodRepository foodRepository, DtoModelMapper modelMapper)
 {
     _foodRepository = foodRepository;
     _modelMapper    = modelMapper;
 }
Beispiel #12
0
 public FoodService()
 {
     _foodRepository = new FoodRepository(DataStore.Instance.State.Foods);
     _modelMapper    = new DtoModelMapper();
 }
 public virtual IQueryable <TDto> GetAll()
 {
     return(DtoModelMapper.FromModelQueryToDtoQuery(Repository.GetAll()));
 }
 public UserService(IUserRepository userRepository, DtoModelMapper modelMapper)
 {
     _userRepository = userRepository;
     _modelMapper    = modelMapper;
 }
 public UserService()
 {
     _userRepository = new UserRepository(DataStore.Instance.State.Users);
     _modelMapper    = new DtoModelMapper();
 }
        public override IQueryable <ChangeSetDto> GetAll()
        {
            IQueryable <Delivery> deliveriesQuery = DeliveriesRepository.GetAll();

            return(DtoModelMapper.FromModelQueryToDtoQuery(_changeSetsRepository.GetAll(), parameters: new { deliveriesQuery = deliveriesQuery }));
        }