public void CallListUsersMethod_WhenParametersAreCorrect() { // Arange var engineMock = new Mock <IEngine>(); var factoryMock = new Mock <IAcademyFactory>(); var seasonMock1 = new Mock <ISeason>(); var seasonMock2 = new Mock <ISeason>(); List <ISeason> seasons = new List <ISeason>(); seasons.Add(seasonMock1.Object); seasons.Add(seasonMock2.Object); engineMock.Setup(m => m.Database.Seasons).Returns(seasons); var command = new ListUsersInSeasonCommand(factoryMock.Object, engineMock.Object); List <string> parameters = new List <string>() { "1" }; // Act command.Execute(parameters); // Assert seasonMock2.Verify(x => x.ListUsers(), Times.Once); }
public void ListASeasonsWithGivenId_WhenExists() { // Arrange var databaseMock = new Mock <IDatabase>(); var listCommand = new ListUsersInSeasonCommand(databaseMock.Object); var parametersList = new List <string>() { "0" }; string expectedResult = "some result"; var mockedSeason = new Mock <ISeason>(); mockedSeason.Setup(s => s.ListUsers()) .Returns(expectedResult); var seasonsDatabase = new List <ISeason>() { mockedSeason.Object }; databaseMock.SetupGet(d => d.Seasons) .Returns(seasonsDatabase); // Act string result = listCommand.Execute(parametersList); // Assert mockedSeason.Verify(s => s.ListUsers(), Times.Once); Assert.AreEqual(expectedResult, result); }
public void ThrowArgumentOutOfRangeException_WhenSeasonIdDoesntExist() { // Arrange var databaseMock = new Mock <IDatabase>(); var listCommand = new ListUsersInSeasonCommand(databaseMock.Object); var parametersList = new List <string>() { "2" }; var seasonsDatabase = new List <ISeason>() { new Mock <ISeason>().Object }; databaseMock.SetupGet(d => d.Seasons) .Returns(seasonsDatabase); // Act & Assert Assert.ThrowsException <ArgumentOutOfRangeException>(() => { listCommand.Execute(parametersList); }); }
public void ReturnStringRepresentingUsers_WhenParametersAreCorrect() { //Arrange var factoryMok = new Mock <IAcademyFactory>(); var databaseMock = new Mock <IDatabase>(); var firstSeasonMock = new Mock <ISeason>(); var secondSeasonMock = new Mock <ISeason>(); List <ISeason> seasons = new List <ISeason>() { firstSeasonMock.Object, secondSeasonMock.Object }; List <string> parameters = new List <string>() { "1" }; string expectedResult = "listing users"; databaseMock.SetupGet(m => m.Seasons).Returns(seasons); secondSeasonMock.Setup(m => m.ListUsers()).Returns(expectedResult); ListUsersInSeasonCommand command = new ListUsersInSeasonCommand(factoryMok.Object, databaseMock.Object); //Act var result = command.Execute(parameters); //Assert secondSeasonMock.Verify(m => m.ListUsers(), Times.Once()); Assert.AreEqual(expectedResult, result); }