Example #1
0
    public bool Add_ExistingScores_Adds(int existingScores, uint moves, int expectedIndex)
    {
        var bestScores = new BestScores();

        for (uint i = 0; i < existingScores; i++)
        {
            bestScores.Add(new Score {
                Name = i.ToString(), Moves = i + 1, Timer = new TimeSpan(0, 1, 2, 3)
            });
        }
        var score = new Score {
            Name = "Dmitrik", Moves = moves, Timer = new TimeSpan(0, 0, 1, 30)
        };

        bestScores.Add(score);

        return(bestScores.Scores[expectedIndex] == score);
    }
Example #2
0
    public void CanBeAdded_NotOneOfTheBestScores_DoesntAddScore()
    {
        // Best scores
        var bestScores = new BestScores();

        bestScores.Add(new Score {
            Name = "A", Moves = 1, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 2, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 3, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 4, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 5, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 6, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 7, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 8, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 9, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 10, Timer = new TimeSpan(0, 0, 10, 25)
        });
        // New score
        var score = new Score {
            Name = "Dmitrik", Moves = 11, Timer = new TimeSpan(0, 0, 10, 25)
        };

        bool actual = bestScores.CanBeAdded(score);

        Assert.That(actual, Is.False);
    }
    public void Save_10BestScores_Saves()
    {
        var bestScores = new BestScores();

        bestScores.Add(new Score {
            Name = "Aaaaaaaaaa", Moves = 92, Timer = new TimeSpan(0, 0, 11, 25)
        });
        bestScores.Add(new Score {
            Name = "Bbbbbbbbb", Moves = 102, Timer = new TimeSpan(0, 0, 12, 25)
        });
        bestScores.Add(new Score {
            Name = "Cccccc", Moves = 103, Timer = new TimeSpan(0, 0, 13, 25)
        });
        bestScores.Add(new Score {
            Name = "Dmitrik", Moves = 124, Timer = new TimeSpan(0, 0, 14, 25)
        });
        bestScores.Add(new Score {
            Name = "Eeeeee", Moves = 135, Timer = new TimeSpan(0, 0, 15, 25)
        });
        bestScores.Add(new Score {
            Name = "Ffffffffffff", Moves = 146, Timer = new TimeSpan(0, 0, 16, 25)
        });
        bestScores.Add(new Score {
            Name = "Gggg", Moves = 147, Timer = new TimeSpan(0, 1, 17, 25)
        });
        bestScores.Add(new Score {
            Name = "Hhhhhhh", Moves = 158, Timer = new TimeSpan(0, 1, 18, 25)
        });
        bestScores.Add(new Score {
            Name = "Iiiiiiii", Moves = 159, Timer = new TimeSpan(0, 1, 19, 25)
        });
        bestScores.Add(new Score {
            Name = "Jjjjjjj", Moves = 200, Timer = new TimeSpan(0, 1, 20, 25)
        });

        var bestScoresStoragePath = $"{AppDomain.CurrentDomain.BaseDirectory}\\{Options.BestScoresStorageFileName}";

        new BestScoresStorage(bestScoresStoragePath).Save(bestScores);
        bool actual = File.Exists(bestScoresStoragePath);

        Assert.That(actual, Is.True);
    }
    public void Load_10BestScores_Loads()
    {
        var bestScores = new BestScores();

        bestScores.Add(new Score {
            Name = "Aaaaaaaaaa", Moves = 92, Timer = new TimeSpan(0, 0, 11, 25)
        });
        bestScores.Add(new Score {
            Name = "Bbbbbbbbb", Moves = 102, Timer = new TimeSpan(0, 0, 12, 25)
        });
        bestScores.Add(new Score {
            Name = "Cccccc", Moves = 103, Timer = new TimeSpan(0, 0, 13, 25)
        });
        bestScores.Add(new Score {
            Name = "Dmitrik", Moves = 124, Timer = new TimeSpan(0, 0, 14, 25)
        });
        bestScores.Add(new Score {
            Name = "Eeeeee", Moves = 135, Timer = new TimeSpan(0, 0, 15, 25)
        });
        bestScores.Add(new Score {
            Name = "Ffffffffffff", Moves = 146, Timer = new TimeSpan(0, 0, 16, 25)
        });
        bestScores.Add(new Score {
            Name = "Gggg", Moves = 147, Timer = new TimeSpan(0, 1, 17, 25)
        });
        bestScores.Add(new Score {
            Name = "Hhhhhhh", Moves = 158, Timer = new TimeSpan(0, 1, 18, 25)
        });
        bestScores.Add(new Score {
            Name = "Iiiiiiii", Moves = 159, Timer = new TimeSpan(0, 1, 19, 25)
        });
        bestScores.Add(new Score {
            Name = "Jjjjjjj", Moves = 200, Timer = new TimeSpan(0, 1, 20, 25)
        });

        var bestScoresStoragePath = $"{AppDomain.CurrentDomain.BaseDirectory}\\{Options.BestScoresStorageFileName}";
        var bestScoresStorage     = new BestScoresStorage(bestScoresStoragePath);

        bestScoresStorage.Save(bestScores);

        var loadBestScores = new BestScores();

        bestScoresStorage.Load(loadBestScores);

        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // Вариант на случай отсутствия перегруженного метода Score.Equals
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        //if (bestScores.Count != loadBestScores.Count)
        //    Assert.Fail();
        //bool equals = true;
        //for (int i = 0; i < bestScores.Count; i++)
        //{
        //    if (bestScores[i].Name != loadBestScores[i].Name ||
        //        bestScores[i].Moves != loadBestScores[i].Moves ||
        //        bestScores[i].Timer != loadBestScores[i].Timer)
        //    {
        //        equals = false;
        //        break;
        //    }
        //}
        //Assert.That(equals, Is.True);

        Assert.That(loadBestScores.Scores, Is.EqualTo(bestScores.Scores));
    }