Esempio n. 1
0
        public void Execute_ShouldReturnSuccessMessageContainingStudentUsernameAndSeasonId_WhenStudentIsAddedIntoSpecifiedSeason()
        {
            // Arrange
            var factoryStub = new Mock <IAcademyFactory>();
            var engineMock  = new Mock <IEngine>();
            var command     = new AddStudentToSeasonCommand(factoryStub.Object, engineMock.Object);

            var studentStub = new Mock <IStudent>();
            var seasonStub  = new Mock <ISeason>();

            studentStub.SetupGet(s => s.Username).Returns("Pesho");
            seasonStub.SetupGet(s => s.Students).Returns(new List <IStudent>());

            engineMock.SetupGet(e => e.Students).Returns(new List <IStudent> {
                studentStub.Object
            });
            engineMock.SetupGet(e => e.Seasons).Returns(new List <ISeason> {
                seasonStub.Object
            });

            string validStudentUsername = "******";
            string validSeasonId        = "0";
            var    parameters           = new List <string> {
                validStudentUsername, validSeasonId
            };
            // Act
            string resultMessage = command.Execute(parameters);

            // Assert
            StringAssert.Contains(validStudentUsername, resultMessage);
            StringAssert.Contains(validSeasonId, resultMessage);
        }
Esempio n. 2
0
        public void Execute_WhenPassedStudentIsAlreadyPartOfThisSeason_ShouldThrowArgumentException()
        {
            var factoryStub = new Mock <IAcademyFactory>();
            var studentStub = new Mock <IStudent>();

            studentStub.Setup(x => x.Username).Returns("Username");
            var engineStudentsStub = new List <IStudent>()
            {
                studentStub.Object
            };

            var seasonStub = new Mock <ISeason>();

            seasonStub.Setup(x => x.Students).Returns(engineStudentsStub);

            var engineSeasons = new List <ISeason>()
            {
                seasonStub.Object
            };

            var engineStub = new Mock <IEngine>();

            engineStub.Setup(x => x.Seasons).Returns(engineSeasons);
            engineStub.Setup(x => x.Students).Returns(engineStudentsStub);

            var command = new AddStudentToSeasonCommand(factoryStub.Object, engineStub.Object);

            var parameters = new List <string>()
            {
                "Username", "0"
            };

            // act and assert
            Assert.Throws <ArgumentException>(() => command.Execute(parameters));
        }
Esempio n. 3
0
        public void Execute_ShouldCorrectlyAddStudentIntoSpecifiedSeason_WhenStudentUsernameDoesNotExistInTheSpecifiedSeason()
        {
            // Arrange
            var factoryStub = new Mock <IAcademyFactory>();
            var engineMock  = new Mock <IEngine>();
            var command     = new AddStudentToSeasonCommand(factoryStub.Object, engineMock.Object);

            var studentStub = new Mock <IStudent>();
            var seasonStub  = new Mock <ISeason>();

            studentStub.SetupGet(s => s.Username).Returns("Pesho");
            seasonStub.SetupGet(s => s.Students).Returns(new List <IStudent>());

            engineMock.SetupGet(e => e.Students).Returns(new List <IStudent> {
                studentStub.Object
            });
            engineMock.SetupGet(e => e.Seasons).Returns(new List <ISeason> {
                seasonStub.Object
            });

            string validStudentUsername = "******";
            string validSeasonId        = "0";
            var    parameters           = new List <string> {
                validStudentUsername, validSeasonId
            };

            // Act
            command.Execute(parameters);
            // Assert
            Assert.AreSame(engineMock.Object.Students[0], engineMock.Object.Seasons[0].Students[0]);
        }
        public void Execute_ShouldThrowArgumentException_WhenThePassedStudentIsAlreadyAPartOfTheSeason()
        {
            var factoryMock = new Mock <IAcademyFactory>();
            var studentMock = new Mock <IStudent>();
            var engineMock  = new Mock <IEngine>();
            var seasonMock  = new Mock <ISeason>();

            var command = new AddStudentToSeasonCommand(factoryMock.Object, engineMock.Object);

            studentMock.Setup(x => x.Username).Returns("Pesho");
            engineMock.Setup(x => x.Students).Returns(new List <IStudent>()
            {
                studentMock.Object
            });
            seasonMock.Setup(x => x.Students).Returns(new List <IStudent>()
            {
                studentMock.Object
            });
            engineMock.Setup(x => x.Seasons).Returns(new List <ISeason>()
            {
                seasonMock.Object
            });

            Assert.Throws <ArgumentException>(() => command.Execute(new List <string>()
            {
                "Pesho", "0"
            }));
        }
Esempio n. 5
0
        public void Execute_ShouldCorrectlyFindStudentbyUsername_WhenPassedSameUsernameWithDifferentCasing()
        {
            // Arrange
            var factoryStub = new Mock <IAcademyFactory>();
            var engineMock  = new Mock <IEngine>();
            var command     = new AddStudentToSeasonCommand(factoryStub.Object, engineMock.Object);

            var studentStub = new Mock <IStudent>();
            var seasonStub  = new Mock <ISeason>();

            studentStub.SetupGet(s => s.Username).Returns("pESHo");
            seasonStub.SetupGet(s => s.Students).Returns(new List <IStudent> {
                studentStub.Object
            });

            engineMock.SetupGet(e => e.Students).Returns(new List <IStudent> {
                studentStub.Object
            });
            engineMock.SetupGet(e => e.Seasons).Returns(new List <ISeason> {
                seasonStub.Object
            });

            string validStudentUsername = "******";
            string validSeasonId        = "0";
            var    parameters           = new List <string> {
                validStudentUsername, validSeasonId
            };

            // Act and Assert
            Assert.Throws <ArgumentException>(() => command.Execute(parameters));
        }
Esempio n. 6
0
        public void ShouldReturnSuccessfulMessageWhenStudentIsAdded()
        {
            //Arrange
            var engineMock  = Mock.Create <IEngine>();
            var factoryMock = Mock.Create <IAcademyFactory>();
            var studentMock = Mock.Create <IStudent>();
            var seasonMock  = Mock.Create <ISeason>();

            Mock.Arrange(() => studentMock.Username).Returns("Pesho");
            Mock.Arrange(() => seasonMock.Students).Returns(new List <IStudent>());
            Mock.Arrange(() => engineMock.Students).Returns(new List <IStudent>()
            {
                studentMock
            });
            Mock.Arrange(() => engineMock.Seasons).Returns(new List <ISeason>()
            {
                seasonMock
            });

            var command = new AddStudentToSeasonCommand(factoryMock, engineMock);

            //Act
            var result = command.Execute(new List <string>()
            {
                "Pesho", "0"
            });

            //Assert
            StringAssert.Contains(result, "Pesho");
            StringAssert.Contains(result, "0");
        }
Esempio n. 7
0
        public void ThrowsArgumentException_WhenTheStudentIsAllreayInTheSeason()
        {
            // Arrange
            var factoryMock = new Mock <IAcademyFactory>();
            var engineMock  = new Mock <IEngine>();

            var studentMock = new Mock <IStudent>();

            studentMock.SetupGet(x => x.Username).Returns("Pesho");

            engineMock.SetupGet(x => x.Students).Returns(new List <IStudent>()
            {
                studentMock.Object
            });

            var seasonMock = new Mock <ISeason>();

            seasonMock.SetupGet(x => x.Students).Returns(new List <IStudent>()
            {
                studentMock.Object
            });

            engineMock.SetupGet(x => x.Seasons).Returns(new List <ISeason>()
            {
                seasonMock.Object
            });

            var command = new AddStudentToSeasonCommand(factoryMock.Object, engineMock.Object);

            // Act and Assert
            Assert.Throws <ArgumentException>(() => command.Execute(new List <string>()
            {
                "Pesho", "0"
            }));
        }
        public void Execute_ShouldCorrectlyAddTheFoundStudentIntoTheSeason()
        {
            var factoryMock        = new Mock <IAcademyFactory>();
            var studentMock        = new Mock <IStudent>();
            var anotherStudentMock = new Mock <IStudent>();
            var engineMock         = new Mock <IEngine>();
            var seasonMock         = new Mock <ISeason>();

            var command = new AddStudentToSeasonCommand(factoryMock.Object, engineMock.Object);

            studentMock.Setup(x => x.Username).Returns("Pesho");
            engineMock.Setup(x => x.Students).Returns(new List <IStudent>()
            {
                studentMock.Object
            });

            anotherStudentMock.Setup(x => x.Username).Returns("Gosho");

            seasonMock.Setup(x => x.Students).Returns(new List <IStudent>()
            {
                anotherStudentMock.Object
            });
            engineMock.Setup(x => x.Seasons).Returns(new List <ISeason>()
            {
                seasonMock.Object
            });

            var message = command.Execute(new List <string>()
            {
                "Pesho", "0"
            });

            Assert.AreEqual(2, seasonMock.Object.Students.Count);
        }
Esempio n. 9
0
        public void ShouldThrowArgumentExceptionWhenPassedStudentIsAlreadyPartOfTheSeason()
        {
            //Arrange
            var engineMock  = Mock.Create <IEngine>();
            var factoryMock = Mock.Create <IAcademyFactory>();
            var studentMock = Mock.Create <IStudent>();
            var seasonMock  = Mock.Create <ISeason>();

            Mock.Arrange(() => studentMock.Username).Returns("Pesho");
            Mock.Arrange(() => seasonMock.Students).Returns(new List <IStudent>()
            {
                new Student("Pesho", Track.Dev)
            });
            Mock.Arrange(() => engineMock.Students).Returns(new List <IStudent>()
            {
                studentMock
            });
            Mock.Arrange(() => engineMock.Seasons).Returns(new List <ISeason>()
            {
                seasonMock
            });

            var command = new AddStudentToSeasonCommand(factoryMock, engineMock);

            //Act & Assert
            Assert.ThrowsException <ArgumentException>(() => command.Execute(new List <string>()
            {
                "Pesho", "0"
            }));
        }
Esempio n. 10
0
        public void Execute_ShouldCorrectlyReturnMessage()
        {
            var factoryMock        = new Mock <IAcademyFactory>();
            var studentMock        = new Mock <IStudent>();
            var anotherStudentMock = new Mock <IStudent>();
            var engineMock         = new Mock <IEngine>();
            var seasonMock         = new Mock <ISeason>();

            var command = new AddStudentToSeasonCommand(factoryMock.Object, engineMock.Object);

            studentMock.Setup(x => x.Username).Returns("Pesho");
            engineMock.Setup(x => x.Students).Returns(new List <IStudent>()
            {
                studentMock.Object
            });

            anotherStudentMock.Setup(x => x.Username).Returns("Gosho");

            seasonMock.Setup(x => x.Students).Returns(new List <IStudent>()
            {
                anotherStudentMock.Object
            });
            engineMock.Setup(x => x.Seasons).Returns(new List <ISeason>()
            {
                seasonMock.Object
            });

            var message = command.Execute(new List <string>()
            {
                "Pesho", "0"
            });

            StringAssert.Contains("Pesho", message);
            StringAssert.Contains("0", message);
        }
Esempio n. 11
0
        public void Execute_ShouldThrowArgumentException_WhenStudentUsernameExistsInTheSeason()
        {
            // Arrange
            var factoryStub = new Mock <IAcademyFactory>();
            var engineStub  = new Mock <IEngine>();
            var command     = new AddStudentToSeasonCommand(factoryStub.Object, engineStub.Object);

            var studentStub = new Mock <IStudent>();
            var seasonStub  = new Mock <ISeason>();

            studentStub.SetupGet(s => s.Username).Returns("Pesho");
            seasonStub.SetupGet(s => s.Students).Returns(new List <IStudent> {
                studentStub.Object
            });

            engineStub.SetupGet(e => e.Students).Returns(new List <IStudent> {
                studentStub.Object
            });
            engineStub.SetupGet(e => e.Seasons).Returns(new List <ISeason> {
                seasonStub.Object
            });

            string validStudentUsername = "******";
            string validSeasonId        = "0";
            var    parameters           = new List <string> {
                validStudentUsername, validSeasonId
            };

            // Act and Assert
            Assert.Throws <ArgumentException>(() => command.Execute(parameters));
        }
Esempio n. 12
0
        public void ReturnMessageContainingStudentUsernameAndSeasonId_WhenTheStudentIsNotInTheSeason()
        {
            // Arrange
            var factoryMock = new Mock <IAcademyFactory>();
            var engineMock  = new Mock <IEngine>();

            var mockedStudent = new Mock <IStudent>();

            mockedStudent.SetupGet(x => x.Username).Returns("Pesho");

            engineMock.SetupGet(x => x.Students)
            .Returns(new List <IStudent>()
            {
                mockedStudent.Object
            });

            var mockedSeason = new Mock <ISeason>();

            var mockedStudent1 = new Mock <IStudent>();

            mockedStudent1.SetupGet(x => x.Username).Returns("Not Pesho");

            mockedSeason.SetupGet(x => x.Students)
            .Returns(new List <IStudent>()
            {
                mockedStudent1.Object
            });

            engineMock.Setup(x => x.Seasons)
            .Returns(new List <ISeason>()
            {
                mockedSeason.Object
            });

            var command = new AddStudentToSeasonCommand(factoryMock.Object, engineMock.Object);

            // Act
            var result = command.Execute(new List <string>()
            {
                "Pesho", "0"
            });


            // Assert
            StringAssert.Contains("Pesho", result);
            StringAssert.Contains("0", result);
        }
Esempio n. 13
0
        public void ReturnMessage_WhenTheStudentIsAddedToCollection()
        {
            // Arrange
            var factoryMock = new Mock <IAcademyFactory>();
            var engineMock  = new Mock <IEngine>();

            var studentMock = new Mock <IStudent>();

            studentMock.SetupGet(x => x.Username).Returns("Pesho");

            engineMock.SetupGet(x => x.Students).Returns(new List <IStudent>()
            {
                studentMock.Object
            });

            var seasonMock = new Mock <ISeason>();


            var studentMockNoPesho = new Mock <IStudent>();

            studentMockNoPesho.SetupGet(x => x.Username).Returns("Not Pesho");

            var studentsInSeason = new List <IStudent>()
            {
                studentMockNoPesho.Object
            };

            seasonMock.SetupGet(x => x.Students).Returns(studentsInSeason);

            engineMock.SetupGet(x => x.Seasons).Returns(new List <ISeason>()
            {
                seasonMock.Object
            });


            var command = new AddStudentToSeasonCommand(factoryMock.Object, engineMock.Object);

            // Act
            var result = command.Execute(new List <string>()
            {
                "Pesho", "0"
            });

            //Assert
            StringAssert.Contains("Pesho", result);
            StringAssert.Contains("Season 0", result);
        }
Esempio n. 14
0
        public void AddCorrectlyStudent_WhenTheStudentIsNotInTheSeason()
        {
            // Arrange
            var factoryMock = new Mock <IAcademyFactory>();
            var engineMock  = new Mock <IEngine>();

            var mockedStudent = new Mock <IStudent>();

            mockedStudent.SetupGet(x => x.Username).Returns("Pesho");

            engineMock.SetupGet(x => x.Students)
            .Returns(new List <IStudent>()
            {
                mockedStudent.Object
            });

            var mockedSeason = new Mock <ISeason>();

            var mockedStudent1 = new Mock <IStudent>();

            mockedStudent1.SetupGet(x => x.Username).Returns("Not Pesho");

            mockedSeason.SetupGet(x => x.Students)
            .Returns(new List <IStudent>()
            {
                mockedStudent1.Object
            });

            engineMock.Setup(x => x.Seasons)
            .Returns(new List <ISeason>()
            {
                mockedSeason.Object
            });

            var command = new AddStudentToSeasonCommand(factoryMock.Object, engineMock.Object);

            // Act
            command.Execute(new List <string>()
            {
                "Pesho", "0"
            });


            // Assert
            Assert.AreEqual(2, mockedSeason.Object.Students.Count());
        }
Esempio n. 15
0
        public void ReturnASuccesMessageContainingSetudentsUsernameAndId_WhenStudentIsAddedToSeason()
        {
            // arrange
            var factoryStub = new Mock <IAcademyFactory>();
            var engineStub  = new Mock <IEngine>();

            string userToAddUsername = "******";
            string seasonId          = "0";

            var inputParameters = new List <string>()
            {
                userToAddUsername, seasonId
            };

            var studentToAdd = new Mock <IStudent>();

            studentToAdd.Setup(x => x.Username).Returns(userToAddUsername);

            var engineStudents = new List <IStudent>()
            {
                studentToAdd.Object
            };

            engineStub.Setup(x => x.Students).Returns(engineStudents);

            var seasonStub     = new Mock <ISeason>();
            var seasonStudents = new List <IStudent>();

            seasonStub.Setup(x => x.Students).Returns(seasonStudents);

            var engineSeasons = new List <ISeason>()
            {
                seasonStub.Object
            };

            engineStub.Setup(x => x.Seasons).Returns(engineSeasons);

            var command = new AddStudentToSeasonCommand(factoryStub.Object, engineStub.Object);

            // act
            var resultMessage = command.Execute(inputParameters);

            // assert
            StringAssert.Contains(userToAddUsername, resultMessage);
            StringAssert.Contains(seasonId, resultMessage);
        }
Esempio n. 16
0
        public void CorrecltyAddStudentToSeason_WhenPassedStudentIsNotAlreadyAPartOfTheSeason()
        {
            // arrange
            var factoryStub = new Mock <IAcademyFactory>();
            var engineStub  = new Mock <IEngine>();

            string userToAddUsername = "******";
            string seasonId          = "0";

            var inputParameters = new List <string>()
            {
                userToAddUsername, seasonId
            };

            var studentToAdd = new Mock <IStudent>();

            studentToAdd.Setup(x => x.Username).Returns(userToAddUsername);

            var engineStudents = new List <IStudent>()
            {
                studentToAdd.Object
            };

            engineStub.Setup(x => x.Students).Returns(engineStudents);

            var seasonStub     = new Mock <ISeason>();
            var seasonStudents = new List <IStudent>();

            seasonStub.Setup(x => x.Students).Returns(seasonStudents);

            var engineSeasons = new List <ISeason>()
            {
                seasonStub.Object
            };

            engineStub.Setup(x => x.Seasons).Returns(engineSeasons);

            var command = new AddStudentToSeasonCommand(factoryStub.Object, engineStub.Object);

            // act
            command.Execute(inputParameters);

            // assert
            Assert.AreSame(seasonStudents.First(), studentToAdd.Object);
        }
Esempio n. 17
0
        public void ThrowArgumentException_WhenPassedStudentIsAlreadyPartOfTheSeason()
        {
            // arrange
            var factoryStub = new Mock <IAcademyFactory>();
            var engineStub  = new Mock <IEngine>();

            string userToAddUsername = "******";
            string seasonId          = "0";

            var inputParameters = new List <string>()
            {
                userToAddUsername, seasonId
            };

            var studentToAdd = new Mock <IStudent>();

            studentToAdd.Setup(x => x.Username).Returns(userToAddUsername);

            var engineStudents = new List <IStudent>()
            {
                studentToAdd.Object
            };

            engineStub.Setup(x => x.Students).Returns(engineStudents);

            var seasonStub     = new Mock <ISeason>();
            var seasonStudents = new List <IStudent>()
            {
                studentToAdd.Object
            };

            seasonStub.Setup(x => x.Students).Returns(seasonStudents);

            var engineSeasons = new List <ISeason>()
            {
                seasonStub.Object
            };

            engineStub.Setup(x => x.Seasons).Returns(engineSeasons);

            var command = new AddStudentToSeasonCommand(factoryStub.Object, engineStub.Object);

            // act and assert
            Assert.Throws <ArgumentException>(() => command.Execute(inputParameters));
        }
Esempio n. 18
0
        public void AddStudentInCollection_WhenTheStudentIsNotInTheSeason()
        {
            // Arrange
            var factoryMock = new Mock <IAcademyFactory>();
            var engineMock  = new Mock <IEngine>();

            var studentMock = new Mock <IStudent>();

            studentMock.SetupGet(x => x.Username).Returns("Pesho");

            engineMock.SetupGet(x => x.Students).Returns(new List <IStudent>()
            {
                studentMock.Object
            });

            var seasonMock = new Mock <ISeason>();

            var studentMockNoPesho = new Mock <IStudent>();

            studentMockNoPesho.SetupGet(x => x.Username).Returns("Not Pesho");

            var studentsInSeason = new List <IStudent>()
            {
                studentMockNoPesho.Object
            };

            seasonMock.SetupGet(x => x.Students).Returns(studentsInSeason);

            engineMock.SetupGet(x => x.Seasons).Returns(new List <ISeason>()
            {
                seasonMock.Object
            });

            var command = new AddStudentToSeasonCommand(factoryMock.Object, engineMock.Object);

            // Act
            var result = command.Execute(new List <string>()
            {
                "Pesho", "0"
            });

            // Assert
            Assert.AreEqual(2, seasonMock.Object.Students.Count);
        }
Esempio n. 19
0
        public void Execute_WhenStudentIsAddedToSeasonCorrectly_ShouldReturnCorrectSuccessMessage()
        {
            var factoryStub = new Mock <IAcademyFactory>();
            var studentStub = new Mock <IStudent>();

            studentStub.Setup(x => x.Username).Returns("Username");
            var engineStudentsStub = new List <IStudent>()
            {
                studentStub.Object
            };

            var seasonStub     = new Mock <ISeason>();
            var seasonStudents = new List <IStudent>();

            seasonStub.Setup(x => x.Students).Returns(seasonStudents);

            var engineSeasons = new List <ISeason>()
            {
                seasonStub.Object
            };

            var engineStub = new Mock <IEngine>();

            engineStub.Setup(x => x.Seasons).Returns(engineSeasons);
            engineStub.Setup(x => x.Students).Returns(engineStudentsStub);

            var command = new AddStudentToSeasonCommand(factoryStub.Object, engineStub.Object);

            var parameters = new List <string>()
            {
                "Username", "0"
            };

            // act
            string returnedValue = command.Execute(parameters);

            // assert
            StringAssert.Contains("Username", returnedValue);
            StringAssert.Contains("0", returnedValue);
        }
Esempio n. 20
0
        public void Execute_WhenStudentIsNotPresentInSeason_ShouldAddFoundStudent()
        {
            var factoryStub = new Mock <IAcademyFactory>();
            var studentStub = new Mock <IStudent>();

            studentStub.Setup(x => x.Username).Returns("Username");
            var engineStudentsStub = new List <IStudent>()
            {
                studentStub.Object
            };

            var seasonStub     = new Mock <ISeason>();
            var seasonStudents = new List <IStudent>();

            seasonStub.Setup(x => x.Students).Returns(seasonStudents);

            var engineSeasons = new List <ISeason>()
            {
                seasonStub.Object
            };

            var engineStub = new Mock <IEngine>();

            engineStub.Setup(x => x.Seasons).Returns(engineSeasons);
            engineStub.Setup(x => x.Students).Returns(engineStudentsStub);

            var command = new AddStudentToSeasonCommand(factoryStub.Object, engineStub.Object);

            var parameters = new List <string>()
            {
                "Username", "0"
            };

            // act
            command.Execute(parameters);

            // assert
            Assert.AreSame(studentStub.Object, seasonStub.Object.Students[0]);
        }
Esempio n. 21
0
        public void ThrowArgumentException_WhenStudentIsAlreadyPartOfTheSeason()
        {
            // Arrange
            var factoryMock = new Mock <IAcademyFactory>();
            var engineMock  = new Mock <IEngine>();

            var mockedStudent = new Mock <IStudent>();

            mockedStudent.SetupGet(x => x.Username).Returns("Pesho");

            engineMock.Setup(x => x.Students)
            .Returns(new List <IStudent>()
            {
                mockedStudent.Object
            });

            var mockedSeason = new Mock <ISeason>();

            mockedSeason.Setup(x => x.Students)
            .Returns(new List <IStudent>()
            {
                new Student("Pesho", Track.Dev)
            });

            engineMock.Setup(x => x.Seasons)
            .Returns(new List <ISeason>()
            {
                mockedSeason.Object
            });

            var command = new AddStudentToSeasonCommand(factoryMock.Object, engineMock.Object);

            // Act & Assert
            Assert.Throws <ArgumentException>(() => command.Execute(new List <string>()
            {
                "Pesho", "0"
            }));
        }