/// <inheritdoc />
        public FarfetchMessage <IEnumerable <ToggleListDto> > GetAll()
        {
            if (_togglerService == null)
            {
                throw new NullReferenceException("Toggler Service hasn't been defined");
            }
            IEnumerable <Toggle>        toggleList    = _togglerService.GetAll();
            IEnumerable <ToggleListDto> toggleDtoList = new List <ToggleListDto>();

            if (toggleList != null && toggleList.Count() != 0)
            {
                toggleDtoList = Mapper.Map <IEnumerable <Toggle>, IEnumerable <ToggleListDto> >(toggleList);
                if (toggleDtoList == null)
                {
                    throw new AutoMapperMappingException("Error mapping types");
                }
            }
            return(new FarfetchMessage <IEnumerable <ToggleListDto> >
            {
                Result = toggleDtoList
            });
        }
Пример #2
0
        public void ShouldUpdateToggleWhenInsertingAgain()
        {
            Models.Service service = new Models.Service
            {
                Name    = "ServiceName",
                Version = "1.0",
                ApiKey  = "apiKey"
            };

            Factory factory = new Factory(FILE_SETTINGS_PATH);

            ApplicationService applicationService = (ApplicationService)factory.GetDbService(AvailableServices.TogglerApplication);

            Assert.NotNull(applicationService);

            service = applicationService.GetByExpression(x => x.Name == service.Name && x.Version == service.Version);
            Assert.NotNull(service);

            TogglerService togglerService = (TogglerService)factory.GetDbService(AvailableServices.Toggler);

            Assert.NotNull(togglerService);

            Toggle toggle = togglerService.GetByExpression(x => x.Name == "toggleName" && x.Value == true);

            Assert.NotNull(toggle);

            togglerService.Insert(toggle);
            var toggleList = togglerService.GetAll()?.ToList();

            Assert.NotNull(toggleList);
            Assert.IsNotEmpty(toggleList);

            var matchingToggles = toggleList.Where(x => x.Name == "toggleName" && x.Value == true);

            Assert.NotNull(matchingToggles);
            Assert.AreEqual(1, matchingToggles.Count());
        }