Skip to content

Instantly share code, notes, and snippets.

@spettifer
Last active February 13, 2020 17:44
Show Gist options
  • Save spettifer/51ba4f7a3ccd80069e3fb7a0502374b3 to your computer and use it in GitHub Desktop.
Save spettifer/51ba4f7a3ccd80069e3fb7a0502374b3 to your computer and use it in GitHub Desktop.
A very contrived example of using a test double for CloudTable using NSubstitute in a unit test
// This is not runnable as is, but shows the basic principle. Note that the cloud table test double is being used as a stub,
// not a spy or a mock, although it could fulfill either of those roles with additional setup if required.
[Fact]
public async Task ExampleUnitTestWithCloudTableTestDouble()
{
var testResult = new TableResult
{
Result = new MyEntity()
{
ETag = "*",
PartitionKey = "PartitionKey",
RowKey = "RowKey",
MyProperty = "SomeValue"
},
HttpStatusCode = 200
};
var subCloudTable = Substitute.For<CloudTable>(new Uri("tempuir.org"));
subCloudTable.ExecuteAsync(Arg.Any<TableOperation>()).Returns(testResult);
var actual = await sut.DoSomething(subCloudTable);
actual.Should().Be(expected);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment