public async Task Given_DataFile_When_Reporting_Then_ProduceJsonReport()
        {
            // Arrange
            var datafile           = Path.Combine(AppContext.BaseDirectory, "Data", "chicago-bulls.csv");
            var expectedReportFile = Path.Combine(AppContext.BaseDirectory, "Data", "chicago-bulls.json");
            var originalReport     = await File.ReadAllTextAsync(expectedReportFile);

            var reportObject   = JsonConvert.DeserializeObject(originalReport);
            var expectedReport = JsonConvert.SerializeObject(reportObject, Formatting.Indented);

            var playerParser    = new PlayerParser();
            var dataProvider    = new CsvDataProvider(playerParser);
            var metricConverter = new ImperialToMetricConverter();
            var enrichers       = new List <IReportEnricher>
            {
                new AveragePlayerHeightEnricher(metricConverter),
                new AveragePointsForTeamEnricher(),
                new TeamEnricher(),
                new TopAchieversEnricher()
            };

            var statisticsReporter = new TeamStatisticsReporter(enrichers);

            var sut = new TeamStatisticsJsonReporter(dataProvider, statisticsReporter);

            // Act
            var result = await sut.GetReportAsJsonAsync(datafile);

            // Assert
            Assert.Equal(expectedReport, result);
        }
        public void PlayerParser_ExtractNames_checkReturnsString()
        {
            ctrl.SaveFile();
            ctrl.LoadFile();
            String actual = new PlayerParser().ExtractName();

            Assert.IsInstanceOfType(actual, String);
        }
        public void PlayerParser_ExtractTotalMoves_checkReturnsInt()
        {
            ctrl.SaveFile();
            ctrl.LoadFile();
            Int32 actual = new PlayerParser().ExtractTotalMoves();

            Assert.IsInstanceOfType(actual, Int32);
        }
        public void PlayerParser_ExtractMovementHistory_checkReturnsList()
        {
            ctrl.SaveFile();
            ctrl.LoadFile();
            List <String> actual = new PlayerParser().ExtractMovementHistory();

            Assert.IsInstanceOfType(actual, List <String>);
        }
示例#5
0
        public void TryParse()
        {
            Player player1;
            Player player2;

            Assert.IsTrue(PlayerParser.TryParse("@playerA @playerB 1-10", out player1, out player2));
            Assert.AreEqual("@playerA", player1.Id);
            Assert.AreEqual("@playerB", player2.Id);
        }
        public void Given_PlayerDescription_When_ArgumentDoesntMatchExpectedFormat_Then_ReturnThrow(string data)
        {
            // Assert
            var sut = new PlayerParser();

            // Act
            // Arrange
            Assert.Throws <ArgumentException>(() => sut.Build(data));
        }
        public async Task Given_DataFile_When_Loaded_Then_ReturnAllPlayers()
        {
            // Arrange
            var playerParser = new PlayerParser();
            var sut          = new CsvDataProvider(playerParser);

            // Act
            var datafile = Path.Combine(AppContext.BaseDirectory, "Data", "chicago-bulls-trimmed.csv");
            var result   = await sut.GetPlayersAsync(datafile);

            // Assert
            Assert.Collection(result, p =>
            {
                Assert.Equal(1, p.Id);
                Assert.Equal(Position.PG, p.Position);
                Assert.Equal(10, p.Number);
                Assert.Equal("United States", p.Country);
                Assert.Equal("Armstrong, B.J.", p.Name);
                Assert.Equal("6 ft 2 in", p.Height);
                Assert.Equal("175 lb", p.Weight);
                Assert.Equal("Iowa", p.University);
                Assert.Equal(12.3m, p.PointsPerGame);
            }, p =>
            {
                Assert.Equal(2, p.Id);
                Assert.Equal(Position.C, p.Position);
                Assert.Equal(24, p.Number);
                Assert.Equal("United States", p.Country);
                Assert.Equal("Cartwright, Bill", p.Name);
                Assert.Equal("7 ft 1 in", p.Height);
                Assert.Equal("246 lb", p.Weight);
                Assert.Equal("San Francisco", p.University);
                Assert.Equal(5.6m, p.PointsPerGame);
            }, p =>
            {
                Assert.Equal(3, p.Id);
                Assert.Equal(Position.PF, p.Position);
                Assert.Equal(54, p.Number);
                Assert.Equal("United States", p.Country);
                Assert.Equal("Grant, Horace", p.Name);
                Assert.Equal("6 ft 10 in", p.Height);
                Assert.Equal("245 lb", p.Weight);
                Assert.Equal("Clemson", p.University);
                Assert.Equal(13.2m, p.PointsPerGame);
            });
        }
        public void Given_PlayerDescription_When_AllDataIsPresent_Then_ReturnPlayer()
        {
            // Assert
            var sut  = new PlayerParser();
            var data = "1,PG,10,United States,\"Armstrong, B.J.\",6 ft 2 in,175 lb,Iowa,12.3";

            // Act
            var result = sut.Build(data);

            // Arrange
            Assert.Equal(1, result.Id);
            Assert.Equal(Position.PG, result.Position);
            Assert.Equal(10, result.Number);
            Assert.Equal("United States", result.Country);
            Assert.Equal("Armstrong, B.J.", result.Name);
            Assert.Equal("6 ft 2 in", result.Height);
            Assert.Equal("175 lb", result.Weight);
            Assert.Equal("Iowa", result.University);
            Assert.Equal(12.3m, result.PointsPerGame);
        }