public void GetLogDataService_Execute_WithBadUser_ShouldFilterLogData() { //------------Setup for test-------------------------- const string logFilePath = @"TextFiles\LogFileWithFlatResultsNEwFormat.txt"; var getLogDataService = new GetLogDataService { ServerLogFilePath = logFilePath }; //---------------Assert Precondition---------------- var logEntriesJson = getLogDataService.Execute(new Dictionary <string, StringBuilder>(), null); Assert.IsNotNull(logEntriesJson); var logEntriesObject = JsonConvert.DeserializeObject <List <LogEntry> >(logEntriesJson.ToString()); Assert.AreEqual(1, logEntriesObject.Count); //------------Execute Test--------------------------- var stringBuilders = new Dictionary <string, StringBuilder> { { "User", "BadUser".ToStringBuilder() } }; logEntriesJson = getLogDataService.Execute(stringBuilders, null); //------------Assert Results------------------------- logEntriesObject = JsonConvert.DeserializeObject <List <LogEntry> >(logEntriesJson.ToString()); Assert.AreEqual(0, logEntriesObject.Count); }
public void GetLogDataService_Execute_WithEndDate_ShouldFilterLogData() { //------------Setup for test-------------------------- const string logFilePath = @"TextFiles\LogFileWithFlatResultsNEwFormat.txt"; var getLogDataService = new GetLogDataService { ServerLogFilePath = logFilePath }; //---------------Assert Precondition---------------- var logEntriesJson = getLogDataService.Execute(new Dictionary <string, StringBuilder>(), null); Assert.IsNotNull(logEntriesJson); var logEntriesObject = JsonConvert.DeserializeObject <List <LogEntry> >(logEntriesJson.ToString()); Assert.AreEqual(1, logEntriesObject.Count); //------------Execute Test--------------------------- var stringBuilders = new Dictionary <string, StringBuilder>(); var longDateString = DateTime.ParseExact("2017-05-25 08:14:12,420", GlobalConstants.LogFileDateFormat, System.Globalization.CultureInfo.InvariantCulture); stringBuilders.Add("CompletedDateTime", longDateString.ToString(GlobalConstants.LogFileDateFormat).ToStringBuilder()); logEntriesJson = getLogDataService.Execute(stringBuilders, null); //------------Assert Results------------------------- logEntriesObject = JsonConvert.DeserializeObject <List <LogEntry> >(logEntriesJson.ToString()); Assert.AreEqual(0, logEntriesObject.Count); }
public void GetLogDataService_GivenEmptyArgs_Returns_ExecuteMessage() { //------------Setup for test------------------------- var webSocketFactoryMock = new Mock <IWebSocketFactory>(); var webSocketWrapperMock = new Mock <IWebSocketWrapper>(); var commandMessage = ""; var onMessage = new Action <string, IWebSocketWrapper>((s, w) => { }); webSocketWrapperMock.Setup(ws => ws.SendMessage(It.IsAny <string>())).Callback((string s) => { commandMessage = s; }).Verifiable(); webSocketWrapperMock.Setup(c => c.Connect()).Returns(webSocketWrapperMock.Object); webSocketWrapperMock.Setup(ws => ws.OnMessage(onMessage)); webSocketFactoryMock.Setup(c => c.New()).Returns(webSocketWrapperMock.Object); var getLogData = new GetLogDataService(webSocketFactoryMock.Object, TimeSpan.FromMilliseconds(1)); var workspaceMock = new Mock <IWorkspace>(); //------------Execute Test--------------------------- var requestArgs = new Dictionary <string, StringBuilder>(); var executeResults = getLogData.Execute(requestArgs, workspaceMock.Object); var jsonSerializer = new Dev2JsonSerializer(); Assert.IsNotNull(executeResults); var deserializedResults = jsonSerializer.Deserialize <IList <IAudit> >(executeResults); //------------Assert Results------------------------- Assert.IsNotNull(deserializedResults); Assert.AreEqual(0, deserializedResults.Count); }
public void GetLogDataService_Execute_WithLogDataContainingURL_shouldReturnLogDataObjectWithUrlERROR() { //------------Setup for test-------------------------- const string logFilePath = @"TextFiles\LogFileWithFlatResultsNEwFormatWithErrors.txt"; var getLogDataService = new GetLogDataService { ServerLogFilePath = logFilePath }; //------------Execute Test--------------------------- var logEntriesJson = getLogDataService.Execute(new Dictionary <string, StringBuilder>(), null); //------------Assert Results------------------------- Assert.IsNotNull(logEntriesJson); var logEntriesObject = JsonConvert.DeserializeObject <List <LogEntry> >(logEntriesJson.ToString()); Assert.IsNotNull(logEntriesObject); Assert.AreEqual("ERROR", logEntriesObject[0].Status); }
public void GetLogDataService_Execute_WithLogDataContainingURl_ShouldReturnLogDataObjectWithUrl() { //------------Setup for test-------------------------- const string logFilePath = @"TextFiles\LogFileWithFlatResultsNEwFormat.txt"; var getLogDataService = new GetLogDataService { ServerLogFilePath = logFilePath }; //------------Execute Test--------------------------- var logEntriesJson = getLogDataService.Execute(new Dictionary <string, StringBuilder>(), null); //------------Assert Results------------------------- Assert.IsNotNull(logEntriesJson); var logEntriesObject = JsonConvert.DeserializeObject <List <LogEntry> >(logEntriesJson.ToString()); Assert.IsNotNull(logEntriesObject); var value = logEntriesObject[0].Url; Assert.IsFalse(string.IsNullOrEmpty(value)); Assert.AreEqual("http://pieter:3142/secure/hello world.xml?<datalist><name></name></datalist>", value); }
public void GetLogDataService_Execute_Should_ExecuteSendMessage() { //------------------------------Arrange---------------------------------- var stringBuilders = new Dictionary <string, StringBuilder> { { "ResourceID", new StringBuilder(GlobalConstants.DefaultLoggingSourceId) } }; var webSocketFactoryMock = new Mock <IWebSocketFactory>(); var webSocketWrapperMock = new Mock <IWebSocketWrapper>(); var commandMessage = ""; var onMessage = new Action <string, IWebSocketWrapper>((s, w) => { }); webSocketWrapperMock.Setup(ws => ws.SendMessage(It.IsAny <string>())).Callback((string s) => { commandMessage = s; }).Verifiable(); webSocketWrapperMock.Setup(c => c.Connect()).Returns(webSocketWrapperMock.Object); webSocketWrapperMock.Setup(ws => ws.OnMessage(onMessage)); webSocketFactoryMock.Setup(c => c.New()).Returns(webSocketWrapperMock.Object); //------------------------------Act-------------------------------------- var getLogDataService = new GetLogDataService(webSocketFactoryMock.Object, TimeSpan.FromMilliseconds(1)); getLogDataService.Execute(stringBuilders, null); //------------------------------Assert----------------------------------- var auditCommand = JsonConvert.DeserializeObject <AuditCommand>(commandMessage); Assert.IsNotNull(auditCommand); Assert.AreEqual("LogQuery", auditCommand.Type); Assert.AreEqual(1, auditCommand.Query.Count); Assert.AreEqual("ResourceID", auditCommand.Query.First().Key); Assert.AreEqual(GlobalConstants.DefaultLoggingSourceId, auditCommand.Query.First().Value.ToString()); webSocketWrapperMock.Verify(s => s.OnMessage(It.IsAny <Action <string, IWebSocketWrapper> >()), Times.Once); }
public void GetLogDataService_Execute_WithLogData_ShouldReturnLogDataObject() { //------------Setup for test-------------------------- const string logData = @"2017-05-18 10:41:03,500 [(null)] INFO - Started Execution for Service Name:tttt Resource Id:a2352f24-fe9f-4e7d-bd0c-f5267b362d0b Mode:Debug 2017-05-18 10:41:03,519 [(null)] DEBUG - Getting Resource to Execute 2017-05-18 10:41:03,519 [(null)] DEBUG - Fetching Execution Plan for a2352f24-fe9f-4e7d-bd0c-f5267b362d0b for workspace 00000000-0000-0000-0000-000000000000 2017-05-18 10:41:03,611 [(null)] DEBUG - Got Resource to Execute 2017-05-18 10:41:03,625 [(null)] INFO - Debug Already Started 2017-05-18 10:41:03,681 [(null)] INFO - Completed Execution for Service Name:tttt Resource Id: a2352f24-fe9f-4e7d-bd0c-f5267b362d0b Mode:Debug "; var getLogDataService = new GetLogDataService(); var logFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()); getLogDataService.ServerLogFilePath = logFilePath; File.WriteAllText(logFilePath, logData); //------------Execute Test--------------------------- var logEntriesJson = getLogDataService.Execute(new Dictionary <string, StringBuilder>(), null); //------------Assert Results------------------------- Assert.IsNotNull(logEntriesJson); var logEntriesObject = JsonConvert.DeserializeObject <List <LogEntry> >(logEntriesJson.ToString()); Assert.IsNotNull(logEntriesObject); }