public void Creates_new_application_instance() { MockRepository mocks = new MockRepository(); ISystemEnvironment systemEnvironment = mocks.CreateMock <ISystemEnvironment>(); IAssemblyContext context = mocks.CreateMock <IAssemblyContext>(); IConfigurationReader configurationReader = mocks.CreateMock <IConfigurationReader>(); using (mocks.Record()) { Expect.Call(context.GetAssemblyVersion()).Return("1.0"); Expect.Call(systemEnvironment.GetMachineName()).Return("MyMachine"); Expect.Call(configurationReader.GetRequiredSetting("TarantinoWebManagementHttpHost")).Return("www.myapp.com"); } using (mocks.Playback()) { IApplicationInstanceFactory factory = new ApplicationInstanceFactory(systemEnvironment, context, configurationReader); ApplicationInstance instance = factory.Create(); Assert.That(instance.AvailableForLoadBalancing, Is.True); Assert.That(instance.MachineName, Is.EqualTo("MyMachine")); Assert.That(instance.Version, Is.EqualTo("1.0")); Assert.That(instance.MaintenanceHostHeader, Is.EqualTo("www.myapp.com")); Assert.That(instance.ApplicationDomain, Is.EqualTo("www.myapp.com")); } mocks.VerifyAll(); }
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); }
public ApplicationInstance Create() { string hostHeader = _configurationReader.GetRequiredSetting("TarantinoWebManagementHttpHost"); ApplicationInstance instance = new ApplicationInstance(); instance.MachineName = _systemEnvironment.GetMachineName(); instance.AvailableForLoadBalancing = true; instance.Version = _assemblyContext.GetAssemblyVersion(); instance.MaintenanceHostHeader = hostHeader; instance.ApplicationDomain = hostHeader; return(instance); }