Exemplo n.º 1
0
        public void Execute_ShouldThrow_WhenThePassedStudentIsAlreadyAPartOfThatSeason()
        {
            var factoryMock = new Mock <IAcademyFactory>();
            var engineMock  = new Mock <IEngine>();
            var parameters  = new List <string>()
            {
                "username", "0"
            };
            var seasonMock  = new Mock <ISeason>();
            var studentMock = new Mock <IStudent>();

            studentMock.SetupGet(x => x.Username).Returns("username");
            var seasonStudents = new List <IStudent>()
            {
                studentMock.Object
            };

            seasonMock.SetupGet(x => x.Students).Returns(seasonStudents);
            engineMock.SetupGet(x => x.Students).Returns(seasonStudents);

            engineMock.Setup(x => x.Seasons[0]).Returns(seasonMock.Object);

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

            // Act & Assert
            Assert.Throws <ArgumentException>(() => command.Execute(parameters));
        }
Exemplo n.º 2
0
        public void Execute_ShouldCorrectlyAddTheFoundStudentIntoTheSeason_WhenThePassedStudentIsNotYetPresent()
        {
            var factoryMock = new Mock <IAcademyFactory>();
            var engineMock  = new Mock <IEngine>();
            var parameters  = new List <string>()
            {
                "username", "0"
            };
            var seasonMock = new Mock <ISeason>();

            var studentMock = new Mock <IStudent>();

            studentMock.SetupGet(x => x.Username).Returns("username");
            var engineStudents = new List <IStudent>()
            {
                studentMock.Object
            };

            var studentMockSeason = new Mock <IStudent>();

            studentMockSeason.SetupGet(x => x.Username).Returns("not username");
            var seasonStudents = new List <IStudent>()
            {
                studentMockSeason.Object
            };

            engineMock.SetupGet(x => x.Students).Returns(engineStudents);
            seasonMock.SetupGet(x => x.Students).Returns(seasonStudents);

            engineMock.Setup(x => x.Seasons[0]).Returns(seasonMock.Object);

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

            // Act
            command.Execute(parameters);

            // Assert
            Assert.AreEqual(2, seasonMock.Object.Students.Count);
        }
Exemplo n.º 3
0
        public void Execute_ShouldReturnCorrectMessageOnAddingStudent_WhenThePassedStudentIsNotYetPresent()
        {
            var factoryMock = new Mock <IAcademyFactory>();
            var engineMock  = new Mock <IEngine>();
            var parameters  = new List <string>()
            {
                "username", "0"
            };
            var seasonMock = new Mock <ISeason>();

            var studentMock = new Mock <IStudent>();

            studentMock.SetupGet(x => x.Username).Returns("username");
            var engineStudents = new List <IStudent>()
            {
                studentMock.Object
            };

            var studentMockSeason = new Mock <IStudent>();

            studentMockSeason.SetupGet(x => x.Username).Returns("not username");
            var seasonStudents = new List <IStudent>()
            {
                studentMockSeason.Object
            };

            engineMock.SetupGet(x => x.Students).Returns(engineStudents);
            seasonMock.SetupGet(x => x.Students).Returns(seasonStudents);

            engineMock.Setup(x => x.Seasons[0]).Returns(seasonMock.Object);

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

            // Act
            var message = command.Execute(parameters);

            // Assert
            Assert.AreEqual("Student username was added to Season 0.", message);
        }