Пример #1
0
        public void GivenGameWhenLoadFromJsonThenCharactersAreLoadedFromJsonFile()
        {
            var json = "{" +
                       "'characters': [" +
                       "{ 'name': 'bob', 'arm': 13, 'str': 14, 'dex': 15, 'const': 16 }," +
                       "{ 'name': 'jack', 'arm': 2, 'str': 3, 'dex': 4, 'const': 5 }," +
                       "]" +
                       "}";

            File.WriteAllText(_otherFilePath, json);

            var game = new EvercraftGame();

            game.Load(_otherFilePath);

            game.Chars[0].Name.Should().Be("bob");
            game.Chars[0].Arm.Should().Be(13);
            game.Chars[0].Str.Should().Be(14);
            game.Chars[0].Dex.Should().Be(15);
            game.Chars[0].Const.Should().Be(16);

            game.Chars[1].Name.Should().Be("jack");
            game.Chars[1].Arm.Should().Be(2);
            game.Chars[1].Str.Should().Be(3);
            game.Chars[1].Dex.Should().Be(4);
            game.Chars[1].Const.Should().Be(5);
        }
Пример #2
0
        public void GivenGameWhenLoadFromDatabaseThenCharactersAreLoadedFromDatabase()
        {
            using (var connection = new SqliteConnection($"Data Source={_otherOtherFilePath}"))
            {
                connection.Open();

                var createTableCommandText = "create table [Characters](Id integer primary key asc, Name Text, Armor integer, Str integer, Dex integer, Const integer)";
                using (var createTableCommand = new SqliteCommand(createTableCommandText, connection))
                {
                    createTableCommand.ExecuteNonQueryAsync();
                }

                var insertRowsCommandText = "insert into [Characters] (Name, Armor, Str, Dex, Const) values ('John', 9, 8, 7, 6);\n" +
                                            "insert into [Characters] (Name, Armor, Str, Dex, Const) values ('Jim', 20, 20, 20, 20);\n";
                using (var insertRowsCommand = new SqliteCommand(insertRowsCommandText, connection))
                {
                    insertRowsCommand.ExecuteNonQueryAsync();
                }
            }
            var game = new EvercraftGame();

            game.Load(_otherOtherFilePath);

            game.Chars[0].Name.Should().Be("John");
            game.Chars[0].Arm.Should().Be(9);
            game.Chars[0].Str.Should().Be(8);
            game.Chars[0].Dex.Should().Be(7);
            game.Chars[0].Const.Should().Be(6);

            game.Chars[1].Name.Should().Be("Jim");
            game.Chars[1].Arm.Should().Be(20);
            game.Chars[1].Str.Should().Be(20);
            game.Chars[1].Dex.Should().Be(20);
            game.Chars[1].Const.Should().Be(20);
        }
Пример #3
0
        public void GivenGameWhenLoadFromCsvThenCharactersAreLoadedFromFile()
        {
            File.WriteAllText(_filePath, "Character,Armor,Strength,Dexterity,Constitution\n" +
                              "Jack,12,13,14,15\n" +
                              "Bob,13,14,15,16\n");

            var game = new EvercraftGame();

            game.Load(_filePath);

            game.Chars[0].Name.Should().Be("Jack");
            game.Chars[0].Arm.Should().Be(12);
            game.Chars[0].Str.Should().Be(13);
            game.Chars[0].Dex.Should().Be(14);
            game.Chars[0].Const.Should().Be(15);

            game.Chars[1].Name.Should().Be("Bob");
            game.Chars[1].Arm.Should().Be(13);
            game.Chars[1].Str.Should().Be(14);
            game.Chars[1].Dex.Should().Be(15);
            game.Chars[1].Const.Should().Be(16);
        }