Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using Moq;
using NUnit.Framework;
using Zenject;
[TestFixture]
public class OthelloBoardPresenterTests : ZenjectUnitTestFixture {
[Test]
public void ViewInvokeOnClickTileEventAt3d_Default_ModelTryPlaceDiskAt3d() {
Mock<IOthelloBoardModel> mockModel = new Mock<IOthelloBoardModel>();
Mock<IOthelloBoardView> mockView = new Mock<IOthelloBoardView>();
Container.Bind<IOthelloBoardModel>().FromInstance( mockModel.Object ).AsSingle();
Container.Bind<IOthelloBoardView>().FromInstance( mockView.Object ).AsSingle();
Container.Bind<OthelloBoardPresenter>().AsSingle();
Container.Resolve<OthelloBoardPresenter>();
mockView.Raise( view => view.OnClickTile += null, 3, 4 );
mockModel.Verify( model => model.TryPlaceDisk( 3, 4 ) );
}
[Test]
public void ModelInvokeOnPlaceDiskEventAt3d_Default_ViewPlaceDiskAt3d() {
Mock<IOthelloBoardModel> mockModel = new Mock<IOthelloBoardModel>();
Mock<IOthelloBoardView> mockView = new Mock<IOthelloBoardView>();
Container.Bind<IOthelloBoardModel>().FromInstance( mockModel.Object ).AsSingle();
Container.Bind<IOthelloBoardView>().FromInstance( mockView.Object ).AsSingle();
Container.Bind<OthelloBoardPresenter>().AsSingle();
Container.Resolve<OthelloBoardPresenter>();
mockModel.Raise( model => model.OnPlaceDisk += null, 3, 4, It.IsAny<Disk>() );
mockView.Verify( view => view.PlaceDisk( 3, 4, It.IsAny<Disk>() ) );
}
[Test]
public void ModelInvokeOnFlipDiskEventAt4d_Default_ViewFlipDiskAt4d() {
Mock<IOthelloBoardModel> mockModel = new Mock<IOthelloBoardModel>();
Mock<IOthelloBoardView> mockView = new Mock<IOthelloBoardView>();
Container.Bind<IOthelloBoardModel>().FromInstance( mockModel.Object ).AsSingle();
Container.Bind<IOthelloBoardView>().FromInstance( mockView.Object ).AsSingle();
Container.Bind<OthelloBoardPresenter>().AsSingle();
Container.Resolve<OthelloBoardPresenter>();
mockModel.Raise( model => model.OnFlipDisk += null, 4, 4 );
mockView.Verify( view => view.FlipDisk( 4, 4 ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment