public void ContextSetup() { _masterModel = new MasterModel(); var cruiseServer = _masterModel.CreateCruiseServer(x => { x.Url = "https://example.com/server1"; x.Name = "Server 1"; }); _zBuildLightsProject = _masterModel.CreateProject(); _zBuildLightsProject.CruiseProjectAssociations = new[] { new CruiseProjectAssociation { Name = "Project 1.1", ServerId = cruiseServer.Id }, new CruiseProjectAssociation { Name = "Project 1.2", ServerId = cruiseServer.Id } }; var cruiseReader = new StubCcReader() .WithResponse(cruiseServer.Url, NetworkResponse.Fail <Projects>("Could not reach server or something bad happened.")); var updater = new ProjectStatusUpdater(cruiseReader); updater.UpdateAllProjectStatuses(_masterModel); }
public NetworkResponse <CcProjectCollectionViewModel> GetProjects(Guid serverId) { var server = _statusProvider.GetSystemStatus().CruiseServers.Single(x => x.Id.Equals(serverId)); var ccResult = _ccReader.GetStatus(server.Url); if (ccResult.IsSuccessful) { var ccProjects = ccResult.Data; var viewModel = _mapper.Map <Projects, CcProjectCollectionViewModel>(ccProjects); return(NetworkResponse.Success(viewModel)); } return(NetworkResponse.Fail <CcProjectCollectionViewModel>(string.Format("Could not reach cruise server at URL: [{0}]", server.Url), ccResult.Exception)); }
public NetworkResponse <Projects> GetStatus(string url) { if (!_lookupCount.ContainsKey(url)) { _lookupCount[url] = 0; } _lookupCount[url] = _lookupCount[url] + 1; if (!_stubbedResponses.ContainsKey(url)) { return(NetworkResponse.Fail <Projects>(string.Format("The response for url [{0}] must be stubbed.", url))); } return(_stubbedResponses[url]); }
public void ContextSetup() { var masterModel = new MasterModel(); var server1 = masterModel.CreateCruiseServer(x => x.Url = "http://www.example.com/1"); var server2 = masterModel.CreateCruiseServer(x => x.Url = "http://www.example.com/2"); var ccReaderResponse = NetworkResponse.Fail <Projects>("Network request failed.", new Exception("I don't wanna")); var statusProvider = S <ISystemStatusProvider>(); statusProvider.Stub(x => x.GetSystemStatus()).Return(masterModel); var ccReader = S <ICcReader>(); ccReader.Stub(x => x.GetStatus("http://www.example.com/1")).Return(ccReaderResponse); IMapper doNotUseMapper = null; var provider = new CruiseProjectModelProvider(ccReader, doNotUseMapper, statusProvider); _result = provider.GetProjects(server1.Id); }
public NetworkResponse <Projects> GetStatus(string url) { try { var request = WebRequest.Create(url); Projects projects; using (var response = request.GetResponse()) using (var stream = response.GetResponseStream()) using (var reader = new StreamReader(stream)) { var serializer = new XmlSerializer(typeof(Projects)); projects = (Projects)serializer.Deserialize(reader); } return(NetworkResponse.Success(projects)); } catch (Exception e) { Log.ErrorException("Exception when trying to get status from Cruise server.", e); return(NetworkResponse.Fail <Projects>(string.Format("{0}: {1}", e.GetType().Name, e.Message))); } }