示例#1
0
        public void ShootAutomatically_ShouldUseTheShootingStrategyToShoot()
        {
            //Arrange
            _computerPlayer.ReloadBombs();

            var     playerBuilder = new PlayerBuilder();
            IPlayer opponent      = playerBuilder.Build();

            GridCoordinate determinedCoordinate = new GridCoordinateBuilder().Build();

            _shootingStrategyMock.Setup(ss => ss.DetermineTargetCoordinate()).Returns(determinedCoordinate);

            //Act
            _computerPlayer.ShootAutomatically(opponent);

            //Assert
            _shootingStrategyMock.Verify(ss => ss.DetermineTargetCoordinate(),
                                         "Use the DetermineTargetCoordinate method of the shooting strategy.");

            var opponentGridMock = playerBuilder.GridMock;

            opponentGridMock.Verify(g => g.Shoot(determinedCoordinate), Times.AtLeastOnce,
                                    "Use the ShootAt method to shoot at the opponent on the coordinate determined by the strategy.");

            _shootingStrategyMock.Verify(ss => ss.RegisterShotResult(It.IsAny <GridCoordinate>(), It.IsAny <ShotResult>()),
                                         "After shooting, the result should be registered with the shooting strategy.");
        }
        public void should_add_energy_when_not_enough()
        {
            var insufficientEnergyPlayer = new PlayerBuilder()
                                           .With(p => p.Id, 74)
                                           .With(p => p.FormSource, currentForm)
                                           .With(p => p.OriginalFormSource, originalForm)
                                           .With(p => p.ActionPoints, 50)
                                           .With(p => p.Mana, 25)
                                           .With(p => p.LastActionTimestamp, DateTime.UtcNow.AddHours(-1))
                                           .BuildAndSave();

            var cmd = new SelfRestoreToBase {
                PlayerId = insufficientEnergyPlayer.Id, Buffs = buffs
            };

            Assert.That(() => DomainRegistry.Repository.Execute(cmd), Throws.Nothing);

            var playerLoaded = DataContext.AsQueryable <Player>().First(p => p.Id == insufficientEnergyPlayer.Id);

            Assert.That(playerLoaded.Id, Is.EqualTo(insufficientEnergyPlayer.Id));
            Assert.That(playerLoaded.Gender, Is.EqualTo(currentForm.Gender));
            Assert.That(playerLoaded.FormSource.Id, Is.EqualTo(currentForm.Id));
            Assert.That(playerLoaded.FormSource.FriendlyName, Is.EqualTo(currentForm.FriendlyName));
            Assert.That(playerLoaded.ActionPoints, Is.EqualTo(47));
            Assert.That(playerLoaded.Mana, Is.EqualTo(15));
            Assert.That(playerLoaded.CleansesMeditatesThisRound, Is.EqualTo(1));
            Assert.That(playerLoaded.PlayerLogs.First().Message,
                        Is.EqualTo(
                            "You rest and attempt to restore yourself to your base form.  [+10, 10/100].  Keep trying and you'll find yourself in a familiar form in no time..."));
            Assert.That(playerLoaded.SelfRestoreEnergy.Amount, Is.EqualTo(10));
            Assert.That(playerLoaded.SelfRestoreEnergy.Timestamp, Is.EqualTo(DateTime.UtcNow).Within(10).Seconds);
            Assert.That(playerLoaded.LastActionTimestamp, Is.EqualTo(DateTime.UtcNow).Within(10).Seconds);
        }
        public void Should_fetch_no_items_of_nonbindable_types()
        {
            var owner = new PlayerBuilder()
                        .With(p => p.Id, 99)
                        .BuildAndSave();

            var consumable = new ItemBuilder()
                             .With(p => p.Id, 1)
                             .With(p => p.Owner, owner)
                             .With(p => p.ItemSource, new ItemSourceBuilder()
                                   .With(s => s.ItemType, PvPStatics.ItemType_Consumable)
                                   .BuildAndSave())
                             .BuildAndSave();

            var rune = new ItemBuilder()
                       .With(p => p.Id, 1)
                       .With(p => p.ItemSource, new ItemSourceBuilder()
                             .With(s => s.ItemType, PvPStatics.ItemType_Rune)
                             .BuildAndSave())
                       .BuildAndSave();

            var items = DomainRegistry.Repository.Find(new GetPlayerItemsOfSoulbindableTypes {
                OwnerId = owner.Id
            }).ToList();

            Assert.That(items, Has.Exactly(0).Items);
        }
示例#4
0
        public void should_throw_exception_if_player_is_not_feral_animal()
        {
            var petPlayer = new PlayerBuilder()
                            .With(p => p.Id, 51)
                            .With(p => p.Mobility, PvPStatics.MobilityPet)
                            .BuildAndSave();

            var item = new ItemBuilder()
                       .With(p => p.FormerPlayer, petPlayer)
                       .With(p => p.Owner, new PlayerBuilder()
                             .With(p => p.FirstName, "Bob")
                             .With(p => p.LastName, "Smith")
                             .BuildAndSave())
                       .BuildAndSave();

            petPlayer.SetItem(item);
            item.SetFormerPlayer(petPlayer);

            var cmd = new Move {
                PlayerId = 51, destination = destination
            };

            Assert.That(() => Repository.Execute(cmd),
                        Throws.TypeOf <DomainException>().With.Message
                        .EqualTo("You can't move because you are a non-feral pet owned by Bob Smith."));
        }
        public void UpdateRosterTeamId_PlayerIsNotCaptainOfExistingTeam_PlayerUpdated()
        {
            // Arrange
            Player        testPlayer = new PlayerBuilder().WithId(PLAYER_ID).WithTeamId(SPECIFIC_TEAM_ID).Build();
            List <Player> testRoster = new List <Player> {
                testPlayer
            };

            MockGetTeamRosterQuery(testRoster);

            Player        captain = new PlayerBuilder().WithId(SPECIFIC_PLAYER_ID).WithTeamId(ANOTHER_TEAM_ID).Build();
            List <Player> roster  = new List <Player> {
                captain
            };

            MockGetPlayerByFullNameQuery(captain);

            var teamToSet = new TeamBuilder().WithId(ANOTHER_TEAM_ID).Build();

            _getTeamByCaptainQueryMock.Setup(tr => tr.Execute(It.IsAny <FindByCaptainIdCriteria>())).Returns(null as Team);
            _getTeamByIdQueryMock.Setup(tr => tr.Execute(It.IsAny <FindByIdCriteria>())).Returns(teamToSet);

            // Act
            var ts = BuildSUT();

            ts.UpdateRosterTeamId(roster, ANOTHER_TEAM_ID);

            // Assert
            VerifyEditPlayer(SPECIFIC_PLAYER_ID, ANOTHER_TEAM_ID, Times.Once());
        }
        public void GiveInformationWithSuiteCallsReceiveInformation()
        {
            var ownedCard         = new Card(Suite.White, Number.One);
            var informationTokens = new Mock <ITokens>(MockBehavior.Strict);

            informationTokens
            .Setup(t => t.Amount)
            .Returns(1);
            informationTokens
            .Setup(t => t.Use());
            var playerBuilder = new PlayerBuilder
            {
                TableBuilder = new TableBuilder
                {
                    InformationTokens = informationTokens.Object,
                },
            };
            var player      = playerBuilder.Build();
            var otherPlayer = new Mock <IInformationReceiverReadOnlyPlayer>(MockBehavior.Strict);

            otherPlayer
            .Setup(p => p.Cards)
            .Returns(new List <Card> {
                ownedCard
            });
            otherPlayer
            .Setup(p => p.Information[ownedCard])
            .Returns(new Information());
            otherPlayer
            .Setup(p => p.ReceiveInformation(ownedCard.Suite));

            player.GiveInformation(otherPlayer.Object, ownedCard.Suite);

            otherPlayer.Verify(p => p.ReceiveInformation(ownedCard.Suite), Times.Once);
        }
示例#7
0
        public void should_not_change_mode_of_unrelated_soulbound_items_and_their_runes(int playerStartMode, int playerEndMode)
        {
            Player player;
            Item   pvpItem, pvpRune, pItem, pRune, commonItem, commonRune;

            SetUpPlayerWithSoulboundItems(out player, playerStartMode,
                                          out pvpItem, out pvpRune,
                                          out pItem, out pRune,
                                          out commonItem, out commonRune);

            var someOtherPlayer = new PlayerBuilder()
                                  .With(p => p.User, new UserBuilder()
                                        .With(u => u.Id, "other")
                                        .BuildAndSave()
                                        )
                                  .With(p => p.Id, 199)
                                  .With(p => p.GameMode, (int)playerStartMode)
                                  .BuildAndSave();

            SwitchPlayerModeForItems(someOtherPlayer, playerEndMode);

            Assert.That(pItem.PvPEnabled, Is.EqualTo((int)GameModeStatics.GameModes.Protection));
            Assert.That(pRune.PvPEnabled, Is.EqualTo((int)GameModeStatics.GameModes.Protection));
            Assert.That(pvpItem.PvPEnabled, Is.EqualTo((int)GameModeStatics.GameModes.PvP));
            Assert.That(pvpRune.PvPEnabled, Is.EqualTo((int)GameModeStatics.GameModes.PvP));
            Assert.That(commonItem.PvPEnabled, Is.EqualTo((int)GameModeStatics.GameModes.Any));
            Assert.That(commonRune.PvPEnabled, Is.EqualTo((int)GameModeStatics.GameModes.Any));
        }
        public void Create_TeamPassed_CaptainUpdated()
        {
            // Arrange
            var newTeam = new TeamBuilder().WithCaptain(SPECIFIC_PLAYER_ID).Build();

            _teamRepositoryMock.Setup(tr => tr.Add(It.IsAny <Team>()))
            .Callback <Team>(t => t.Id = SPECIFIC_TEAM_ID);

            var captain = new PlayerBuilder()
                          .WithId(SPECIFIC_PLAYER_ID)
                          .WithNoTeam()
                          .Build();

            _getPlayerByIdQueryMock.Setup(pr =>
                                          pr.Execute(It.Is <FindByIdCriteria>(
                                                         cr =>
                                                         cr.Id == captain.Id)))
            .Returns(captain);
            MockGetAllTeamsQuery(CreateSeveralTeams());

            // Act
            var sut = BuildSUT();

            sut.Create(newTeam);

            // Assert
            Assert.AreEqual(captain.TeamId, SPECIFIC_TEAM_ID);
            VerifyCreateTeam(newTeam, Times.Once());
        }
示例#9
0
        public void BuildWithLevelShouldThrowInvalidLevelException()
        {
            var level         = "iniciante";
            var playerBuilder = new PlayerBuilder(randomNumber);

            Assert.That(() => playerBuilder.WithLevel(level), Throws.TypeOf <InvalidLevelException>());
        }
示例#10
0
        private static void GivePlayerSoulboundItemWithRune(Player player, int offset, GameModeStatics.GameModes mode, out Item item, out Item rune)
        {
            var formerPlayer = new PlayerBuilder()
                               .With(p => p.User, new UserBuilder()
                                     .With(u => u.Id, "former")
                                     .BuildAndSave()
                                     )
                               .With(p => p.Id, 100 + offset)
                               .BuildAndSave();

            item = new ItemBuilder()
                   .With(i => i.Id, 500 + offset)
                   .With(i => i.FormerPlayer, formerPlayer)
                   .With(i => i.PvPEnabled, (int)mode)
                   .BuildAndSave();

            rune = new ItemBuilder()
                   .With(i => i.Id, 600 + offset)
                   .With(i => i.PvPEnabled, (int)mode)
                   .With(i => i.ItemSource, new ItemSourceBuilder()
                         .With(i => i.ItemType, PvPStatics.ItemType_Rune)
                         .BuildAndSave())
                   .BuildAndSave();

            item.SoulbindToPlayer(player);
            item.AttachRune(rune);
        }
示例#11
0
        public void CanMoveAsAnimal()
        {
            var stats = new List <Stat>
            {
                new StatBuilder().With(t => t.AchievementType, StatsProcedures.Stat__TimesMoved).With(t => t.Amount, 3).BuildAndSave()
            };

            var player = new PlayerBuilder()
                         .With(i => i.Location, LocationsStatics.STREET_200_SUNNYGLADE_DRIVE)
                         .With(p => p.User, new UserBuilder()
                               .With(u => u.Stats, stats)
                               .BuildAndSave())
                         .With(p => p.Item, new ItemBuilder()
                               .With(i => i.dbLocationName, "someplace")
                               .BuildAndSave()
                               )
                         .BuildAndSave();

            var destinationLogs = player.MoveToAsAnimal("coffee_shop_patio");

            Assert.That(destinationLogs.SourceLocationLog,
                        Is.EqualTo("John Doe (feral) left toward Carolyne's Coffee Shop (Patio)"));
            Assert.That(destinationLogs.DestinationLocationLog,
                        Is.EqualTo("John Doe (feral) entered from Street: 200 Sunnyglade Drive"));

            Assert.That(player.PlayerLogs.ElementAt(0).Message,
                        Is.EqualTo(
                            "You moved from <b>Street: 200 Sunnyglade Drive</b> to <b>Carolyne's Coffee Shop (Patio)</b>."));
            Assert.That(player.PlayerLogs.ElementAt(0).IsImportant, Is.False);

            Assert.That(player.Location, Is.EqualTo("coffee_shop_patio"));

            Assert.That(player.User.Stats.First(s => s.AchievementType == StatsProcedures.Stat__TimesMoved).Amount,
                        Is.EqualTo(4));
        }
示例#12
0
        public void ShootAt_ShouldReturnHitWhenAShipIsHit()
        {
            //Arrange
            var playerBuilder = new PlayerBuilder();

            playerBuilder.GridMock.Setup(g => g.Shoot(It.IsAny <GridCoordinate>())).Returns((GridCoordinate c) =>
                                                                                            new GridSquare(c)
            {
                Status = GridSquareStatus.Hit
            });
            var   kind    = ShipKind.All.NextRandomElement();
            IShip hitShip = new ShipBuilder(kind).Build();

            playerBuilder.FleetMock.Setup(f => f.FindShipAtCoordinate(It.IsAny <GridCoordinate>())).Returns(hitShip);

            IPlayer        opponent   = playerBuilder.Build();
            GridCoordinate coordinate = new GridCoordinateBuilder().Build();

            _humanPlayer.ReloadBombs();

            //Act
            var result = _humanPlayer.ShootAt(opponent, coordinate);

            //Assert
            playerBuilder.GridMock.Verify(g => g.Shoot(coordinate), Times.Once,
                                          "The Shoot method of the opponent grid should have been called.");
            Assert.That(result.ShotFired, Is.True, "The result should indicate that the shot was fired.");
            Assert.That(result.Hit, Is.True, "The result should indicate that it was a hit.");
            playerBuilder.FleetMock.Verify(f => f.FindShipAtCoordinate(coordinate), Times.Once,
                                           "Use the FindShipAtCoordinate of the opponent fleet to determine which kind of ship was hit.");
        }
示例#13
0
        /// <summary>
        /// [Worker Thread] : 検討モードに入る。
        /// GameModeのsetterから呼び出される。
        /// </summary>
        private void StartConsideration()
        {
            CanUserMove = true;

            // 検討モード用のプレイヤーセッティングを行う。
            {
                var setting = new GameSetting();

                switch (GameMode)
                {
                // 検討用エンジン
                case GameModeEnum.ConsiderationWithEngine:
                    setting.Player(Color.BLACK).PlayerName = "検討エンジン";
                    setting.Player(Color.BLACK).IsCpu      = true;
                    Players[0 /*検討用のプレイヤー*/] = PlayerBuilder.Create(PlayerTypeEnum.UsiEngine);
                    break;

                // 詰将棋エンジン
                case GameModeEnum.ConsiderationWithMateEngine:
                    setting.Player(Color.BLACK).PlayerName = "詰将棋エンジン";
                    setting.Player(Color.BLACK).IsCpu      = true;
                    Players[0 /* 詰将棋用のプレイヤー */]            = PlayerBuilder.Create(PlayerTypeEnum.UsiEngine);
                    break;
                }
                GameSetting = setting;
            }

            // 局面の設定
            kifuManager.EnableKifuList = false;

            // 検討ウィンドウへの読み筋などのリダイレクトを設定
            InitEngineConsiderationInfo(GameMode);
        }
示例#14
0
        public void ChangeOwner_automatically_equips_pets_and_not_other_items()
        {
            var newOwner = new PlayerBuilder()
                           .With(p => p.Id, 1)
                           .With(p => p.Location, "somewhere")
                           .BuildAndSave();

            var pet = new ItemBuilder()
                      .With(i => i.Id, 100)
                      .With(i => i.IsEquipped, false)
                      .With(i => i.Owner, null)
                      .With(i => i.dbLocationName, "somewhere")
                      .With(i => i.ItemSource, new ItemSourceBuilder()
                            .With(i => i.ItemType, PvPStatics.ItemType_Pet)
                            .BuildAndSave())
                      .BuildAndSave();

            var shirt = new ItemBuilder()
                        .With(i => i.Id, 100)
                        .With(i => i.IsEquipped, true)
                        .With(i => i.ItemSource, new ItemSourceBuilder()
                              .With(i => i.ItemType, PvPStatics.ItemType_Shirt)
                              .BuildAndSave())
                        .BuildAndSave();

            pet.ChangeOwner(newOwner);
            shirt.ChangeOwner(newOwner);

            Assert.That(pet.IsEquipped, Is.True);
            Assert.That(shirt.IsEquipped, Is.False);
        }
示例#15
0
        public void EXTRA_CreateFromGame_ShouldNotShowSunkenShipsOfOpponentIfSunkenShipsDoNotNeedToBeReported()
        {
            //Arrange
            IPlayer player   = new PlayerBuilder().WithFleetPositionedOnGrid(true).Build();
            IPlayer opponent = new PlayerBuilder().WithFleetPositionedOnGrid(true).Build();
            var     settings = new GameSettingsBuilder().WithMustReportSunkenShip(false).Build();
            var     game     = new GameBuilder().WithPlayers(player, opponent).WithSettings(settings).Build();

            IList <IShipInfo> opponentShipInfos = new List <IShipInfo>
            {
                new Mock <IShipInfo>().Object
            };

            _shipInfoFactoryMock.Setup(f => f.CreateMultipleFromSunkenShipsOfFleet(It.IsAny <Fleet>())).Returns(opponentShipInfos);

            //Act
            IGameInfo gameInfo = _factory.CreateFromGame(game, player.Id);

            //Assert
            Assert.That(gameInfo, Is.Not.Null, "No instance of a class that implements IGame is returned.");

            Assert.That(gameInfo.SunkenOpponentShips, Is.Not.Null, "SunkenOpponentShips must be an empty list.");
            Assert.That(gameInfo.SunkenOpponentShips.Count, Is.Zero, "SunkenOpponentShips must be an empty list.");

            _shipInfoFactoryMock.Verify(f => f.CreateMultipleFromSunkenShipsOfFleet(It.IsAny <Fleet>()), Times.Never,
                                        "CreateMultipleFromSunkenShipsOfFleet should not be called when sunken ships do not need to be reported.");
        }
        public void Create_PlayerIsCaptainOfExistingTeam_ValidationExceptionThrown()
        {
            // Arrange
            var newTeam = new TeamBuilder().Build();
            var captain = new PlayerBuilder().WithTeamId(SPECIFIC_TEAM_ID).Build();

            var captainLeadTeam = new TeamBuilder().WithId(SPECIFIC_TEAM_ID).Build();
            var testTeams       = new TeamServiceTestFixture().AddTeam(captainLeadTeam).Build();

            _getPlayerByIdQueryMock.Setup(pr =>
                                          pr.Execute(It.Is <FindByIdCriteria>(cr =>
                                                                              cr.Id == captain.Id)))
            .Returns(captain);
            _getTeamByCaptainQueryMock.Setup(tm =>
                                             tm.Execute(It.Is <FindByCaptainIdCriteria>(cr =>
                                                                                        cr.CaptainId == captain.Id)))
            .Returns(testTeams.Where(tm => tm.Id == captain.TeamId).FirstOrDefault());

            // Act
            var  sut          = BuildSUT();
            bool gotException = false;

            try
            {
                sut.Create(newTeam);
            }
            catch (ValidationException)
            {
                gotException = true;
            }

            // Assert
            Assert.IsTrue(gotException);
            VerifyCreateTeam(newTeam, Times.Never());
        }
示例#17
0
        public void Given_LeagueDoesNotExist_When_GetPlayerForTeamCompetitor_Then_ExceptionIsThrown()
        {
            // Arrange
            var teams   = new TeamsBuilder().Build();
            var players = new PlayerBuilder().Build();
            var builder = new TeamLeagueBuilder()
                          .WithCompetitors(teams)
                          .WithPlayers(teams[0], players);

            var teamLeague = builder.Build();

            var contextMock = MockDbContext(
                new List <TeamLeague> {
                teamLeague
            }.AsQueryable(),
                teamLeague.Competitors.Select(c => c.Team).AsQueryable()
                );
            var handler = new GetPlayerForTeamCompetitorQueryHandler(
                contextMock.Object,
                Mapper.MapperConfig());

            //Act
            var command = new GetPlayerForTeamCompetitorQuery
            {
                LeagueName = "DoesNotExist",
                TeamName   = "Tottenham Hotspur",
                PlayerName = "John Doe"
            };
            Func <Task> func = async() => await handler.Handle(command, CancellationToken.None);

            //Assert
            func.Should().Throw <TeamLeagueNotFoundException>();
        }
        public void UpdateRosterTeamId_InvalidPlayerId_MissingEntityExceptionThrown()
        {
            // Arrange
            Player        invalidPlayer = new PlayerBuilder().WithId(UNASSIGNED_ID).Build();
            List <Player> roster        = new List <Player> {
                invalidPlayer
            };

            MockGetTeamByIdQuery(new TeamBuilder().WithId(SPECIFIC_TEAM_ID).Build());

            var testPlayer = new PlayerBuilder().WithTeamId(SPECIFIC_TEAM_ID).Build();

            MockGetTeamRosterQuery(new List <Player> {
                testPlayer
            });

            // Act
            var  ts           = BuildSUT();
            bool gotException = false;

            try
            {
                ts.UpdateRosterTeamId(roster, SPECIFIC_TEAM_ID);
            }
            catch (MissingEntityException)
            {
                gotException = true;
            }

            // Assert
            Assert.IsTrue(gotException);
            VerifyEditPlayer(UNASSIGNED_ID, SPECIFIC_TEAM_ID, Times.Never());
        }
示例#19
0
        public void Given_LeagueDoesNotExist_When_UpdateTeamLeagueMatchLineupEntry_Then_LineupEntryNotFoundExceptionIsThrown()
        {
            // Arrange
            var builder = new TeamLeagueBuilder()
                          .WithCompetitors(new TeamsBuilder().Build())
                          .WithRounds();

            var teamLeague = builder.Build();
            var players    = new PlayerBuilder().Build();

            var contextMock = MockDbContext(
                Enumerable.Repeat(teamLeague, 1).AsQueryable(),
                players.AsQueryable()
                );

            var handler = new UpdateTeamLeagueMatchLineupEntryCommandHandler(
                contextMock.Object,
                Mapper.MapperConfig()
                );

            //Act
            var request = new UpdateTeamLeagueMatchLineupEntryCommand
            {
                LeagueName      = "DoesNotExist",
                MatchGuid       = new Guid("00000000-0000-0000-0000-000000000000"),
                TeamName        = "Tottenham Hotspur",
                LineupEntryGuid = new Guid("00000000-0000-0000-0000-000000000000"),
                PlayerName      = "John Doe",
                PlayerNumber    = "1"
            };
            Func <Task> func = async() => await handler.Handle(request, CancellationToken.None);

            //Assert
            func.Should().Throw <LineupEntryNotFoundException>();
        }
示例#20
0
        public void should_delete_player_and_their_stuff()
        {
            var owner = new PlayerBuilder()
                        .With(p => p.Id, 23)
                        .BuildAndSave();

            new SkillBuilder()
            .With(s => s.Id, 1)
            .With(s => s.Owner, owner)
            .BuildAndSave();

            new EffectBuilder()
            .With(s => s.Id, 2)
            .With(s => s.Owner, owner)
            .BuildAndSave();

            new PlayerLogBuilder()
            .With(s => s.Id, 3)
            .With(s => s.Owner, owner)
            .BuildAndSave();

            Assert.That(() => DomainRegistry.Repository.Execute(new DeletePlayer {
                PlayerId = 23
            }), Throws.Nothing);

            Assert.That(DataContext.AsQueryable <Player>().Where(p => p.Id == 23), Is.Empty);

            Assert.That(DataContext.AsQueryable <Skill>().Where(p => p.Id == 1), Is.Empty);

            Assert.That(DataContext.AsQueryable <Effect>().Where(p => p.Id == 2), Is.Empty);

            Assert.That(DataContext.AsQueryable <PlayerLog>().Where(p => p.Id == 3), Is.Empty);
        }
        public void UpdateRosterTeamId_PlayerAndTeamPassed_PlayerUpdated()
        {
            // Arrange
            var           firstPlayer  = new PlayerBuilder().WithId(PLAYER_ID).WithTeamId(SPECIFIC_TEAM_ID).Build();
            var           secondPlayer = new PlayerBuilder().WithId(PLAYER_ID + 1).WithFirstName("Second").WithTeamId(SPECIFIC_TEAM_ID).Build();
            List <Player> testRoster   = new List <Player> {
                firstPlayer, secondPlayer
            };

            MockGetTeamRosterQuery(testRoster);

            Player        player = new PlayerBuilder().WithId(SPECIFIC_PLAYER_ID).WithTeamId(null).Build();
            List <Player> roster = new List <Player> {
                player
            };

            MockGetPlayerByFullNameQuery(player);
            MockGetPlayerByIdQuery(player);

            var teamToSet = new TeamBuilder().WithId(SPECIFIC_TEAM_ID).Build();

            _getTeamByIdQueryMock.Setup(tr => tr.Execute(It.IsAny <FindByIdCriteria>())).Returns(teamToSet);

            // Act
            var ts = BuildSUT();

            ts.UpdateRosterTeamId(roster, SPECIFIC_TEAM_ID);

            // Assert
            VerifyEditPlayer(SPECIFIC_PLAYER_ID, SPECIFIC_TEAM_ID, Times.Exactly(2));
        }
        public void Should_fetch_no_items_with_mismatched_owner()
        {
            var owner = new PlayerBuilder()
                        .With(p => p.Id, 99)
                        .BuildAndSave();

            var nonowner = new PlayerBuilder()
                           .With(p => p.Id, 66)
                           .BuildAndSave();

            var nonBindableItem = new ItemBuilder()
                                  .With(p => p.Id, 1)
                                  .With(p => p.Owner, owner)
                                  .With(p => p.ItemSource, new ItemSourceBuilder()
                                        .With(s => s.ItemType, PvPStatics.ItemType_Consumable)
                                        .BuildAndSave())
                                  .BuildAndSave();

            var bindableItem = new ItemBuilder()
                               .With(p => p.Id, 1)
                               .With(p => p.ItemSource, new ItemSourceBuilder()
                                     .With(s => s.ItemType, PvPStatics.ItemType_Consumable_Reuseable)
                                     .BuildAndSave())
                               .BuildAndSave();

            var items = DomainRegistry.Repository.Find(new GetPlayerItemsOfSoulbindableTypes {
                OwnerId = nonowner.Id
            }).ToList();

            Assert.That(items, Has.Exactly(0).Items);
        }
        public void UpdateRosterTeamId_PlayerIsNotExist_PlayerNeverGetEdit()
        {
            // Arrange
            var           testPlayer       = new PlayerBuilder().WithId(PLAYER_ID).WithTeamId(SPECIFIC_TEAM_ID).Build();
            var           testSecondPlayer = new PlayerBuilder().WithId(PLAYER_ID + 1).WithTeamId(SPECIFIC_TEAM_ID).Build();
            List <Player> testRoster       = new List <Player> {
                testPlayer, testSecondPlayer
            };

            MockGetTeamRosterQuery(testRoster);

            Player        player = new PlayerBuilder().WithId(SPECIFIC_PLAYER_ID + 1).WithTeamId(null).Build();
            List <Player> roster = new List <Player> {
                player
            };

            var teamToSet = new TeamBuilder().WithId(SPECIFIC_TEAM_ID).Build();

            _getTeamByIdQueryMock.Setup(tr => tr.Execute(It.IsAny <FindByIdCriteria>())).Returns(teamToSet);

            var sut = BuildSUT();

            // Act
            try
            {
                sut.UpdateRosterTeamId(roster, SPECIFIC_TEAM_ID);
            }
            catch (MissingEntityException)
            {
            }

            // Assert
            VerifyEditPlayer(SPECIFIC_PLAYER_ID, SPECIFIC_TEAM_ID, Times.Never());
        }
示例#24
0
        public void Should_transfer_existing_item_with_no_player()
        {
            var george = new PlayerBuilder().With(p => p.Id, 55)
                         .With(p => p.FirstName, "George")
                         .BuildAndSave();

            new ItemBuilder().With(i => i.Id, 7)
            .With(i => i.Owner, george)
            .With(i => i.dbLocationName, "")
            .BuildAndSave();

            var cmdEdit = new UpdateItem
            {
                ItemId         = 7,
                OwnerId        = null,
                dbLocationName = "tampa"
            };

            Assert.That(() => Repository.Execute(cmdEdit), Throws.Nothing);

            var editedItem = DataContext.AsQueryable <Item>().FirstOrDefault(cr => cr.Id == 7);

            Assert.That(editedItem.Id, Is.EqualTo(7));
            Assert.That(editedItem.Owner, Is.Null);
            Assert.That(editedItem.dbLocationName, Is.EqualTo("tampa"));
        }
        public void Create_InvalidAchievements_ArgumentExceptionThrown()
        {
            string invalidAchievements = CreateInvalidTeamAchievements();
            string argExMessage        = string.Format(
                Resources.ValidationTeamAchievements,
                VolleyManagement.Domain.Constants.Team.MAX_ACHIEVEMENTS_LENGTH);
            var testTeam = new TeamBuilder()
                           .WithAchievements(invalidAchievements)
                           .Build();
            Player testPlayer = new PlayerBuilder().WithId(PLAYER_ID).Build();

            _getPlayerByIdQueryMock.Setup(pr => pr.Execute(It.Is <FindByIdCriteria>(cr => cr.Id == testPlayer.Id))).Returns(testPlayer);
            MockGetAllTeamsQuery(CreateSeveralTeams());
            Exception exception = null;
            var       sut       = BuildSUT();

            // Act
            try
            {
                sut.Create(testTeam);
            }
            catch (ArgumentException ex)
            {
                exception = ex;
            }

            // Assert
            VerifyExceptionThrown(
                exception,
                new ArgumentException(argExMessage, "Achievements"));
        }
示例#26
0
        public void Should_delete_all_message_owned_by_player()
        {
            var player = new PlayerBuilder()
                         .With(p => p.Id, 3)
                         .BuildAndSave();

            new MessageBuilder()
            .With(m => m.Id, 61)
            .With(m => m.Receiver, player)
            .BuildAndSave();

            new MessageBuilder()
            .With(m => m.Id, 79)
            .With(m => m.Receiver, player)
            .BuildAndSave();

            var cmd = new DeleteAllMessagesOwnedByPlayer {
                OwnerId = 3
            };

            Assert.That(() => Repository.Execute(cmd), Throws.Nothing);

            var messages = DataContext.AsQueryable <Message>();

            Assert.That(messages, Has.Exactly(2).Items);
            Assert.That(messages.First().IsDeleted, Is.True);
            Assert.That(messages.Last().IsDeleted, Is.True);
        }
        public void Create_InvalidTeamCoachNameNotAllowedSymbols_ArgumentExceptionThrown()
        {
            string invalidCoachName = "name%-)";
            string argExMessage     = string.Format(
                Resources.ValidationCoachName,
                VolleyManagement.Domain.Constants.Team.MAX_COACH_NAME_LENGTH);
            var testTeam = new TeamBuilder()
                           .WithCoach(invalidCoachName)
                           .Build();
            Player testPlayer = new PlayerBuilder().WithId(PLAYER_ID).Build();

            _getPlayerByIdQueryMock.Setup(pr => pr.Execute(It.Is <FindByIdCriteria>(cr => cr.Id == testPlayer.Id))).Returns(testPlayer);
            MockGetAllTeamsQuery(CreateSeveralTeams());
            Exception exception = null;
            var       sut       = BuildSUT();

            // Act
            try
            {
                sut.Create(testTeam);
            }
            catch (ArgumentException ex)
            {
                exception = ex;
            }

            // Assert
            VerifyExceptionThrown(
                exception,
                new ArgumentException(argExMessage, "Coach"));
        }
        public void Map_DomainPlayerAsParam_MappedToViewModel()
        {
            // Arrange
            var testViewModel = new PlayerMvcViewModelBuilder()
                                .WithId(1)
                                .WithFirstName("FirstName")
                                .WithLastName("LastName")
                                .WithBirthYear(1983)
                                .WithHeight(186)
                                .WithWeight(95)
                                .WithTeamId(1)
                                .Build();

            var testDomainModel = new PlayerBuilder(1, "FirstName", "LastName")
                                  .WithBirthYear(1983)
                                  .WithHeight(186)
                                  .WithWeight(95)
                                  .Build();

            // Act
            var actual = PlayerViewModel.Map(testDomainModel);

            // Assert
            Assert.Equal(testViewModel, actual, new PlayerViewModelComparer());
        }
        public void Create_InvalidCaptainId_MissingEntityExceptionThrown()
        {
            // Arrange
            var    newTeam    = new TeamBuilder().Build();
            Player testPlayer = new PlayerBuilder().WithId(SPECIFIC_PLAYER_ID).Build();

            _getPlayerByIdQueryMock.Setup(pr => pr.Execute(It.Is <FindByIdCriteria>(cr => cr.Id == testPlayer.Id))).Returns(testPlayer);

            // Act
            var  sut          = BuildSUT();
            bool gotException = false;

            try
            {
                sut.Create(newTeam);
            }
            catch (MissingEntityException)
            {
                gotException = true;
            }

            // Assert
            Assert.IsTrue(gotException);
            VerifyCreateTeam(newTeam, Times.Never());
        }
示例#30
0
        public void can_create_tf_energy()
        {
            var player = new PlayerBuilder()
                         .With(i => i.Id, 50)
                         .BuildAndSave();

            var caster = new PlayerBuilder()
                         .With(i => i.Id, 987)
                         .BuildAndSave();

            var form = new FormSourceBuilder()
                       .With(i => i.Id, 13)
                       .BuildAndSave();

            DomainRegistry.Repository.Execute(new CreateTFEnergy
            {
                PlayerId     = player.Id,
                Amount       = 100,
                FormSourceId = form.Id,
                CasterId     = caster.Id
            });

            Assert.That(DataContext.AsQueryable <TFEnergy>().Where(t =>
                                                                   t.Owner.Id == 50 &&
                                                                   t.Caster.Id == 987 &&
                                                                   t.Amount == 100 &&
                                                                   t.FormSource.Id == 13), Has.Exactly(1).Items);
        }
示例#31
0
        public void GivenAPlayer(string playerName)
        {
            var player = new PlayerBuilder()
                                .WithName(playerName)
                                .Build();

            SaveDomainObject(player);
        }