Inheritance: IEsbManagementEndpoint
        public void ClearLogNoDirectoryPassedExpectsNoDelete()
        {
            //execute
            var clearLog = new ClearLog();
            var dict = new Dictionary<string, StringBuilder>();
            var result = clearLog.Execute(dict, GetWorkspace().Object);

            //assert
            Assert.IsTrue(result.Contains("Cant delete a file if no directory is passed."));
        }
        public void ClearLogNonValidDirectoryExpectsNoDelete()
        {
            //setup
            const string dir = "c:/no_suc_directory_will_Ever_Exist_unless_you_Are_a_cake";

            //execute
            var clearLog = new ClearLog();
            var dict = new Dictionary<string, StringBuilder> { { "Directory", new StringBuilder(dir) } };
            var result = clearLog.Execute(dict, GetWorkspace().Object);

            //assert
            Assert.IsTrue(result.Contains("No such directory exists on the server."));
        }
        public void ClearLogDirectoryExpectsFilesDeleted()
        {
            lock(SyncRoot)
            {
                //setup
                var fileName1 = Guid.NewGuid().ToString() + "_Test.log";
                var fileName2 = Guid.NewGuid().ToString() + "_Test.log";

                var path1 = Path.Combine(_testDir, fileName1);
                File.WriteAllText(path1, @"hello test");
                Assert.IsTrue(File.Exists(path1));

                var path2 = Path.Combine(_testDir, fileName2);
                File.WriteAllText(path2, @"hello test");
                Assert.IsTrue(File.Exists(path2));

                //execute
                var values = new Dictionary<string, StringBuilder> { { "Directory", new StringBuilder(_testDir) } };
                var esb = new ClearLog();
                var result = esb.Execute(values, GetWorkspace().Object);

                //assert
                Assert.IsTrue(result.Contains("Success"));
                Assert.IsFalse(File.Exists(path1));
                Assert.IsFalse(File.Exists(path2));
            }
        }
        public void DeleteLogCreateServiceEntryExpectedReturnsDynamicService()
        {
            var esb = new ClearLog();
            var result = esb.CreateServiceEntry();
            Assert.AreEqual(esb.HandlesType(), result.Name);
            Assert.AreEqual("<DataList><Directory ColumnIODirection=\"Input\"/><Dev2System.ManagmentServicePayload ColumnIODirection=\"Both\"></Dev2System.ManagmentServicePayload></DataList>", result.DataListSpecification.ToString());
            Assert.AreEqual(1, result.Actions.Count);

            var serviceAction = result.Actions[0];
            Assert.AreEqual(esb.HandlesType(), serviceAction.Name);
            Assert.AreEqual(enActionType.InvokeManagementDynamicService, serviceAction.ActionType);
            Assert.AreEqual(esb.HandlesType(), serviceAction.SourceMethod);
        }
 public void DeleteLogHandlesTypeExpectedReturnsDeleteLogService()
 {
     var esb = new ClearLog();
     var result = esb.HandlesType();
     Assert.AreEqual("ClearLogService", result);
 }
        public void ClearLogExecuteWithValidPathAndLockedExpectedReturnsError()
        {
            Dev2JsonSerializer serializer = new Dev2JsonSerializer();
            lock(SyncRoot)
            {
                //setup
                var fileName1 = Guid.NewGuid().ToString() + "_Test.log";
                var fileName2 = Guid.NewGuid().ToString() + "_Test.log";

                var path1 = Path.Combine(_testDir, fileName1);
                File.WriteAllText(path1, @"hello test");
                Assert.IsTrue(File.Exists(path1));

                var path2 = Path.Combine(_testDir, fileName2);
                File.WriteAllText(path2, @"hello test");
                Assert.IsTrue(File.Exists(path2));

                var fs = File.OpenRead(path2);

                //execute
                StringBuilder result;
                try
                {
                    var values = new Dictionary<string, StringBuilder> { { "Directory", new StringBuilder(_testDir) } };
                    var esb = new ClearLog();
                    result = esb.Execute(values, GetWorkspace().Object);
                }
                finally
                {
                    fs.Close();
                }

                var msg = serializer.Deserialize<ExecuteMessage>(result.ToString());

                //assert
                Assert.IsTrue(msg.Message.ToString().StartsWith("Error clearing "));
            }
        }