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_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_GetAuthorizationContextForService_Returns_Administrator()
        {
            //------------Setup for test-------------------------
            var getLogData = new GetLogDataService();
            //------------Execute Test---------------------------
            var authorizationContextForService = getLogData.GetAuthorizationContextForService();

            //------------Assert Results-------------------------
            Assert.AreEqual(AuthorizationContext.Administrator, authorizationContextForService);
        }
        public void GetLogDataService_ServerLogFilePath_NotSet_ShouldReturnStandardValue()
        {
            //------------Setup for test--------------------------
            var getLogDataService = new GetLogDataService();

            //------------Execute Test---------------------------
            var logFilePath = getLogDataService.ServerLogFilePath;

            //------------Assert Results-------------------------
            Assert.AreEqual(EnvironmentVariables.ServerLogFile, logFilePath);
        }
        public void GetAuthorizationContextForService_ShouldReturnContext()
        {
            //------------Setup for test--------------------------
            var getLogDataService = new GetLogDataService();

            //------------Execute Test---------------------------
            var resId = getLogDataService.GetAuthorizationContextForService();

            //------------Assert Results-------------------------
            Assert.AreEqual(AuthorizationContext.Administrator, resId);
        }
        public void GetLogDataService_HandlesType_ExpectName()
        {
            //------------Setup for test--------------------------
            var getLogDataService = new GetLogDataService();


            //------------Execute Test---------------------------

            //------------Assert Results-------------------------
            Assert.AreEqual("GetLogDataService", getLogDataService.HandlesType());
        }
        public void GetResourceID_ShouldReturnEmptyGuid()
        {
            //------------Setup for test--------------------------
            var getLogDataService = new GetLogDataService();

            //------------Execute Test---------------------------
            var resId = getLogDataService.GetResourceID(new Dictionary <string, StringBuilder>());

            //------------Assert Results-------------------------
            Assert.AreEqual(Guid.Empty, resId);
        }
        public void GetLogDataService_ServerLogFilePath_WhenSet_ShouldReturnSetValue()
        {
            //------------Setup for test--------------------------
            var getLogDataService = new GetLogDataService {
                ServerLogFilePath = "MyPath"
            };
            //------------Execute Test---------------------------
            var logFilePath = getLogDataService.ServerLogFilePath;

            //------------Assert Results-------------------------
            Assert.AreEqual("MyPath", logFilePath);
        }
        public void GetLogDataService_CreateServiceEntry_ExpectProperlyFormedDynamicService()
        {
            //------------Setup for test--------------------------
            var getLogDataService = new GetLogDataService();


            //------------Execute Test---------------------------
            var a = getLogDataService.CreateServiceEntry();
            //------------Assert Results-------------------------
            var b = a.DataListSpecification.ToString();

            Assert.AreEqual("<DataList><ResourceType ColumnIODirection=\"Input\"/><Roles ColumnIODirection=\"Input\"/><ResourceName ColumnIODirection=\"Input\"/><Dev2System.ManagmentServicePayload ColumnIODirection=\"Both\"></Dev2System.ManagmentServicePayload></DataList>", b);
        }
        public void GetLogDataService_CreateServiceEntry_Returns_GetExecutionHistory()
        {
            //------------Setup for test-------------------------
            var getLogData = new GetLogDataService();
            //------------Execute Test---------------------------
            var dynamicService = getLogData.CreateServiceEntry();
            var handleType     = getLogData.HandlesType();

            //------------Assert Results-------------------------
            Assert.IsNotNull(dynamicService);
            Assert.IsFalse(string.IsNullOrEmpty(handleType));
            Assert.AreEqual(handleType, dynamicService.Name);
        }
        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);
        }