public void ListService_Should_Call_ServiceRepository() { // Arrange var serviceRepoMock = new Mock <IServiceRepository>(); var userMock = new Mock <IUserRepository>(); var writerMock = new Mock <IWriter>(); var sut = new ListServicesCommand(serviceRepoMock.Object, writerMock.Object); // var list = new List <IService>(); var serviceMock = new Mock <IService>(); serviceMock.SetupGet(x => x.Name).Returns("Name"); list.Add(serviceMock.Object); serviceRepoMock.SetupGet(x => x.Services).Returns(list); serviceRepoMock.Setup(x => x.DeleteService(It.IsAny <string>())); // var serviceFactoryMock = new Mock<IServiceFactory>(); var parameters = new List <string>() { "", "Name", "7" }; sut.Parameters = parameters; // Act sut.Execute(); // Assert serviceRepoMock.Verify(x => x.Services, Times.Exactly(2)); }
public void ListService_Should_Throw_ArgumentException_When_TheRepoIsEmpty() { // Arrange var serviceRepoMock = new Mock <IServiceRepository>(); var userMock = new Mock <IUserRepository>(); var writerMock = new Mock <IWriter>(); var sut = new ListServicesCommand(serviceRepoMock.Object, writerMock.Object); // var list = new List <IService>(); var serviceMock = new Mock <IService>(); serviceMock.SetupGet(x => x.Name).Returns("Name"); // list.Add(serviceMock.Object); serviceRepoMock.SetupGet(x => x.Services).Returns(list); serviceRepoMock.Setup(x => x.DeleteService(It.IsAny <string>())); // var serviceFactoryMock = new Mock<IServiceFactory>(); var parameters = new List <string>() { "", "Name", "7" }; sut.Parameters = parameters; // Act & Assert Assert.ThrowsException <ArgumentException>(() => sut.Execute()); }