Ejemplo n.º 1
0
        public async void BonusCanBeActivatedAlreadyActivatedFailure()
        {
            //Arrange
            var testUser = await _usersRepository.GetUserByEmailAsync("*****@*****.**");

            var getServicesListDto = new GetServicesListDto {
                PageSize = 100
            };
            var allServices = await _servicesService.GetAllServicesAsync(testUser.Id, getServicesListDto);

            var activateBonusDto = new ActivateBonusDto
            {
                ServiceId = allServices.Items.First().Id,
                Promocode = "itpromocode"
            };

            await _servicesService.ActivateBonusAsync(testUser.Id, activateBonusDto);

            var canBeProcessedDto = await _servicesService.BonusCanBeActivatedAsync(testUser.Id, activateBonusDto);

            //Assert
            Assert.False(canBeProcessedDto.CanBeProcessed);
            Assert.Equal((int)AppConsts.HttpStatusCodes.Status409Conflict, canBeProcessedDto.StatusCode);
            Assert.Equal($"Bonus is already activated for the service.", canBeProcessedDto.RejectionReason);
        }
Ejemplo n.º 2
0
        public async void BonusShouldBeActivatedSuccess()
        {
            //Arrange
            var testUser = await _usersRepository.GetUserByEmailAsync("*****@*****.**");

            var getServicesListDto = new GetServicesListDto {
                PageSize = 100
            };
            var allServices = await _servicesService.GetAllServicesAsync(testUser.Id, getServicesListDto);

            var activateBonusDto = new ActivateBonusDto
            {
                ServiceId = allServices.Items.First().Id,
                Promocode = "itpromocode"
            };

            //Act
            await _servicesService.ActivateBonusAsync(testUser.Id, activateBonusDto);

            allServices = await _servicesService.GetAllServicesAsync(testUser.Id, getServicesListDto);

            var service = allServices.Items.Single(s => s.Activated);

            //Assert
            Assert.Equal(service.Id, activateBonusDto.ServiceId);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Obtaines a filtered and paginated list of services
        /// </summary>
        /// <param name="userId">User id (to define activated services)</param>
        /// <param name="getServicesListDto">Model for getting the list with filtering and paging</param>
        /// <returns>Returns the filtered and paginated list of services</returns>
        public async Task <ServiceListDto> GetAllServicesAsync(Guid userId, GetServicesListDto getServicesListDto)
        {
            var services = await PaginatedList <Service> .FromIQueryable(_servicesRepository.GetAllServicesAsync(userId,
                                                                                                                 getServicesListDto.Filter),
                                                                         getServicesListDto.CurrentPage,
                                                                         getServicesListDto.PageSize == 0?_settings.PageSize : getServicesListDto.PageSize);

            var serviceListDto = new ServiceListDto(services, _mapper);

            return(serviceListDto);
        }
Ejemplo n.º 4
0
        public async void ApplyInvalidFilterServicesShouldBeGotSuccess()
        {
            //Arrange
            var getServicesListDto = new GetServicesListDto
            {
                Filter = "some invalid filter"
            };

            //Act
            var services = await _servicesService.GetAllServicesAsync(Guid.NewGuid(), getServicesListDto);

            //Assert
            Assert.Equal(0, services.TotalItems);
            Assert.Empty(services.Items);
        }
Ejemplo n.º 5
0
        public async void AllServicesAllDefaultsShouldBeGotSuccess()
        {
            //Arrange
            var getServicesListDto = new GetServicesListDto {
            };
            var initServices       = InitDefaults.GetInitialServices();

            //Act
            var services = await _servicesService.GetAllServicesAsync(Guid.NewGuid(), getServicesListDto);

            //Assert
            Assert.Equal(services.TotalItems, initServices.Count);
            Assert.Equal(services.Items.Count, _settings.PageSize);
            Assert.Equal(services.PageSize, _settings.PageSize);
            Assert.Equal(1, services.CurrentPage);
            Assert.Equal((int)Math.Ceiling(services.TotalItems / (double)services.PageSize), services.TotalPages);
        }
Ejemplo n.º 6
0
        public async void ApplyFilterServicesShouldBeGotSuccess()
        {
            //Arrange
            var getServicesListDto = new GetServicesListDto
            {
                Filter = "ic"
            };

            var initServicesFiltered = InitDefaults.GetInitialServices()
                                       .Where(s => s.Name.Contains(getServicesListDto.Filter))
                                       .ToList();

            //Act
            var services = await _servicesService.GetAllServicesAsync(Guid.NewGuid(), getServicesListDto);

            //Assert
            Assert.Equal(initServicesFiltered.Count(), services.TotalItems);
            AssertServices(initServicesFiltered, services.Items);
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> GetServiceListAsync(string filter, int currentPage, int pageSize)
        {
            var getServicesListDto = new GetServicesListDto
            {
                Filter      = filter,
                CurrentPage = currentPage,
                PageSize    = pageSize
            };
            var validationResult = new GetPaginatedListDtoValidator().Validate(getServicesListDto);

            if (!validationResult.IsValid)
            {
                return(UnprocessableEntity(new ExceptionMessage(validationResult.Errors.Select(x => x.ErrorMessage))));
            }

            var userId           = Guid.Parse(User.Identity.Name);
            var servicesListDtos = await _servicesService.GetAllServicesAsync(userId, getServicesListDto);

            return(Ok(servicesListDtos));
        }
Ejemplo n.º 8
0
        public async void BonusCanBeActivatedSuccess()
        {
            //Arrange
            var testUser = await _usersRepository.GetUserByEmailAsync("*****@*****.**");

            var getServicesListDto = new GetServicesListDto {
                PageSize = 100
            };
            var allServices = await _servicesService.GetAllServicesAsync(testUser.Id, getServicesListDto);

            var activateBonusDto = new ActivateBonusDto
            {
                ServiceId = allServices.Items.First().Id,
                Promocode = "itpromocode"
            };

            //Act
            var canBeProcessedDto = await _servicesService.BonusCanBeActivatedAsync(testUser.Id, activateBonusDto);

            //Assert
            Assert.True(canBeProcessedDto.CanBeProcessed);
        }