McKelt.com

Remembering Thoughts

 

Recent comments

Authors

Categories


Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

RhinoMocks – WhenCalled

The following test would fail without this

 

.WhenCalled(invocation => invocation.ReturnValue = new TestResult(){IsTrue = true, Message = "BBB"})

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Matlock.Core.Shared;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Rhino.Mocks;

namespace Matlock.Tests
{
    [TestClass]
    public class ChrisTest
    {

        private IRuleService ruleService;

        [TestMethod]
        public void ShouldNotChangeReturnedTestResult()
        {
            ruleService = MockRepository.GenerateMock<IRuleService>();
            var testResult = new TestResult();
            testResult.IsTrue = true;
            testResult.Message = "AAA";
            ruleService.Stub(a => a.GetTestResult()).Return(testResult)
                .WhenCalled(invocation => invocation.ReturnValue = new TestResult(){IsTrue = true, Message = "BBB"});



            var testClass = new TestClass(ruleService);
            testClass.KillTheString();
            Assert.IsTrue(testClass.StringIsThere());
            
        }

        public interface IRuleService
        {
            TestResult GetTestResult();
        }

        public class TestResult
        {
            public bool IsTrue { get; set; }
            public string Message { get; set; }
        }

        private class TestClass
        {
            private readonly IRuleService ruleService;

            public TestClass(IRuleService ruleService)
            {
                this.ruleService = ruleService;
            }

            public void KillTheString()
            {
                var result = ruleService.GetTestResult();
                result.Message = string.Empty;
            }

            public bool StringIsThere()
            {
                var result = ruleService.GetTestResult();
                return !string.IsNullOrEmpty(result.Message);
            }
        }
    }
}

Posted by chris on Tuesday, July 06, 2010 10:51 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Crystal Software Development

Crystal Software Development Download


Posted by chris on Wednesday, June 30, 2010 3:56 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Integrated Security = SSPI -- Security Support Provider Interface

Using Integrated Security in connection strings should be either of the following:

Integrated Security=SSPI

or

Integrated Security=false

It should not be

Integrated Security=true

Posted by chris on Tuesday, June 29, 2010 5:39 PM
Permalink | Comments (0) | Post RSSRSS comment feed

LIFO vs FIFO

LIFO

FIFO

higher COGS   lower COGS
lower taxes   higher taxes
lower net income   higher net income
lower inventory balances   higher inventory balances
higher cash flows (less tax paid out)   lower cash flows (more tax paid out)
lower net and gross margins   higher net and gross margins
lower current ratio   higher current ratio
higher inventory turnover   lower inventory turnover
DA and DE higher   DA and DE lower

 

Under IFRS the permissible cost flow methods are:

  • Specific Identification
  • FIFO
  • Weighted average cost

Categories: CFA
Posted by chris on Monday, June 21, 2010 10:30 PM
Permalink | Comments (0) | Post RSSRSS comment feed

WPF UI Thread Dispatcher

A simple implemention for calling asych methods from the UI

 

Examples

 

1.

dispatcher.ExecuteOnMainUIThread(CommandManager.InvalidateRequerySuggested);

 

2.

dispatcher.Execute(() =>
{
SomeLongRunningMethodHere();
});

 

The interface

 
using System;

namespace Mvvm
{
public interface IDispatcher
{
void Execute(Action action);

void ExecuteOnMainUIThread(Action action);
}
}

Synchronous for use in Testing

 
using System;

namespace Mvvm
{
public class SynchronousDispatcher : IDispatcher
{
public void Execute(Action action)
{
action();
}

public void ExecuteOnMainUIThread(Action action)
{
action();
}
}

}

Asynchronous for use by the application at run time

 
using System;

namespace Mvvm
{
using System.Windows;
using System.Windows.Threading;

public class AsynchronousDispatcher : IDispatcher
{
public void Execute(Action action)
{
action.BeginInvoke(CallBack, action);
}

public void ExecuteOnMainUIThread(Action action)
{
Dispatcher dispatcher;

if (Application.Current != null)
{
dispatcher = Application.Current.Dispatcher;
}
else
{
dispatcher = Dispatcher.CurrentDispatcher;
}

dispatcher.Invoke(action);
}

private void CallBack(IAsyncResult result)
{
try
{
((Action)result.AsyncState).EndInvoke(result);
}
catch (Exception ex)
{
// Need to raise the exception on the main thread
ExecuteOnMainUIThread(() =>
{
throw ex;
}
);
}
finally
{
result.AsyncWaitHandle.Close();
}


}
}
}


Categories: .Net
Posted by chris on Wednesday, May 26, 2010 12:15 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Rhino Mock Constraints -- AssertWasCalled

Rhino Mock Constraints allow use to test a methods parameters were called with the correct arguments.

public interface IDocumentService
{
void Save(string userName, Document document, Stream stream);
}
 
 

Some ways to ensure the method that contains the save method passes the correct internally constructed arguments include
 
documentService.AssertWasCalled(
a=>a.Save("chris", doc, adaptor.InputStream),               
b => b.Constraints(Is.Equal(“chris”), Is.NotNull(), Is.AnyThing()));
 
 
Passing in Property.AllPropertiesMatch(this.MyTestObjectWithPropertiesThatShouldMatch)
will check values against each object
 


Posted by Chris on Thursday, May 20, 2010 5:55 PM
Permalink | Comments (0) | Post RSSRSS comment feed

CFA – Accounting Ratios

Liquidity ratios

 

\mbox{Current ratio} = \frac {\mbox{Current Assets}} {\mbox{Current Liabilities}}

 

 

\mbox{Quick (Acid Test) Ratio} = {\mbox{Cash and Cash Equivalent} + \mbox{Marketable Securities} + \mbox{Accounts Receivable}\over \mbox{Current Liabilities}}

Cash ratio is the same as Quick without the accounts receivable

 

 

Solvency ratios

 

Long term debt to equity =  total debt / total equity

 

Debt to equity = total debt / total equity

 

Total debt ratio = total debt / total assets

 

Financial leverage ratio = total assets / total equity


Categories: CFA
Posted by chris on Saturday, May 08, 2010 11:42 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Allow IIS7 to download .config files

1. In the following file

C:\Windows\System32\inetsrv\config\applicationHost.config

Ensure the following

<section name="requestFiltering" overrideModeDefault="Allow" />

2

This is the web.config file

 

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
         <handlers>
           <clear />
            <add 
                name="StaticFile" 
                path="*" verb="*" 
                modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" 
                resourceType="Either" 
                requireAccess="Read" />
        </handlers>
        <staticContent>
            <mimeMap fileExtension=".*" mimeType="application/octet-stream" />
        </staticContent>
        <security>
            <requestFiltering>
                <fileExtensions allowUnlisted="true">
                    <remove fileExtension=".config" />
                    <add fileExtension=".config" allowed="true" />
                </fileExtensions>
            </requestFiltering>
        </security>
    </system.webServer>
</configuration>

Posted by chris on Thursday, March 11, 2010 5:58 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Visual Studio Icons

For free icons that come with Visual Studio check out

 

C:\Program Files\Microsoft Visual Studio 9.0\Common7\VS2008ImageLibrary\1033\

 

VS2008ImageLibrary.zip


Posted by chris on Monday, February 22, 2010 6:45 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Stream bytes to files

                using (var stream =
                    Assembly.GetAssembly(typeof(StubPolicy)).GetManifestResourceStream(
                        "Documents.TestHelpers.Files.test.msg"))
                {
                    const int bufferLength = 256;
                    var buffer = new Byte[bufferLength];
                    if (stream != null)
                    {
                        int bytesRead = stream.Read(buffer, 0, bufferLength);

                        using (var fs = new FileStream(filename, FileMode.CreateNew, FileAccess.Write))
                        {
                            // Write out the input stream
                            while (bytesRead > 0)
                            {
                                fs.Write(buffer, 0, bytesRead);
                                bytesRead = stream.Read(buffer, 0, bufferLength);
                            }
                            fs.Close();
                        }
                        stream.Close();
                    }
                }

Posted by chris on Wednesday, February 10, 2010 3:48 PM
Permalink | Comments (0) | Post RSSRSS comment feed