public void Correctly_creates_new_application_instance_if_existing_instance_does_not_exist() { ApplicationInstance instance = new ApplicationInstance(); MockRepository mocks = new MockRepository(); ISystemEnvironment environment = mocks.CreateMock <ISystemEnvironment>(); IConfigurationReader configurationReader = mocks.CreateMock <IConfigurationReader>(); IApplicationInstanceRepository repository = mocks.CreateMock <IApplicationInstanceRepository>(); IApplicationInstanceFactory factory = mocks.CreateMock <IApplicationInstanceFactory>(); using (mocks.Record()) { Expect.Call(environment.GetMachineName()).Return("MyMachine"); Expect.Call(configurationReader.GetRequiredSetting("TarantinoWebManagementHttpHost")).Return("www.myapp.com"); Expect.Call(repository.GetByMaintenanceHostHeaderAndMachineName("www.myapp.com", "MyMachine")).Return(null); Expect.Call(factory.Create()).Return(instance); repository.Save(instance); } using (mocks.Playback()) { ICurrentApplicationInstanceRetriever retriever = new CurrentApplicationInstanceRetriever(environment, configurationReader, repository, factory); Assert.That(retriever.GetApplicationInstance(), Is.SameAs(instance)); } mocks.VerifyAll(); }
public ApplicationInstance GetApplicationInstance() { string machineName = _environment.GetMachineName(); string applicationDomainName = _configurationReader.GetRequiredSetting("TarantinoWebManagementHttpHost"); ApplicationInstance instance = _repository.GetByMaintenanceHostHeaderAndMachineName(applicationDomainName, machineName); if (instance == null) { instance = _factory.Create(); _repository.Save(instance); } return(instance); }