public void GetAgents() { ChromeExtensionController cec = new ChromeExtensionController(); cec.Request = new HttpRequestMessage(); cec.Request.SetConfiguration(new HttpConfiguration()); AgentMessage message = new AgentMessage(); message.uuid = _agentGuid; message.token = _agentToken; List <AgentResponse> response = cec.Agents(message); Assert.IsNotNull(response); Assert.AreEqual(1, response.Count); Assert.AreEqual("Unit Test Chrome Agent", response[0].name); Assert.AreEqual("http://localhost", response[0].url); Assert.AreEqual("http://localhost/login.php", response[0].loginUrl); }
public void SendData() { ChromeExtensionController cec = new ChromeExtensionController(); cec.Request = new HttpRequestMessage(); cec.Request.SetConfiguration(new HttpConfiguration()); byte[] fileContents = System.IO.File.ReadAllBytes(@".\TestData\sample.csv"); Assert.IsNotNull(fileContents); AgentMessage message = new AgentMessage(); message.uuid = _agentGuid; message.token = _agentToken; message.agent_id = _agentId; message.filename = "sample.csv"; message.data = Convert.ToBase64String(fileContents); HttpResponseMessage response = cec.Data(message); Assert.IsTrue(response.IsSuccessStatusCode); }
public void RegisterAgent() { ChromeExtensionController cec = new ChromeExtensionController(); cec.Request = new HttpRequestMessage(); cec.Request.SetConfiguration(new HttpConfiguration()); AgentMessage message = new AgentMessage(); message.uuid = Guid.NewGuid(); HttpResponseMessage response = cec.Register(message); var content = response.Content; Assert.IsNotNull(content); Assert.IsInstanceOfType(content, typeof(ObjectContent <AgentMessage>)); AgentMessage responseMessage = (AgentMessage)((ObjectContent <AgentMessage>)content).Value; Assert.IsNotNull(responseMessage.token); Assert.AreNotEqual(Guid.Parse("00000000-0000-0000-0000-000000000000"), responseMessage.token); _agentGuid = responseMessage.uuid; _agentToken = responseMessage.token; // If we've gotten this far, we've registered a new AgentChrome, let's associate it with the agent using (var ctx = new DataFlowDbContext()) { AgentChrome ac = ctx.AgentChromes.Where(chr => chr.AgentUuid == _agentGuid && chr.AccessToken == _agentToken).FirstOrDefault(); AgentAgentChrome aac = new AgentAgentChrome(); aac.AgentChromeId = ac.Id; aac.AgentId = _agentId; ctx.AgentAgentChromes.Add(aac); ctx.SaveChanges(); _agentChromeId = ac.Id; _agentAgentChromeId = aac.Id; } }