Showing posts with label Unit Test. Show all posts
Showing posts with label Unit Test. Show all posts

Monday, March 16, 2015

DRF File and PCDOCS Link Handler for eDOCS DM

Couple years ago I created a handler for DRF files, OpenText eDOCS DM document links. The purpose of the tool was to give users the ability to open eDOCS DM documents in read-only mode if they (the users) do not want to install eDOCS DM Extensions.

Today I'm publishing the tool, its full source code, and some basic documentation:
EDocsLinkHandler

The best part of this package is, of course, the full source code (C# / .NET 4 / Visual Studio 2013). It's my implementation of DM WCF API helpers, and it even includes unit tests! :-)

Although the helpers only implement the logon, search, and document download functionality, they may serve as a starting point for anyone developing for DM with WCF API. After two years since the code was written, I still like it, maybe with the exception of the way I implemented the DMSearchResults class... Well, consider it as a free demo. Enjoy!

Tuesday, February 25, 2014

DM Server Log Parser Update

EDocsLogParser v1.0.3, a new version, has been uploaded to Drive and GitHub. I tuned up performance a bit and fixed OutOfMemoryException which occurred on some large (~1 GB) log files. The parser was tested on logs larger than 1.3 GB and it worked fine.

While working on these updates, I noticed that DM Server logs become messy when the load on the server increases: messages from different calls are often mixed on same lines. I did my best to resolve this mess in the log parser, but it couldn't be resolved completely. I added new unit tests with snippets from real logs, so you can see a part of that "having fun".

If I wrote the parser from the beginning now, I would based it on loading a whole log file as a single string and not breaking it by lines as I've implemented it. I give it up: I find the OpenText's product being buggy and a bit badly designed to spend too much time and passion on it. With this said, I'm quite happy with EDocsLogParser as it is: it extracts 99.99% of all SQL events out of a messy 1 GB log and this is more than enough for the tasks I intended it for:
How to Find Slow SQL Queries in eDOCS DM Server Logs
SQL Connection Cache Size for OpenText eDOCS DM Server

Tuesday, December 17, 2013

Run Workflow Application Synchronously to Check the Completion State

If you come across this article, you are probably writing a Unit Test for your workflow, in which you need to know when workflow processing is completed. You also may want to examine the CompletionState value from the Complete event, otherwise you would use WorkflowInvoker instead of WorkflowApplication...

The solution turns out to be fairly simple: use ManualResetEvent. Okay, let's get to the code and that will be it:

using System.Activities;
using System.Threading;

[TestMethod]
public void TestExternalCancellationSimple() {
    var wf = new SomeActivity {
        ...
    };

    ActivityInstanceState state = ActivityInstanceState.Executing;
    var mre = new ManualResetEvent(false);

    var app = new WorkflowApplication(wf) {
        Completed = (e) => {
            state = e.CompletionState;
            mre.Set();
        }
    };
    app.Run();
    Thread.Sleep(500);  // wait a bit and then cancel the workflow
    app.Cancel();

    mre.WaitOne();

    Assert.AreEqual(ActivityInstanceState.Canceled, state);
}

UPDATE: Everything had been invented known even before we came in this world... Very similar code to the snippet above can be found in WF's Getting Started How to: Run a Workflow, with the only difference is that in MSDN they use AutoResetEvent, which is, technically speaking more correct, though doesn't make any difference if you call WaitOne only once.

Thursday, December 12, 2013

Unit Testing Workflows

Here comes my first Workflow in Unit Tests. I tend to think that "Dot Net" inevitably turns into "Brace Net"... :-)

[TestClass]
public class BackupTests {
    [TestMethod, ExpectedException(typeof(InvalidWorkflowException))]
    public void IndexArgumentMissingTest() {
        Activity backup = new BackupFilesActivity { Copier = new MockCopier() };
        var sequence = new Sequence { Activities = { backup } };
        WorkflowInvoker.Invoke(sequence);
    }

    [TestMethod, ExpectedException(typeof(MyException))]
    public void CopyFailsTest() {
        var index = new IndexInfo() { ID = 1 };
        Activity backup = new BackupFilesActivity { 
            Copier = new MockCopier(new MyException()),
        };
        var inputs = new Dictionary<string, object>() { { "Index", index } };
        WorkflowInvoker.Invoke(backup, inputs);
    }

    [TestMethod]
    public void MockCopyWorksTest() {
        var index = new IndexInfo() { ID = 1 };
        Activity backup = new BackupFilesActivity {
            Copier = new MockCopier(),
            Index = new InArgument<IndexInfo>((ctx) => index)
        };
        var sequence = new Sequence { Activities = { backup } };
        WorkflowInvoker.Invoke(sequence);
    }
}