|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MockByExample.Calculators;
using Rhino.Mocks;
namespace MockByExample.Tests
{
[TestClass]
public class BusinessRuleCalculatorPublicApiTests : BusinessRuleCalculator
{
/// <summary>
/// If zero value is passed the method returns Zero
/// </summary>
[TestMethod]
public void GetRuleForZeroCase()
{
var calculator = new BusinessRuleCalculator();
const RuleType expected = RuleType.Zero;
var result = calculator.GetRule(0);
Assert.AreEqual(expected, result);
}
/// <summary>
/// Value is positive so ensure that the GetRuleForPositive
/// method is invoked and that the GetRuleForNegative is not
/// </summary>
[TestMethod]
public void GetRuleForPositiveValue()
{
var calculator = MockRepository
.GeneratePartialMock<BusinessRuleCalculatorPublicApiTests>();
const int value = 1;
const RuleType expected = RuleType.PositiveNormalCase;
calculator.Expect(c => c.GetRuleForPositive(value))
.Return(expected)
.Repeat.Once();
calculator.Expect(c => c.GetRuleForNegative(value))
.IgnoreArguments()
.Repeat.Never();
var result = calculator.GetRule(value);
Assert.AreEqual(expected, result);
calculator.VerifyAllExpectations();
}
/// <summary>
/// Value is positive so ensure that the GetRuleForPositive
/// method is invoked and that the GetRuleForNegative is not
/// </summary>
[TestMethod]
public void GetRuleForNegativeValue()
{
var calculator = MockRepository.GeneratePartialMock<BusinessRuleCalculatorPublicApiTests>();
const int value = -1;
const RuleType expected = RuleType.NegativeNormalCase;
calculator.Expect(c => c.GetRuleForPositive(value))
.IgnoreArguments()
.Repeat.Never();
calculator.Expect(c => c.GetRuleForNegative(value))
.Return(expected)
.Repeat.Once();
var result = calculator.GetRule(value);
Assert.AreEqual(expected, result);
calculator.VerifyAllExpectations();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.