public void ReturnSuccessMessage_WhenInvokedWithValidParameters() { // Arrange var sportscardFactoryMock = new Mock <ISportscardFactory>(); var sportServiceMock = new Mock <ISportService>(); var sportName = "Gym"; var expectedMessage = $"Sport {sportName} was added to database."; var expectedSport = new SportDto() { Name = sportName }; sportscardFactoryMock .Setup(x => x.CreateSportDto(sportName)) .Returns(expectedSport); var addSportCommand = new AddSportCommand(sportscardFactoryMock.Object, sportServiceMock.Object); var parameters = new List <string>() { sportName }; //Act var actualMessage = addSportCommand.Execute(parameters); //Assert Assert.AreEqual(expectedMessage, actualMessage); }
public void ThrowArgumentNullException_WhenInvokedWithInvalidNullSportNameParameter() { // Arrange var sportscardFactoryMock = new Mock <ISportscardFactory>(); var sportServiceMock = new Mock <ISportService>(); var sportName = "Gym"; var expectedMessage = $"{sportName} sport was added to database."; var expectedSport = new SportDto() { Name = sportName }; sportscardFactoryMock .Setup(x => x.CreateSportDto(sportName)) .Returns(expectedSport); var addSportCommand = new AddSportCommand(sportscardFactoryMock.Object, sportServiceMock.Object); var parameters = new List <string>() { null }; //Act && Assert Assert.ThrowsException <ArgumentNullException>(() => addSportCommand.Execute(parameters)); }
public void CallSportAddMethodOnce_WhenInvokedWithValidParameters() { // Arrange var sportscardFactoryMock = new Mock <ISportscardFactory>(); var sportServiceMock = new Mock <ISportService>(); var sportName = "Gym"; var expectedSport = new SportDto() { Name = sportName }; sportscardFactoryMock .Setup(x => x.CreateSportDto(sportName)) .Returns(expectedSport); var addSportCommand = new AddSportCommand(sportscardFactoryMock.Object, sportServiceMock.Object); var parameters = new List <string>() { sportName }; //Act addSportCommand.Execute(parameters); //Assert sportServiceMock.Verify(x => x.AddSport(expectedSport), Times.Once); }