public void Dev2StateLogger_LogPreExecuteState_Tests()
        {
            TestSetup(out _fileWrapper, out _directoryWrapper, out _dev2StateLogger, out _activity, out _detailedLog);
            // test
            _dev2StateLogger.LogPreExecuteState(_activity.Object);
            _dev2StateLogger.Dispose();
            // verify
            var text = _fileWrapper.ReadAllText(_detailedLog.LogFilePath);

            //Expect something like: "header:LogPreExecuteState\r\n{\"timestamp\":\"2018-06-19T16:05:29.6755408+02:00\",\"NextActivity\":null}\r\n{\"DsfDataObject\":{\"ServerID\":\"00000000-0000-0000-0000-000000000000\",\"ParentID\":\"00000000-0000-0000-0000-000000000000\",\"ClientID\":\"00000000-0000-0000-0000-000000000000\",\"ExecutingUser\":\"Mock<System.Security.Principal.IIdentity:00000001>.Object\",\"ExecutionID\":null,\"ExecutionOrigin\":0,\"ExecutionOriginDescription\":null,\"ExecutionToken\":\"Mock<Dev2.Common.Interfaces.IExecutionToken:00000001>.Object\",\"IsSubExecution\":false,\"IsRemoteWorkflow\":false,\"Environment\":{\"scalars\":{},\"record_sets\":{},\"json_objects\":{}}}}\r\n"
            Assert.IsTrue(text.Contains("LogPreExecuteState"));
            Assert.IsTrue(text.Contains("timestamp"));
            Assert.IsTrue(text.Contains("NextActivity"));
            Assert.IsTrue(text.Contains("scalars"));
            Assert.IsTrue(text.Contains("record_sets"));
            Assert.IsTrue(text.Contains("json_objects"));
        }
        public void Dev2StateLogger_Given_LogFile_AlreadyExists()
        {
            var streamWriter = TextWriter.Synchronized(new StreamWriter(new MemoryStream()));
            var mockedStream = new Mock <IDev2StreamWriter>();

            mockedStream.Setup(p => p.SynchronizedTextWriter).Returns(streamWriter);
            var mockedDataObject  = SetupDataObject();
            var mockedFileWrapper = new Mock <IFile>();

            mockedFileWrapper.Setup(p => p.AppendText(It.IsAny <string>())).Returns(mockedStream.Object);
            mockedFileWrapper.Setup(p => p.Exists(It.IsAny <string>())).Returns(true);
            mockedFileWrapper.Setup(p => p.GetLastWriteTime(It.IsAny <string>())).Returns(DateTime.Today.AddDays(-1));
            _dev2StateLogger = GetDev2JsonStateLogger(mockedFileWrapper.Object, mockedDataObject);
            var nextActivity = new Mock <IDev2Activity>();

            // test
            _dev2StateLogger.Dispose();
            // verify
            mockedFileWrapper.Verify(p => p.Copy(It.IsAny <string>(), It.IsAny <string>()), Times.AtLeastOnce());
            mockedFileWrapper.Verify(p => p.AppendText(It.IsAny <string>()), Times.AtLeastOnce());
        }
        public void Dev2StateLogger_Given_LogFile_AlreadyExists_And_Is_More_Than_30_Days_Old()
        {
            var streamWriter = TextWriter.Synchronized(new StreamWriter(new MemoryStream()));
            var mockedStream = new Mock <IDev2StreamWriter>();

            mockedStream.Setup(p => p.SynchronizedTextWriter).Returns(streamWriter);
            var mockedDataObject  = SetupDataObject();
            var mockedFileWrapper = new Mock <IFile>();
            var zipWrapper        = new Mock <IZipFile>();

            zipWrapper.Setup(p => p.CreateFromDirectory(It.IsAny <string>(), It.IsAny <string>()));
            mockedFileWrapper.Setup(p => p.AppendText(It.IsAny <string>())).Returns(mockedStream.Object);
            mockedFileWrapper.Setup(p => p.Exists(It.IsAny <string>())).Returns(true);
            mockedFileWrapper.Setup(p => p.GetLastWriteTime(It.IsAny <string>())).Returns(DateTime.Today.AddDays(-45));
            _dev2StateLogger = GetDev2JsonStateLogger(mockedFileWrapper.Object, mockedDataObject, zipWrapper.Object);
            // test
            _dev2StateLogger.Dispose();
            // verify
            mockedFileWrapper.Verify(p => p.Copy(It.IsAny <string>(), It.IsAny <string>()), Times.AtLeastOnce());
            mockedFileWrapper.Verify(p => p.AppendText(It.IsAny <string>()), Times.AtLeastOnce());
            mockedFileWrapper.Verify(p => p.Delete(It.IsAny <string>()), Times.AtLeastOnce());
        }