コード例 #1
0
        public static PlayManager CreateDefaultPlayManager()
        {
            var player          = new PlayerMock();
            var playlistManager = new PlaylistManager(new PlaylistDatabase(new PlaylistIOMock()), null);
            var taskHost        = new StartSongTaskHostMock();

            return(new PlayManager(player, playlistManager, taskHost));
        }
コード例 #2
0
ファイル: GameTest.cs プロジェクト: tealpaintedduck/rps_cs
 public void GetReady()
 {
     player = new PlayerMock ("Ron");
     computerPlayer = new PlayerMock ();
     computerPlayerTwo = new PlayerMock ();
     game = new Game (player, computerPlayer);
     computerGame = new Game (computerPlayer, computerPlayerTwo);
 }
コード例 #3
0
        public void ThrowArgumentNullException_WhenPassedNullValue()
        {
            //Arrange
            string invalidUser = null;

            var playerMock = new PlayerMock(invalidUser);


            //Act & Assert
            Assert.ThrowsException <ArgumentNullException>(() =>
                                                           playerMock.GetPlayer(invalidUser));
        }
コード例 #4
0
        public void T02bSidePlayerIsOn_ReturnsFront()
        {
            var doorDirection = new Vector3(-1, 0, 0);
            var doorPosition  = new Vector3(0, 0, 0);
            var doorMock      = new DoorMock(doorPosition, doorDirection);

            var playerPos    = new Vector3(-10, 0, 0);
            var playerMock   = new PlayerMock(playerPos);
            var sut          = new DoorDetection(doorMock, playerMock);
            var playerSideOn = sut.PlayerSideOn();

            Assert.AreEqual(DoorDetection.DoorSide.Front, playerSideOn);
        }
コード例 #5
0
        public void T01dSidePlayerIsOn_ReturnsBack()
        {
            var doorDirection = new Vector3(0, 0, 1);
            var doorPosition  = new Vector3(0, 0, 0);
            var doorMock      = new DoorMock(doorPosition, doorDirection);

            var playerPos    = new Vector3(2, 0, -1);
            var playerMock   = new PlayerMock(playerPos);
            var sut          = new DoorDetection(doorMock, playerMock);
            var playerSideOn = sut.PlayerSideOn();

            Assert.AreEqual(DoorDetection.DoorSide.Back, playerSideOn);
        }
コード例 #6
0
        public void RunStartSongTaskTest()
        {
            var lck              = new object();
            var queueItem        = new QueueItem(Constants.Resource1AYoutube, new MetaData(Constants.TestUid, Constants.ListId));
            var queueItemGain    = new QueueItem(Constants.Resource1AYoutubeGain, new MetaData(Constants.TestUid, Constants.ListId));
            var playResource     = new PlayResource(queueItem.AudioResource.ResourceId, queueItem.AudioResource, queueItem.MetaData);
            var playResourceGain = new PlayResource(queueItemGain.AudioResource.ResourceId, queueItemGain.AudioResource, queueItemGain.MetaData);

            {
                // Queue item without gain gets it set and update gets invoked
                var loaderContext = new LoaderContextMock();
                var player        = new PlayerMock();

                var task = new StartSongTask(loaderContext, player, Constants.VolumeConfig, lck, queueItem);

                AudioResource changedResource     = null;
                QueueItem     containingQueueItem = null;
                task.OnAudioResourceUpdated += (sender, args) => {
                    changedResource     = args.Resource;
                    containingQueueItem = args.QueueItem;
                };

                var waitHandle  = new InformingEventWaitHandle(false, EventResetMode.AutoReset);
                var tokenSource = new CancellationTokenSource();
                var t           = Task.Run(() => task.RunInternal(waitHandle, tokenSource.Token));

                // Wait that the task reached the first point, cancel
                waitHandle.OutputHandle.WaitOne();
                tokenSource.Cancel();
                waitHandle.Set();

                // Check that it actually failed
                AssertThrowsInnerException <AggregateException, TaskCanceledException>(() => {
                    var _ = t.Result;
                });

                Assert.NotNull(changedResource);
                Assert.NotNull(containingQueueItem);
                Assert.AreSame(containingQueueItem, queueItem);

                var gain = changedResource.Gain;
                Assert.IsTrue(gain.HasValue);
                Assert.AreEqual(gain.Value, VolumeDetectorMock.VolumeSet);
            }

            {
                var loaderContext = new LoaderContextMock();
                var player        = new PlayerMock();

                var task = new StartSongTask(loaderContext, player, Constants.VolumeConfig, lck, queueItem);

                var waitHandle  = new InformingEventWaitHandle(false, EventResetMode.AutoReset);
                var tokenSource = new CancellationTokenSource();
                var t           = Task.Run(() => task.RunInternal(waitHandle, tokenSource.Token));

                // Wait that the task reached the first point, cancel
                waitHandle.OutputHandle.WaitOne();
                lock (lck) {
                    waitHandle.Set();
                    Task.Delay(100);
                    tokenSource.Cancel();
                }

                AssertThrowsInnerException <AggregateException, TaskCanceledException>(() => {
                    var _ = t.Result;
                });
            }

            {
                var player = new PlayerMock();

                var task = new StartSongTask(null, player, Constants.VolumeConfig, null, null);
                PlayInfoEventArgs argsBefore = null;
                PlayInfoEventArgs argsAfter  = null;

                task.BeforeResourceStarted += (sender, args) => {
                    Assert.IsNotNull(args);
                    Assert.AreEqual(args.Invoker, Constants.TestUid);
                    Assert.AreSame(args.MetaData, queueItemGain.MetaData);
                    Assert.AreSame(args.ResourceData, queueItemGain.AudioResource);
                    Assert.AreSame(args.SourceLink, LoaderContextMock.RestoredLink);
                    argsBefore = args;
                };

                task.AfterResourceStarted += (sender, args) => {
                    Assert.IsNotNull(args);
                    Assert.AreEqual(args.Invoker, Constants.TestUid);
                    Assert.AreSame(args.MetaData, queueItemGain.MetaData);
                    Assert.AreSame(args.ResourceData, queueItemGain.AudioResource);
                    Assert.AreSame(args.SourceLink, LoaderContextMock.RestoredLink);
                    argsAfter = args;
                };

                var t = Task.Run(() => task.StartResource(new SongAnalyzerResult {
                    Resource = playResourceGain, RestoredLink = LoaderContextMock.RestoredLink
                }));

                var res = t.Result;

                Assert.IsTrue(res.Ok);
                Assert.AreSame(argsBefore, argsAfter);

                Assert.NotNull(player.PlayArgs.res);
                Assert.NotNull(player.PlayArgs.gain);
                Assert.AreSame(player.PlayArgs.res, playResourceGain);
                Assert.AreEqual(player.PlayArgs.gain, queueItemGain.AudioResource.Gain);
                Assert.AreEqual(player.Volume, 10.0f);
            }

            {
                var player = new PlayerMock();

                var task = new StartSongTask(null, player, Constants.VolumeConfig, null, null);
                var t    = Task.Run(() => task.StartResource(new SongAnalyzerResult {
                    Resource = playResource, RestoredLink = LoaderContextMock.RestoredLink
                }));

                var res = t.Result;

                Assert.IsTrue(res.Ok);

                Assert.NotNull(player.PlayArgs.res);
                Assert.NotNull(player.PlayArgs.gain);
                Assert.AreSame(player.PlayArgs.res, playResource);
                Assert.AreEqual(player.PlayArgs.gain, 0);
                Assert.AreEqual(player.Volume, 10.0f);
            }
        }
コード例 #7
0
        public void ComputerPlayerTest_1()
        {
            var computerPlayer = new ComputerPlayer("P1", _wrapper, _treeManager);
            var anotherPlayer  = new PlayerMock("P2");

            var board1Str = new[]
            {
                "_____",
                "_b___",
                "_____",
                "_b___",
                "w____"
            };
            var board1 = new BoardMock(board1Str, 5, false);

            board1.ActivePlayer.Figures
            .First(f => f.X == 0 && f.Y == 4)
            .AvailableMoves = new List <Cell> {
                new Cell(1, 3)
            };

            var board2Str = new[]
            {
                "_____",
                "_b___",
                "__w__",
                "_____",
                "_____"
            };
            var board2 = new BoardMock(board2Str, 5, false);

            board2.ActivePlayer.Figures
            .First(f => f.X == 2 && f.Y == 2)
            .AvailableMoves = new List <Cell> {
                new Cell(0, 0)
            };

            var board3Str = new[]
            {
                "W____",
                "_____",
                "_____",
                "_____",
                "_____"
            };
            var board3 = new BoardMock(board3Str, 5, false);

            board3.SwitchPlayers();

            var gameMock = new GameMock(
                new[] { board1, board2, board3 },
                new IPlayer[] { computerPlayer, computerPlayer, anotherPlayer });

            var cts = new CancellationTokenSource();

            computerPlayer.MakeMove(gameMock, cts.Token).Wait();

            gameMock.Moves
            .Should()
            .BeEquivalentTo(new[]
            {
                new Move(0, 4, 1, 3),
                new Move(2, 2, 0, 0)
            });
        }