Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Create tests for Mock.Reset #220

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions Telerik.JustMock.Tests/MockResetFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using System;
using System.Threading;
using System.Threading.Tasks;

#region JustMock Test Attributes
#if NUNIT
using NUnit.Framework;
using TestCategory = NUnit.Framework.CategoryAttribute;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using AssertionException = NUnit.Framework.AssertionException;
#if NUNIT3
using ClassInitialize = NUnit.Framework.OneTimeSetUpAttribute;
using ClassCleanup = NUnit.Framework.OneTimeTearDownAttribute;
#endif
#elif XUNIT
using Xunit;
using Telerik.JustMock.XUnit.Test.Attributes;
using TestCategory = Telerik.JustMock.XUnit.Test.Attributes.XUnitCategoryAttribute;
using TestClass = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestClassAttribute;
using TestMethod = Xunit.FactAttribute;
using TestInitialize = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestInitializeAttribute;
using TestCleanup = Telerik.JustMock.XUnit.Test.Attributes.EmptyTestCleanupAttribute;
using AssertionException = Telerik.JustMock.XUnit.AssertFailedException;
#elif VSTEST_PORTABLE
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using AssertionException = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.AssertFailedException;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AssertionException = Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException;
#endif
#endregion

namespace Telerik.JustMock.Tests
{
[TestClass]
public class MockResetFixture
{
#if NUNIT && NUNIT3
private static Foo staticFoo;
[ClassInitialize]
public static void ClassInitialize()
{
staticFoo = Mock.Create<Foo>();
Mock.Arrange(() => staticFoo.FooNotImplemented());
}

[ClassCleanup]
public static void ClassCleanup()
{
Mock.Reset();
Assert.Throws<NotImplementedException>(() => staticFoo.FooNotImplemented());
}
#else
private static Foo staticFoo;
[ClassInitialize]
public static void ClassInitialize(TestContext ctx)
{
staticFoo = Mock.Create<Foo>();
Mock.Arrange(() => staticFoo.FooNotImplemented());
}

[ClassCleanup]
public static void ClassCleanup()
{
Mock.Reset();
Assert.Throws<NotImplementedException>(() => staticFoo.FooNotImplemented());
}
#endif
private Foo myFoo;
[TestInitialize]
public void TestInit()
{
myFoo = Mock.Create<Foo>();
Mock.Arrange(() => myFoo.FooNotImplemented());
}

[TestCleanup]
public void TestCleanup()
{
Mock.Reset();
Assert.Throws<NotImplementedException>(() => myFoo.FooNotImplemented());
}

[TestMethod]
public void ThrowNotImplementedAfterMockReset()
{
// Arrange
var myFoo = Mock.Create<Foo>();

// Act
Mock.Reset();

// Assert
Assert.Throws<NotImplementedException>(() => myFoo.FooNotImplemented());
}

[TestMethod]
public void DoNotThrowErrorWithMockReset()
{
// Act
Mock.Reset();

// Assert
myFoo.FooNotImplemented();

}

class Foo
{
public void FooNotImplemented()
{
throw new NotImplementedException();
}
}

}
}
1 change: 1 addition & 0 deletions Telerik.JustMock.Tests/Telerik.JustMock.Tests.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<Compile Include="$(MSBuildThisFileDirectory)MatchersFixture.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MiscFixture.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MockFixture.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MockResetFixture.cs" />
<Compile Include="$(MSBuildThisFileDirectory)NinjectAutoMockFixture.cs" />
<Compile Include="$(MSBuildThisFileDirectory)NonPublicFixture.cs" />
<Compile Include="$(MSBuildThisFileDirectory)OccurrenceFixture.cs" />
Expand Down