-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#31 Add addition, subtraction, and multiplication
- Loading branch information
Showing
3 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Pose.Tests | ||
{ | ||
public class OperatorTests | ||
{ | ||
[Fact] | ||
public void Can_shim_addition_operator() | ||
{ | ||
// Arrange | ||
var shimmedValue = new DateTime(2004, 01, 01); | ||
var dateTimeAddShim = Shim.Replace(() => Is.A<DateTime>() + Is.A<TimeSpan>()) | ||
.With(delegate(DateTime dt, TimeSpan ts) { return shimmedValue; }); | ||
|
||
// Act | ||
var result = default(DateTime); | ||
PoseContext.Isolate( | ||
() => | ||
{ | ||
var now = DateTime.Now; | ||
var zeroSeconds = TimeSpan.Zero; | ||
|
||
result = now + zeroSeconds; | ||
}, dateTimeAddShim); | ||
|
||
// Assert | ||
result.Should().Be(shimmedValue, because: "that is the value the shim is configured to return"); | ||
} | ||
|
||
[Fact] | ||
public void Can_shim_subtraction_operator() | ||
{ | ||
// Arrange | ||
var shimmedValue = new DateTime(2004, 01, 01); | ||
var dateTimeAddShim = Shim.Replace(() => Is.A<DateTime>() - Is.A<TimeSpan>()) | ||
.With(delegate(DateTime dt, TimeSpan ts) { return shimmedValue; }); | ||
|
||
// Act | ||
var result = default(DateTime); | ||
PoseContext.Isolate( | ||
() => | ||
{ | ||
var now = DateTime.Now; | ||
var zeroSeconds = TimeSpan.Zero; | ||
|
||
result = now - zeroSeconds; | ||
}, dateTimeAddShim); | ||
|
||
// Assert | ||
result.Should().Be(shimmedValue, because: "that is the value the shim is configured to return"); | ||
} | ||
|
||
[Fact] | ||
public void Can_shim_multiplication_operator() | ||
{ | ||
// Arrange | ||
var shimmedValue = int.MaxValue; | ||
var dateTimeAddShim = Shim.Replace(() => Is.A<int>() * Is.A<int>()) | ||
.With(delegate(int l, int r) { return shimmedValue; }); | ||
|
||
// Act | ||
var result = default(int); | ||
PoseContext.Isolate( | ||
() => | ||
{ | ||
result = 1 * 1; | ||
}, dateTimeAddShim); | ||
|
||
// Assert | ||
result.Should().Be(shimmedValue, because: "that is the value the shim is configured to return"); | ||
} | ||
} | ||
} |