Beispiel #1
0
        public void GetAllEntriesForLadder_ReturnsAllEntriesForGivenLadder()
        {
            var myLadderId = "My Ladder Id";
            var myEntry    = new LadderEntry
            {
                LadderId = myLadderId,
                Platform = "PC",
                Score    = 123,
                Username = "******"
            };
            var myLadderList = new List <LadderEntry>
            {
                new LadderEntry(),
                new LadderEntry(),
                new LadderEntry(),
                new LadderEntry(),
            };

            myLadderList.Add(myEntry);

            _repository
            .Setup(r => r.GetAllEntriesForLadder(myLadderId))
            .Returns(myLadderList);

            var service = new LadderService(_repository.Object, _logger.Object);

            var result = service.GetAllEntriesForLadder(myLadderId);

            result
            .Should()
            .NotBeEmpty()
            .And.HaveCount(5)
            .And.ContainEquivalentOf(myEntry);
        }
Beispiel #2
0
        public void GetEntryForUser_ReturnsNullWhenInputIsNotValid(string ladderId, string platform, string username)
        {
            var service = new LadderService(_repository.Object, _logger.Object);

            service
            .GetEntryForUser(ladderId, platform, username)
            .Should()
            .BeNull();
        }
Beispiel #3
0
        public void Upsert_ReturnsNullWhenNullIsPassed()
        {
            var service = new LadderService(_repository.Object, _logger.Object);

            service
            .Upsert(null)
            .Should()
            .BeNull();
        }
Beispiel #4
0
        public void GetAllEntriesForLadder_ReturnsEmptyListIfLadderIdIsNullOrEmpty(string ladderId)
        {
            var service = new LadderService(_repository.Object, _logger.Object);

            service
            .GetAllEntriesForLadder(ladderId)
            .Should()
            .NotBeNull()
            .And.BeEmpty();
        }
            public void GamesAreCreated()
            {
                // Arrange
                var mockUnitOfWork = TestUtils.GetUnitOfWorkMock();

                mockUnitOfWork.SetupGet(x => x.Games).Returns(new MockGamesRepository());
                mockUnitOfWork.SetupGet(x => x.Ladders).Returns(new MockLadderRepository());
                var unitOfWork = mockUnitOfWork.Object;

                var gameServiceMock = new Mock <IGameService>();

                gameServiceMock.Setup(x => x.Create(
                                          Enums.GameType.Ranking,
                                          It.IsAny <User>(),
                                          It.IsAny <string>(),
                                          It.IsAny <string>(),
                                          It.IsAny <string>(),
                                          It.IsAny <Domain.Games.GameOptions>()))
                .Returns(TestUtils.CreateGame(2, 1, Enums.GameType.Ranking));

                var ladderService = new LadderService(unitOfWork, gameServiceMock.Object, TestUtils.MockMapTemplateProvider(), new Mock <IEventAggregator>().Object);

                var mapTemplate = TestUtils.GetMapTemplate();

                var ladder = new Ladder("Default", 2, 1);

                ladder.MapTemplates.Add(mapTemplate.Name);

                ladder.Options.MapDistribution = Enums.MapDistribution.Default;
                ladder.Options.VisibilityModifier.Add(Enums.VisibilityModifierType.None);

                ladder.ToggleActive(true);

                unitOfWork.Ladders.Add(ladder);

                var user1 = TestUtils.CreateUser("1");
                var user2 = TestUtils.CreateUser("2");

                ladder.QueueUser(user1);
                ladder.QueueUser(user2);

                // Act
                ladderService.CheckAndCreateMatches(new TestRandomGen());

                // Assert
                Assert.IsTrue(ladder.Games.Any());
                var game = ladder.Games.First();

                Assert.AreEqual(Enums.GameState.Active, game.State);
                Assert.AreEqual(Enums.GameType.Ranking, game.Type);
                Assert.AreEqual(ladder, game.Ladder);
                Assert.IsFalse(ladder.Queue.Any());
            }
Beispiel #6
0
        public void DeleteEntry_LogsErrorWhenRepositoryThrows()
        {
            var myLadder         = "myLadder";
            var myPlatform       = "myPlatform";
            var myUsername       = "******";
            var exceptionMessage = "An error occurred because blablabalabla";

            _repository
            .Setup(r => r.DeleteEntry(myLadder, myPlatform, myUsername))
            .Throws(new Exception(exceptionMessage));

            var service = new LadderService(_repository.Object, _logger.Object);
            var result  = service.DeleteEntry(myLadder, myPlatform, myUsername);

            _logger.Verify(l => l.LogError(It.IsAny <Exception>(), It.IsAny <string>()), Times.Once(), "Logger not called");
        }
Beispiel #7
0
        public void DeleteEntry_ReturnsTrueWhenEntryExists()
        {
            var myLadder   = "myLadder";
            var myPlatform = "myPlatform";
            var myUsername = "******";

            _repository
            .Setup(r => r.DeleteEntry(myLadder, myPlatform, myUsername))
            .Returns(true);

            var service = new LadderService(_repository.Object, _logger.Object);

            var result = service.DeleteEntry(myLadder, myPlatform, myUsername);

            result.Should().Be(true);
        }
Beispiel #8
0
        public void GetAllEntriesForLadder_ReturnsEmptyListIfLadderIdIsOkButServerHasNoEntryForThatLadder()
        {
            var myLadderId = "My Ladder Id";

            _repository
            .Setup(r => r.GetAllEntriesForLadder(myLadderId))
            .Returns(new List <LadderEntry>());

            var service = new LadderService(_repository.Object, _logger.Object);

            var result = service.GetAllEntriesForLadder(myLadderId);

            result
            .Should()
            .BeEmpty();
        }
Beispiel #9
0
        public void GetTopEntries_LogsErrorWhenRepositoryThrows()
        {
            var myLadderId = "My Ladder Id";

            var exceptionMessage = "An error occurred because blablabalabla";

            _repository
            .Setup(r => r.GetTopEntries(myLadderId))
            .Throws(new Exception(exceptionMessage));

            var service = new LadderService(_repository.Object, _logger.Object);

            service.GetTopEntries(myLadderId);

            _logger.Verify(l => l.LogError(It.IsAny <Exception>(), It.IsAny <string>()), Times.Once());
        }
Beispiel #10
0
        public void GetEntryForUser_ReturnsNullWhenInputIsOkButThereAreNoEntriesCorrespondingToThatKey()
        {
            var myLadderId = "My Ladder Id";
            var myPlatform = "PC";
            var myUsername = "******";

            _repository
            .Setup(r => r.GetEntryForUser(myLadderId, myPlatform, myUsername))
            .Returns <LadderEntry>(null);

            var service = new LadderService(_repository.Object, _logger.Object);

            service
            .GetEntryForUser(myLadderId, myPlatform, myUsername)
            .Should()
            .BeNull();
        }
Beispiel #11
0
        public void GetEntryForUser_LogsErrorWhenRepositoryThrows()
        {
            var myLadderId = "My Ladder Id";
            var myPlatform = "PC";
            var myUsername = "******";

            var exceptionMessage = "An error occurred because blablabalabla";

            _repository
            .Setup(r => r.GetEntryForUser(myLadderId, myPlatform, myUsername))
            .Throws(new Exception(exceptionMessage));

            var service = new LadderService(_repository.Object, _logger.Object);

            service.GetEntryForUser(myLadderId, myPlatform, myUsername);

            _logger.Verify(l => l.LogError(It.IsAny <Exception>(), It.IsAny <string>()), Times.Once(), "Logger not called");
        }
Beispiel #12
0
        public void Upsert_ReturnsTheUpdatedOrInsertedEntryIfEverythingIsOK()
        {
            var entry = new LadderEntry
            {
                LadderId = "My Ladder",
                Platform = "PC",
                Username = "******"
            };

            _repository
            .Setup(r => r.Upsert(entry))
            .Returns(() => entry);

            var service = new LadderService(_repository.Object, _logger.Object);

            service
            .Upsert(entry)
            .Should()
            .BeEquivalentTo(entry);
        }
Beispiel #13
0
        public void Upsert_LogsErrorWhenRepositoryThrows()
        {
            var entry = new LadderEntry
            {
                LadderId = "My Ladder",
                Platform = "PC",
                Username = "******"
            };


            var exceptionMessage = "An error occurred because blablabalabla";

            _repository
            .Setup(r => r.Upsert(entry))
            .Throws(new Exception(exceptionMessage));

            var service = new LadderService(_repository.Object, _logger.Object);

            service.Upsert(entry);

            _logger.Verify(l => l.LogError(It.IsAny <Exception>(), It.IsAny <string>()), Times.Once());
        }
Beispiel #14
0
        public void GetEntryForUser_ReturnsMyEntryWhenMyKeyMatchesOneEntry()
        {
            var myLadderId = "My Ladder Id";
            var myPlatform = "PC";
            var myUsername = "******";
            var myEntry    = new LadderEntry
            {
                LadderId = myLadderId,
                Platform = myPlatform,
                Username = myUsername
            };

            _repository
            .Setup(r => r.GetEntryForUser(myLadderId, myPlatform, myUsername))
            .Returns(() => myEntry);

            var service = new LadderService(_repository.Object, _logger.Object);
            var result  = service.GetEntryForUser(myLadderId, myPlatform, myUsername);

            result
            .Should()
            .BeEquivalentTo(myEntry);
        }
Beispiel #15
0
        static async Task Main(string[] args)
        {
            //CsvReaderService _csvReader = new CsvReaderService();
            //_csvReader.ReadTeamFile();
            LadderService   _ladder         = new LadderService();
            List <Team>     teams           = new List <Team>();
            ScrapingService _scrapper       = new ScrapingService();
            Team            theFormed       = JsonSerializer.Deserialize <Team>(File.ReadAllText(filePathBase + filePathTheFormed));
            Team            theTwisted      = JsonSerializer.Deserialize <Team>(File.ReadAllText(filePathBase + filePathTheTwisted));
            Team            theFeared       = JsonSerializer.Deserialize <Team>(File.ReadAllText(filePathBase + filePathTheFeared));
            Team            theHidden       = JsonSerializer.Deserialize <Team>(File.ReadAllText(filePathBase + filePathTheHidden));
            List <Item>     theFormedItems  = JsonSerializer.Deserialize <List <Item> >(File.ReadAllText(filePathBase + filePathTheFormedItems));
            List <Item>     theTwistedItems = JsonSerializer.Deserialize <List <Item> >(File.ReadAllText(filePathBase + filePathTheTwistedItems));
            List <Item>     theFearedItems  = JsonSerializer.Deserialize <List <Item> >(File.ReadAllText(filePathBase + filePathTheFearedItems));
            List <Item>     theHiddenTeams  = JsonSerializer.Deserialize <List <Item> >(File.ReadAllText(filePathBase + filePathTheHiddenItems));
            List <Member>   members         = JsonSerializer.Deserialize <List <Member> >(File.ReadAllText(filePathBase + "\\BPL3Members.json"));


            List <Member> updateMember = await GetLadder(members, new List <Team> {
                theFormed, theTwisted, theFeared, theHidden
            });

            SerializeJsonService.SerializeJson(updateMember, filePathBase + "\\BPL3Members.json");
            TeamItem updateFormed = await _scrapper.GetItems(theFormed.StashUrl, new TeamItem { Team = theFormed, Items = theFormedItems });

            TeamItem updateFearedItems = await _scrapper.GetItems(theFeared.StashUrl, new TeamItem { Team = theFeared, Items = theFearedItems });

            TeamItem updateTwistedItems = await _scrapper.GetItems(theTwisted.StashUrl, new TeamItem { Team = theTwisted, Items = theTwistedItems });

            TeamItem updateHiddenItems = await _scrapper.GetItems(theHidden.StashUrl, new TeamItem { Team = theHidden, Items = theHiddenTeams });

            List <Member> theTwistedMembers = members.Where(m => m.TeamName == "The Twisted").ToList();
            List <Member> theFearedMembers  = members.Where(m => m.TeamName == "The Feared").ToList();
            List <Member> theHiddenMembers  = members.Where(m => m.TeamName == "The Hidden").ToList();
            List <Member> theFormedMembers  = members.Where(m => m.TeamName == "The Formed").ToList();

            List <int> points = new List <int>();

            points.AddRange(CalcPoints(theTwistedMembers));
            points.AddRange(CalcPoints(theFearedMembers));
            points.AddRange(CalcPoints(theHiddenMembers));
            points.AddRange(CalcPoints(theFormedMembers));
            theTwisted.LevelPoints = points[0];
            theTwisted.DelvePoints = points[1];
            theTwisted.TotalPoints = theTwisted.LevelPoints + theTwisted.DelvePoints + theTwisted.SetPoints;
            theFeared.LevelPoints  = points[2];
            theFeared.DelvePoints  = points[3];
            theFeared.TotalPoints  = theFeared.LevelPoints + theFeared.DelvePoints + theFeared.SetPoints;
            theHidden.LevelPoints  = points[4];
            theHidden.DelvePoints  = points[5];
            theHidden.TotalPoints  = theHidden.LevelPoints + theHidden.DelvePoints + theHidden.SetPoints;
            theFormed.LevelPoints  = points[6];
            theFormed.DelvePoints  = points[7];
            theFormed.TotalPoints  = theFormed.LevelPoints + theFormed.DelvePoints + theFormed.SetPoints;

            SerializeJsonService.SerializeJson(updateFormed.Team, filePathBase + filePathTheFormed);
            SerializeJsonService.SerializeJson(updateFormed.Items, filePathBase + filePathTheFormedItems);
            SerializeJsonService.SerializeJson(updateHiddenItems.Team, filePathBase + filePathTheHidden);
            SerializeJsonService.SerializeJson(updateHiddenItems.Items, filePathBase + filePathTheHiddenItems);
            SerializeJsonService.SerializeJson(updateTwistedItems.Team, filePathBase + filePathTheTwisted);
            SerializeJsonService.SerializeJson(updateTwistedItems.Items, filePathBase + filePathTheTwistedItems);
            SerializeJsonService.SerializeJson(updateFearedItems.Team, filePathBase + filePathTheFeared);
            SerializeJsonService.SerializeJson(updateFearedItems.Items, filePathBase + filePathTheFearedItems);
        }