Exemple #1
0
        public IActionResult RefreshCache([FromBody] RefreshCacheModel refreshCacheModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var app = _db.Applications.Find(refreshCacheModel.ApplicationId);

            if (app == null)
            {
                throw new InvalidOperationException("Application ID is invalid");
            }

            _bus.Publish(new RefreshTogglesCache
            {
                Environment     = refreshCacheModel.EnvName,
                ApplicationName = app.AppName
            });

            _bus.Publish(new NSTogglesContracts.RefreshTogglesCache
            {
                Environment     = refreshCacheModel.EnvName,
                ApplicationName = app.AppName
            });

            return(Ok());
        }
Exemple #2
0
        public async Task Publishes_Message_With_CacheRefresh_Command()
        {
            //arrange
            var appModel = new AddApplicationModel {
                ApplicationName = "tst", EnvironmentName = "testEnv", DefaultToggleValue = false
            };
            var response = await _client.PostAsJsonAsync("/api/applications/add", appModel);

            response.EnsureSuccessStatusCode();

            var app = await response.Content.ReadAsJsonAsync <Application>();

            var refreshCacheModel = new RefreshCacheModel
            {
                EnvName       = "DEV",
                ApplicationId = app.Id
            };

            //act
            var response2 = await _client.PostAsJsonAsync("/api/CacheRefresh", refreshCacheModel);

            response2.EnsureSuccessStatusCode();

            var msg = (RefreshTogglesCache)_messages.FirstOrDefault(m => m is RefreshTogglesCache);

            msg.Should().NotBeNull();
            msg.Environment.Should().Be("DEV");
            msg.ApplicationName.Should().Be("tst");
        }
        public async Task <IActionResult> RefreshCache([FromBody] RefreshCacheModel refreshCacheModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var app = await _applicationsRepository.FindByIdAsync(refreshCacheModel.ApplicationId);

            if (app == null)
            {
                throw new InvalidOperationException("Application ID is invalid");
            }

            await _bus.Publish(new RefreshTogglesCache
            {
                Environment     = refreshCacheModel.EnvName,
                ApplicationName = app.AppName
            });

            return(Ok());
        }
        public void Publishes_Message_With_CacheRefresh_Command()
        {
            //arrange
            var appModel = new AddApplicationModel {
                ApplicationName = "test", EnvironmentName = "testEnv", DefaultToggleValue = false
            };
            var response = Utils.PostAsJsonAsync(_client, "/api/applications/add", appModel).Result;

            response.EnsureSuccessStatusCode();

            var refreshCacheModel = new RefreshCacheModel
            {
                EnvName       = "DEV",
                ApplicationId = 1
            };

            //act
            var response2 = Utils.PostAsJsonAsync(_client, "/api/CacheRefresh", refreshCacheModel).Result;

            response2.EnsureSuccessStatusCode();

            //TODO: check to see how to test sending of messages on the BUS
        }