Skip to content

Commit

Permalink
Added tests to check setup up time
Browse files Browse the repository at this point in the history
  • Loading branch information
CeesKaas committed Nov 28, 2020
1 parent f2aa090 commit d90d3b1
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/Moq.Tests/MockFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1312,5 +1312,37 @@ public void Accessing_property_of_bad_serializable_type_after_SetupAllProperties
Assert.ThrowsAny<Exception>(() => mock.Object.BadSerializable);
}
#endif

public interface ITestInterface
{
void Get(Guid id);
}

[Fact]
public void Thousand_different_setups_can_be_done_in_under_a_second()
{
var sw = System.Diagnostics.Stopwatch.StartNew();
var mock = new Mock<ITestInterface>();
for (int i = 0; i < 1000; i++)
{
mock.Setup(m => m.Get(Guid.NewGuid()));
}
sw.Stop();
Assert.True(sw.Elapsed < TimeSpan.FromSeconds(1), $"Setups were expected to take less than a second but it took {sw.Elapsed}");
}

[Fact]
public void Thousand_same_setups_can_be_done_in_under_a_second()
{
var sw = System.Diagnostics.Stopwatch.StartNew();
var mock = new Mock<ITestInterface>();
var id = Guid.NewGuid();
for (int i = 0; i < 1000; i++)
{
mock.Setup(m => m.Get(id));
}
sw.Stop();
Assert.True(sw.Elapsed < TimeSpan.FromSeconds(1), $"Setups were expected to take less than a second but it took {sw.Elapsed}");
}
}
}

0 comments on commit d90d3b1

Please sign in to comment.