Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using NUnit.Framework;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Gyms.Tests
- {
- public class GymsTests
- {
- // Implement unit tests here
- [Test]
- [TestCase(10)]
- [TestCase(0)]
- public void ConstructorShouldSetNewCollectionNoMatterOfCapacity(int value)
- {
- Gym gym = new Gym("TestGym", value);
- Assert.IsTrue(gym.Count == 0);
- }
- [Test]
- [TestCase("TestGym1", 10)]
- [TestCase("TestGym2", 0)]
- public void ConstructorShouldSetGymNameValues(string name, int capacity)
- {
- Gym gym = new Gym(name, capacity);
- string expectedName = name;
- int expectedCapacity = capacity;
- Assert.IsTrue(gym.Name == expectedName && gym.Capacity == expectedCapacity);
- }
- [Test]
- [TestCase(null)]
- [TestCase("")]
- public void ConstructorShouldThrowsExceptionWhenNameIsNullOrEmpty(string value)
- {
- Assert.Throws<ArgumentNullException>(() => new Gym(value, 10));
- }
- [Test]
- [TestCase(-1)]
- [TestCase(int.MinValue)]
- public void ConstructorShouldThrowsExceptionWhenCapacityValueIsNegative(int value)
- {
- Assert.Throws<ArgumentException>(() => new Gym("TestGym", value), "Invalid gym capacity.");
- }
- [Test]
- public void AddAthleteShouldThrowsExceptionWhenTryToAddMoreThanCapacityAthletes()
- {
- Gym gym = new Gym("TestGym", 0);
- Assert.Throws<InvalidOperationException>(() => gym.AddAthlete(new Athlete("testAthlete")), "The gym is full.");
- }
- [Test]
- public void AddAthleteShouldIncreaseTheCountWithAddingOfNewAthlete()
- {
- Gym gym = new Gym("TestGym", 10);
- gym.AddAthlete(new Athlete("TestAthlete"));
- int expectedCount = 1;
- int actual = gym.Count;
- Assert.AreEqual(expectedCount, actual);
- }
- [Test]
- public void RemoveAthleteMethodShouldThrowsExceptinWhenNonExistingAthlete()
- {
- Gym gym = new Gym("TestGym", 10);
- string name = "NonExistingAthlete";
- Assert.Throws<InvalidOperationException>(() => gym.RemoveAthlete(name), $"The athlete {name} doesn't exist.");
- }
- [Test]
- public void RemoveAthleteMethodShouldDecreaseTheCountByRemovingAthlete()
- {
- Gym gym = new Gym("TestGym", 10);
- gym.AddAthlete(new Athlete("TestAthlete1"));
- gym.AddAthlete(new Athlete("TestAthlete2"));
- gym.RemoveAthlete("TestAthlete1");
- int expected = 1;
- int actual = gym.Count;
- Assert.AreEqual(expected, actual);
- }
- [Test]
- public void InjureAthleteShouldThrowsExceptionWhenNonExistingAthlete()
- {
- Gym gym = new Gym("TestGym", 10);
- string fullName = "NonExistingAthlete";
- Assert.Throws<InvalidOperationException>(() => gym.InjureAthlete(fullName), $"The athlete {fullName} doesn't exist.");
- }
- [Test]
- public void InjureAthleteShoulSetTrueToIsInjuredPropertyForGivenAthleteName()
- {
- Gym gym = new Gym("TestGym", 10);
- gym.AddAthlete(new Athlete("TestAthlete1"));
- Athlete athlete = gym.InjureAthlete("TestAthlete1");
- bool expected = true;
- bool actual = athlete.IsInjured;
- Assert.AreEqual(expected, actual);
- }
- [Test]
- public void InjureAthleteShouldReturnExactlyTheSameAthleteByGivenName()
- {
- Gym gym = new Gym("TestGym", 10);
- Athlete expected = new Athlete("TestAthlete1");
- gym.AddAthlete(expected);
- Athlete actual = gym.InjureAthlete("TestAthlete1");
- Assert.IsTrue(actual.FullName == expected.FullName);
- Assert.IsTrue(actual.IsInjured == expected.IsInjured);
- Assert.IsTrue(actual.GetHashCode() == expected.GetHashCode());
- }
- [Test]
- public void ReportMethodShouldReturnCorrectStringFormatWhenThereAreInjuredOrRemovedAthletes()
- {
- List<Athlete> list = new List<Athlete>();
- Gym gym = new Gym("TestGym", 10);
- gym.AddAthlete(new Athlete("TestAthlete1"));
- gym.AddAthlete(new Athlete("TestAthlete2"));
- gym.AddAthlete(new Athlete("TestAthlete3"));
- list.Add(new Athlete("TestAthlete1") { IsInjured = true});
- list.Add(new Athlete("TestAthlete2"));
- gym.InjureAthlete("TestAthlete1");
- gym.RemoveAthlete("TestAthlete3");
- string expected = $"Active athletes at {gym.Name}: {string.Join(", ", list.Where(a => !a.IsInjured).Select(a => a.FullName))}";
- string actual = gym.Report();
- Assert.AreEqual(expected, actual);
- }
- [Test]
- public void ReportShouldWorkWithNoAthletes()
- {
- Gym gym = new Gym("TestGym", 10);
- string expected = $"Active athletes at {gym.Name}: {string.Empty}";
- string actual = gym.Report();
- Assert.AreEqual(expected, actual);
- }
- [Test]
- public void ReportShouldWorkWithOnlyInjuredAthletes()
- {
- Gym gym = new Gym("TestGym", 10);
- gym.AddAthlete(new Athlete("TestAthlete1") { IsInjured = true });
- gym.AddAthlete(new Athlete("TestAthlete2") { IsInjured = true });
- gym.AddAthlete(new Athlete("TestAthlete3") { IsInjured = true });
- string expected = $"Active athletes at {gym.Name}: {string.Empty}";
- string actual = gym.Report();
- Assert.AreEqual(expected,actual);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment