/// <inheritdoc />
        public FarfetchMessage <ToggleDto> Get(Guid id)
        {
            if (_togglerService == null)
            {
                throw new NullReferenceException("Toggler Service hasn't been defined");
            }
            Toggle toggle = _togglerService.GetById(id);

            if (toggle == null)
            {
                return(new FarfetchMessage <ToggleDto>
                {
                    Result = null
                });
            }
            ToggleDto toggleDto = Mapper.Map <Toggle, ToggleDto>(toggle);

            if (toggleDto == null)
            {
                throw new AutoMapperMappingException("Error mapping types");
            }

            return(new FarfetchMessage <ToggleDto>
            {
                Result = toggleDto
            });
        }
Beispiel #2
0
        public void ShouldInsertToggleWithAssociatedService()
        {
            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);

            Toggle toggle = new Toggle
            {
                Id          = Guid.NewGuid(),
                Value       = true,
                ServiceList = new List <Models.Service>
                {
                    service
                },
                Name      = "toggleName",
                Overrides = false
            };

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

            Assert.NotNull(togglerService);
            togglerService.Insert(toggle);

            Toggle dbToggle = togglerService.GetById(toggle.Id);

            Assert.NotNull(dbToggle);
            Assert.AreEqual(toggle.Id, dbToggle.Id);
            Assert.AreEqual(toggle.Name, dbToggle.Name);
            Assert.AreEqual(toggle.Overrides, dbToggle.Overrides);
            Assert.AreEqual(toggle.Value, dbToggle.Value);
            Assert.NotNull(dbToggle.ServiceList);
            Assert.AreEqual(toggle.ServiceList.Count, dbToggle.ServiceList.Count);
            Assert.IsNotEmpty(toggle.ServiceList);
        }