Exemple #1
0
        public void Should_ThrowExceptionWhenNoServices()
        {
            Factory factory = new Factory(FILE_SETTINGS_PATH);
            Toggle  toggle1 = new Toggle
            {
                Id          = Guid.NewGuid(),
                Value       = true,
                ServiceList = new List <Models.Service>
                {
                },
                Name      = "toggleName",
                Overrides = false
            };

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

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

            try
            {
                bool shouldNotExecute = togglerService.ShouldApplicationExecute(toggle1);
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.Pass();
                throw;
            }
        }
Exemple #2
0
        public void Should_RetriveToggleValueForService()
        {
            Models.Service service = new Models.Service
            {
                Id      = Guid.NewGuid(),
                Name    = "ServiceNameTest",
                Version = "1.0",
                ApiKey  = "apiKey"
            };

            Factory factory = new Factory(FILE_SETTINGS_PATH);

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

            Assert.NotNull(applicationService);
            applicationService.Insert(service);

            Models.Service dbService = applicationService.GetById(service.Id);
            Assert.NotNull(dbService);
            Assert.AreEqual(service.Id, dbService.Id);
            Assert.AreEqual(service.ApiKey, dbService.ApiKey);
            Assert.AreEqual(service.Name, dbService.Name);
            Assert.AreEqual(service.Version, dbService.Version);

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

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

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

            bool shouldExecute = togglerService.ShouldApplicationExecute(toggle1);

            Assert.IsTrue(shouldExecute);
        }
        /// <inheritdoc />
        public FarfetchMessage <bool> GetForService(string toggleName, bool toggleValue, string serviceName, string serviceVersion)
        {
            if (string.IsNullOrEmpty(toggleName))
            {
                throw new ArgumentNullException(nameof(toggleName));
            }
            if (string.IsNullOrEmpty(serviceName))
            {
                throw new ArgumentNullException(nameof(serviceName));
            }
            if (string.IsNullOrEmpty(serviceVersion))
            {
                throw new ArgumentNullException(nameof(serviceVersion));
            }
            if (_togglerService == null)
            {
                throw new NullReferenceException("Toggler Service hasn't been defined");
            }

            Toggle toggle = new Toggle
            {
                Id          = Guid.Empty,
                Name        = toggleName,
                Overrides   = false,
                Value       = toggleValue,
                ServiceList = new List <Service>
                {
                    new Service
                    {
                        Name    = serviceName,
                        Version = serviceVersion
                    }
                }
            };

            bool result = _togglerService.ShouldApplicationExecute(toggle);

            return(new FarfetchMessage <bool>
            {
                Result = result,
            });
        }