Ejemplo n.º 1
0
    public void FindCompetitorsInRange_With_Max_Value_Inclusive()
    {
        //Arrange

        var olympics = new Olympics();

        //Act

        olympics.AddCompetition(1, "SoftUniada", 500);
        olympics.AddCompetition(2, "Java", 600);

        olympics.AddCompetitor(5, "Ani");
        olympics.Compete(5, 1);
        olympics.Compete(5, 2);

        olympics.AddCompetitor(1, "Ivan");
        olympics.Compete(1, 1);

        olympics.AddCompetitor(2, "Stamat");
        olympics.Compete(2, 1);
        olympics.Compete(2, 2);

        int expectedCount = 2;
        int actualCount   = olympics.FindCompetitorsInRange(500, 1100).Count();


        //Assert

        Assert.AreEqual(expectedCount, actualCount);
    }
Ejemplo n.º 2
0
    public void FindCompetitorsInRange_With_Invalid_Range_Should_Return_Empty_Collection()
    {
        //Arrange

        var olympics = new Olympics();

        //Act

        olympics.AddCompetition(1, "SoftUniada", 500);
        olympics.AddCompetition(2, "Java", 600);

        olympics.AddCompetitor(5, "Ani");
        olympics.Compete(5, 1);
        olympics.Compete(5, 2);

        olympics.AddCompetitor(1, "Ivan");
        olympics.Compete(1, 1);

        olympics.AddCompetitor(2, "Stamat");
        olympics.Compete(2, 1);
        olympics.Compete(2, 2);

        var actual = olympics.FindCompetitorsInRange(0, 499);

        //Assert

        Assert.AreEqual(Enumerable.Empty <Competitor>(), actual);
    }
Ejemplo n.º 3
0
    public void AddCompetition_With_Existing_Id_Should_Throw_Exception()
    {
        //Arrange
        IOlympics olympics = new Olympics();

        //Act
        olympics.AddCompetition(1, "SoftUniada", 500);
        olympics.AddCompetition(2, "CodeWizard", 600);
        olympics.AddCompetition(3, "Programming Basics", 100);


        //Assert
        Assert.Throws <ArgumentException>(() => olympics.AddCompetition(1, "CSharpForDummies", 20));
    }
Ejemplo n.º 4
0
    public void Compete_With_Valid_Competitors_In_Competition_Score_Changed()
    {
        //Arrange

        var olympics = new Olympics();

        //Act

        olympics.AddCompetition(1, "SoftUniada", 500);

        olympics.AddCompetitor(5, "Ani");
        olympics.Compete(5, 1);

        olympics.AddCompetitor(1, "Ivan");
        olympics.Compete(1, 1);

        olympics.AddCompetitor(2, "Stamat");
        olympics.Compete(2, 1);

        int  expectedCompetitorsScore = 1500;
        long actualCompetitorsScore   = 0;

        foreach (Competitor competitor in olympics.GetCompetition(1).Competitors)
        {
            actualCompetitorsScore += competitor.TotalScore;
        }

        //Assert

        Assert.AreEqual(expectedCompetitorsScore, actualCompetitorsScore);
    }
Ejemplo n.º 5
0
    public void Disqualify_Should_Decrease_Competitors_Count_In_Competition()
    {
        //Arrange

        var olympics = new Olympics();

        //Act

        olympics.AddCompetition(1, "SoftUniada", 500);

        olympics.AddCompetitor(5, "Ani");
        olympics.Compete(5, 1);

        olympics.AddCompetitor(1, "Ivan");
        olympics.Compete(1, 1);

        olympics.AddCompetitor(2, "Stamat");
        olympics.Compete(2, 1);
        olympics.Disqualify(1, 5);
        int expectedCompetitorsCount = 2;
        int actualCompetitorsCount   = olympics.GetCompetition(1).Competitors.Count;

        //Assert

        Assert.AreEqual(expectedCompetitorsCount, actualCompetitorsCount);
    }
Ejemplo n.º 6
0
    public void Disqualify_Should_Reduce_Score()
    {
        //Arrange

        var olympics = new Olympics();

        //Act

        olympics.AddCompetition(1, "SoftUniada", 500);

        olympics.AddCompetitor(5, "Ani");
        olympics.Compete(5, 1);

        olympics.AddCompetitor(1, "Ivan");
        olympics.Compete(1, 1);

        olympics.AddCompetitor(2, "Stamat");
        olympics.Compete(2, 1);
        olympics.Disqualify(1, 5);

        int  expectedScore          = 0;
        long actualCompetitorsScore = olympics.GetByName("Ani").Sum(a => a.TotalScore);

        //Assert

        Assert.AreEqual(expectedScore, actualCompetitorsScore);
    }
Ejemplo n.º 7
0
    public void Compete_With_Valid_Competitors_In_Competition()
    {
        //Arrange

        var olympics = new Olympics();

        //Act

        olympics.AddCompetition(1, "SoftUniada", 500);

        olympics.AddCompetitor(5, "Ani");
        olympics.Compete(5, 1);

        olympics.AddCompetitor(1, "Ivan");
        olympics.Compete(1, 1);

        olympics.AddCompetitor(2, "Stamat");
        olympics.Compete(2, 1);

        int expectedCompetitorsCount = 3;
        int actualCompetitorsCount   = olympics.GetCompetition(1).Competitors.Count;

        //Assert

        Assert.AreEqual(expectedCompetitorsCount, actualCompetitorsCount);
    }
Ejemplo n.º 8
0
    public void AddCompetition_Count_Should_Increase()
    {
        //Arrange
        var olympics = new Olympics();

        //Act
        olympics.AddCompetition(1, "SoftUniada", 500);
        olympics.AddCompetition(2, "CodeWizard", 600);
        olympics.AddCompetition(3, "Programming Basics", 100);
        olympics.AddCompetition(4, "CSharpForDummies", 20);

        int expectedCount = 4;
        int actualCount   = olympics.CompetitionsCount();

        //Assert
        Assert.AreEqual(expectedCount, actualCount);
    }
Ejemplo n.º 9
0
    public void FindCompetitorsInRange_Correct_Order()
    {
        //Arrange

        var olympics = new Olympics();

        //Act

        olympics.AddCompetition(1, "SoftUniada", 500);
        olympics.AddCompetition(2, "Java", 600);

        olympics.AddCompetitor(5, "Ani");
        olympics.Compete(5, 1);
        olympics.Compete(5, 2);

        olympics.AddCompetitor(1, "Ivan");
        olympics.Compete(1, 1);

        olympics.AddCompetitor(2, "Stamat");
        olympics.Compete(2, 1);
        olympics.Compete(2, 2);

        int[] ids            = { 1, 2, 5 };
        bool  isCorrectOrder = true;

        var competitors = olympics.FindCompetitorsInRange(400, 1100).ToList();

        for (int i = 0; i < ids.Length; i++)
        {
            if (competitors[i].Id != ids[i])
            {
                isCorrectOrder = false;
                break;
            }
        }

        //Assert

        Assert.IsTrue(isCorrectOrder);
    }
Ejemplo n.º 10
0
    public void Disqualify_Should_Throw_Exception_With_Invalid_Competition_Id()
    {
        //Arrange

        var olympics = new Olympics();

        //Act

        olympics.AddCompetition(1, "CompetitionOne", 50);
        olympics.AddCompetitor(1, "Ani");
        olympics.Compete(1, 1);

        //Assert

        Assert.Throws <ArgumentException>(() => olympics.Disqualify(2, 1));
    }
Ejemplo n.º 11
0
    public void Compete_With_Invalid_Competition_Id_Should_Throw_Exception()
    {
        //Arrange

        var olympics = new Olympics();

        //Act

        olympics.AddCompetition(1, "SoftUniada", 500);
        olympics.AddCompetitor(5, "Ani");
        olympics.Compete(5, 1);

        //Assert

        Assert.Throws <ArgumentException>(() => olympics.Compete(5, 7));
    }
Ejemplo n.º 12
0
    public void GetCompetition_With_Invalid_Id_Should_Throw_Exception()
    {
        //Arrange

        var    olympics = new Olympics();
        int    id       = 1;
        string name     = "SoftUniada";
        int    score    = 500;

        //Act

        olympics.AddCompetition(id, name, score);

        //Assert

        Assert.Throws <ArgumentException>(() => olympics.GetCompetition(int.MinValue));
    }
Ejemplo n.º 13
0
    public void Contains_Should_Throw_Exception_With_Invalid_Id()
    {
        //Arrange

        var olympics   = new Olympics();
        var competitor = new Competitor(5, "Ani");

        //Act

        olympics.AddCompetition(1, "SoftUniada", 500);

        olympics.AddCompetitor(5, "Ani");

        //Assert

        Assert.Throws <ArgumentException>(() => olympics.Contains(2, competitor));
    }
Ejemplo n.º 14
0
    public void GetCompetition_Should_Return_Correct_Competition()
    {
        //Arrange

        var    olympics = new Olympics();
        int    id       = 1;
        string name     = "SoftUniada";
        int    score    = 500;

        //Act

        olympics.AddCompetition(id, name, score);
        Competition competition          = olympics.GetCompetition(id);
        bool        isCorrectCompetition = competition.Id == id && competition.Name == name && competition.Score == score;

        //Assert

        Assert.IsTrue(isCorrectCompetition);
    }
Ejemplo n.º 15
0
    public void Contains_Should_Return_True_With_Valid_Data()
    {
        //Arrange

        var olympics   = new Olympics();
        var competitor = new Competitor(5, "Ani");

        //Act

        olympics.AddCompetition(1, "SoftUniada", 500);

        olympics.AddCompetitor(5, "Ani");
        olympics.Compete(5, 1);

        var actual = olympics.Contains(1, competitor);

        //Assert

        Assert.IsTrue(actual);
    }