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; } }
/// <inheritdoc /> public FarfetchMessage <ToggleDto> Insert(ToggleDto toggleDto) { if (_togglerService == null) { throw new NullReferenceException("Toggler Service hasn't been defined"); } Toggle toggle = Mapper.Map <ToggleDto, Toggle>(toggleDto); if (toggle == null) { throw new AutoMapperMappingException("Error mapping types"); } _togglerService.Insert(toggle); toggle = _togglerService.GetByExpression(x => x.Value == toggleDto.Value && x.Overrides == toggleDto.Overrides && x.Name == toggleDto.Name); toggleDto = Mapper.Map <Toggle, ToggleDto>(toggle); if (toggle == null) { throw new AutoMapperMappingException("Error mapping types"); } return(new FarfetchMessage <ToggleDto> { Result = toggleDto, }); }
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); }
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); }
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()); }