public void Should_disable_load_balancing_when_requested() { ApplicationInstance instance = new ApplicationInstance(); instance.AvailableForLoadBalancing = false; MockRepository mocks = new MockRepository(); IApplicationInstanceContext instanceContext = mocks.CreateMock <IApplicationInstanceContext>(); IWebContext context = mocks.CreateMock <IWebContext>(); ISecureAvailabilityStatusUpdater updater = mocks.CreateMock <ISecureAvailabilityStatusUpdater>(); using (mocks.Record()) { Expect.Call(instanceContext.GetCurrent()).Return(instance); Expect.Call(context.GetRequestItem(LoadBalanceStatusManager.ENABLED_PARAM)).Return("FALSE"); Expect.Call(updater.SetStatus(false)).Return(string.Empty); } using (mocks.Playback()) { ILoadBalanceStatusManager manager = new LoadBalanceStatusManager(instanceContext, context, updater); string errorMessage = manager.HandleLoadBalanceRequest(); Assert.That(errorMessage, Is.Empty); } }
public string HandleLoadBalanceRequest() { string errorMessage = string.Empty; ApplicationInstance currentInstance = _instanceContext.GetCurrent(); string enabledParameter = _context.GetRequestItem(ENABLED_PARAM); if (enabledParameter != null) { bool enabled = bool.Parse(enabledParameter); errorMessage = _statusUpdater.SetStatus(enabled); } else if (!currentInstance.AvailableForLoadBalancing) { _context.SetHttpResponseStatus(400, "This application has been turned off"); } return(errorMessage); }