<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Dotnet Tdd on Chris McKelt - Remembering Thoughts</title><link>https://blog.smarttechventures.au/tags/dotnet-tdd/</link><description>Recent content in Dotnet Tdd on Chris McKelt - Remembering Thoughts</description><generator>Hugo -- 0.147.2</generator><language>en</language><lastBuildDate>Sun, 06 Oct 2013 00:00:00 +0800</lastBuildDate><atom:link href="https://blog.smarttechventures.au/tags/dotnet-tdd/index.xml" rel="self" type="application/rss+xml"/><item><title>XUnit Ignore test at runtime (with SpecFlow tag @IgnoreLocally)</title><link>https://blog.smarttechventures.au/articles/posts/xunit-ignore-test-at-runtime-with-specflow-tag-ignorelocally-2-2/</link><pubDate>Sun, 06 Oct 2013 00:00:00 +0800</pubDate><guid>https://blog.smarttechventures.au/articles/posts/xunit-ignore-test-at-runtime-with-specflow-tag-ignorelocally-2-2/</guid><description>&lt;p>Code &amp;ndash;&amp;gt; &lt;a href="https://github.com/chrismckelt/XUnit.OptionallyIgnore" target="_blank">https://github.com/chrismckelt/XUnit.OptionallyIgnore&lt;/a>&lt;/p>
&lt;p>NuGet &amp;ndash;&amp;gt; &lt;a href="https://www.nuget.org/packages/Xunit.SpecFlow.AssertSkip/" target="_blank">https://www.nuget.org/packages/Xunit.SpecFlow.AssertSkip/&lt;/a>&lt;/p>
&lt;p>As Xunit has no Assert.Ignore() using the OptionallyIgnoreTestFactAttribute attribute on a method and setting McKeltCustom.SpecflowPlugin.Settings.IgnoreLocally == true will ignore the test at runtime&lt;/p>
&lt;p>In SpecFlow set this as a plugin and use the tag &lt;strong>@IgnoreLocally&lt;/strong>&amp;ndash; before each test scenario is run turn on/off the setting to run this test.&lt;/p>
&lt;p>&lt;strong>Sample usage:&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>namespace Tester
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>{
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public class Dummy
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public Dummy()
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> McKeltCustom.SpecflowPlugin.Settings.IgnoreLocally = true;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public class TestFixture : IUseFixture&amp;lt;Dummy&amp;gt;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> [OptionallyIgnoreTestFact\]
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public void DoesThisWork()
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Assert.True(false, &amp;#34;This should not be run&amp;#34;);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public void SetFixture(Dummy data)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> throw new NotImplementedException();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>SpecFlow tag can be on a feature or a scenario&lt;/p></description></item><item><title>Sales Tax Calculator using SpecFlow &amp; The State Pattern And Chained Commands</title><link>https://blog.smarttechventures.au/articles/posts/sales-tax-calculator-using-specflow-the-state-pattern-and-chained-commands/</link><pubDate>Fri, 11 Mar 2011 00:00:00 +0800</pubDate><guid>https://blog.smarttechventures.au/articles/posts/sales-tax-calculator-using-specflow-the-state-pattern-and-chained-commands/</guid><description>&lt;p>Using &lt;a href="http://www.specflow.org/" target="_blank">SpecFlow&lt;/a> heres how I solved the following problem&lt;/p>
&lt;h5 id="problem--sales-taxes">PROBLEM : SALES TAXES&lt;/h5>
&lt;blockquote>
&lt;p>Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty is an additional sales tax applicable on all imported goods at a rate of 5%, with no exemptions._&lt;/p>
&lt;p>When I purchase items I receive a receipt which lists the name of all the items and their price (including tax), finishing with the total cost of the items, and the total amounts of sales taxes paid. The rounding rules for sales tax are that for a tax rate of n%, a shelf price of p contains (np/100 rounded up to the nearest 0.05) amount of sales tax.&lt;/p></description></item><item><title>RhinoMocks – WhenCalled</title><link>https://blog.smarttechventures.au/articles/posts/rhinomocks-whencalled/</link><pubDate>Tue, 06 Jul 2010 00:00:00 +0800</pubDate><guid>https://blog.smarttechventures.au/articles/posts/rhinomocks-whencalled/</guid><description>&lt;p>The following test would fail without this&lt;/p>
&lt;pre>&lt;code>.WhenCalled(invocation =&amp;gt; invocation.ReturnValue = new TestResult(){IsTrue = true, Message = &amp;quot;BBB&amp;quot;})
&lt;/code>&lt;/pre>
&lt;p> &lt;/p>
&lt;pre>&lt;code>[TestClass]
public class ChrisTest
{
private IRuleService ruleService;
[TestMethod]
public void ShouldNotChangeReturnedTestResult()
{
ruleService = MockRepository.GenerateMock&amp;lt;IRuleService&amp;gt;();
var testResult = new TestResult();
testResult.IsTrue = true;
testResult.Message = &amp;quot;AAA&amp;quot;;
ruleService.Stub(a =&amp;gt; a.GetTestResult()).Return(testResult)
.WhenCalled(invocation =&amp;gt; invocation.ReturnValue = new TestResult(){IsTrue = true, Message = &amp;quot;BBB&amp;quot;});
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);
}
}
}
&lt;/code>&lt;/pre></description></item><item><title>Rhino Mock Constraints -- AssertWasCalled</title><link>https://blog.smarttechventures.au/articles/posts/rhino-mock-constraints-assertwascalled/</link><pubDate>Thu, 20 May 2010 00:00:00 +0800</pubDate><guid>https://blog.smarttechventures.au/articles/posts/rhino-mock-constraints-assertwascalled/</guid><description>&lt;p>Rhino Mock Constraints allow use to test a methods parameters were called with the correct arguments.&lt;/p>
&lt;blockquote>
&lt;p>public interface IDocumentService
{
void Save(string userName, Document document, Stream stream);
}&lt;/p>&lt;/blockquote>
&lt;p>Some ways to ensure the method that contains the save method passes the correct internally constructed arguments include&lt;/p>
&lt;blockquote>
&lt;p>documentService.AssertWasCalled(a=&amp;gt;a.Save(&amp;ldquo;chris&amp;rdquo;, doc, adaptor.InputStream), b =&amp;gt; b.Constraints(Is.Equal(“chris”), Is.NotNull(), Is.AnyThing()));&lt;/p>&lt;/blockquote>
&lt;p>Passing in&lt;/p>
&lt;pre>&lt;code>Property.AllPropertiesMatch(this.MyTestObjectWithPropertiesThatShouldMatch)
&lt;/code>&lt;/pre>
&lt;p>will check values against each object&lt;/p></description></item><item><title>ISpecification</title><link>https://blog.smarttechventures.au/articles/posts/ispecification/</link><pubDate>Wed, 03 Feb 2010 00:00:00 +0800</pubDate><guid>https://blog.smarttechventures.au/articles/posts/ispecification/</guid><description>&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>public interface ISpecification&amp;lt;T&amp;gt;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>{
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> bool IsSatisfiedBy(T candidate);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ISpecification&amp;lt;T&amp;gt; And(ISpecification&amp;lt;T&amp;gt; other);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ISpecification&amp;lt;T&amp;gt; Or(ISpecification&amp;lt;T&amp;gt; other);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ISpecification&amp;lt;T&amp;gt; XOr(ISpecification&amp;lt;T&amp;gt; other);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ISpecification&amp;lt;T&amp;gt; AndAllOf(IEnumerable&amp;lt;ISpecification&amp;lt;T&amp;gt;&amp;gt; specifications);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> T Target { get; set; }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> void GetResults(ResultsVisitor visitor);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> IEnumerable&amp;lt;Type&amp;gt; WhatWasAssessed();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Risks.IDemoCommand GetCommand();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span> using System;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>using System.Collections.Generic;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>using Demo.Core.Commands;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>using Demo.Core.Risks;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>using Demo.Core.Specification.Common;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>namespace Demo.Core.Specification
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>{
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public abstract class AbstractSpecification&amp;lt;T&amp;gt; : ISpecification&amp;lt;T&amp;gt;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> protected SpecificationResult result;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> protected IList&amp;lt;Type&amp;gt; ruleList = new List&amp;lt;Type&amp;gt;();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> protected bool SoftCheck { get; set; }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public T Candidate { get; set; }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public T Target { get; set; }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public bool IsReplay {protected get; set;}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public ISpecification&amp;lt;T&amp;gt; And(ISpecification&amp;lt;T&amp;gt; other)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> return new AndSpecification&amp;lt;T&amp;gt;(this, other);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public ISpecification&amp;lt;T&amp;gt; Or(ISpecification&amp;lt;T&amp;gt; other)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> return new OrSpecification&amp;lt;T&amp;gt;(this, other);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public ISpecification&amp;lt;T&amp;gt; XOr(ISpecification&amp;lt;T&amp;gt; other)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> return new XORSpecification&amp;lt;T&amp;gt;(this, other);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public ISpecification&amp;lt;T&amp;gt; AndAllOf(IEnumerable&amp;lt;ISpecification&amp;lt;T&amp;gt;&amp;gt; specifications)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> return new AndAllOfSpecification&amp;lt;T&amp;gt;(this, specifications);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public virtual bool Evaluate(T candidate)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> throw new NotImplementedException(&amp;#34;You need to provide a predicate or override IsSatisfiedBy&amp;#34;);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public virtual IDemoCommand GetCommand()
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> return new NoCommand();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public virtual void GetResults(ResultsVisitor visitor)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> if (result != null &amp;amp;&amp;amp; !string.IsNullOrEmpty(result.Message))
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> visitor.Add(result);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public virtual IEnumerable&amp;lt;Type&amp;gt; WhatWasAssessed()
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> return ruleList;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public virtual string MessageFormat()
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> throw new NotImplementedException(&amp;#34;You need to provide a result a message or override IsSatisfiedBy&amp;#34;);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public virtual bool IsSatisfiedBy(T candidate)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> if (IsReplay)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> return true;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Type ruleType = GetType();
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ruleList.Add(ruleType);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Candidate = candidate;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> bool satisfied = Evaluate(candidate);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> if (!satisfied || (SoftCheck &amp;amp;&amp;amp; !string.IsNullOrEmpty(result.Message)))
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> result = new SpecificationResult
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Satisfied = SoftCheck,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Message = string.Format(MessageFormat(), candidate, Target)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> };
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> return satisfied;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> public AbstractSpecification&amp;lt;T&amp;gt; SuccessOrRhs(ISpecification&amp;lt;T&amp;gt; specification)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> return new SuccessOrRhsSpecification&amp;lt;T&amp;gt;(specification);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item></channel></rss>