public void GetByName_TopicNameIsNull_ThrowsArgumentNullException() { // Arrange ITopicService target = new TopicService(new Mock<IUnitOfWork>().Object, this._topicValidationMock.Object); // Act and Assert Assert.Throws<ArgumentNullException>(() => target.GetByName(null)); }
public void GetByName_TopicNameIsValid_ReturnsTopic() { // Arrange Topic testTopic = new Topic { TopicId = 1, Name = "topic_name" }; // Arrange - mock topicRepository Mock<ITopicRepository> topicRepositoryMock = new Mock<ITopicRepository>(); topicRepositoryMock.Setup(r => r.GetByName(testTopic.Name)) .Returns(testTopic); // Arrange - mock unitOfWork Mock<IUnitOfWork> unitOfWorkMock = new Mock<IUnitOfWork>(); unitOfWorkMock.SetupGet(u => u.TopicRepository) .Returns(topicRepositoryMock.Object); // Arrange - create target ITopicService target = new TopicService(unitOfWorkMock.Object, this._topicValidationMock.Object); // Act Topic topic = target.GetByName(testTopic.Name); // Assert Assert.AreSame(testTopic, topic); }
public void GetByName_NonexistentTopicName_ReturnsNull() { // Arrange string topicName = "nonexistent_topic_name"; // Arrange - mock topicRepository Mock<ITopicRepository> topicRepositoryMock = new Mock<ITopicRepository>(); topicRepositoryMock.Setup(r => r.GetByName(topicName)) .Returns((Topic)null); // Arrange - mock unitOfWork Mock<IUnitOfWork> unitOfWorkMock = new Mock<IUnitOfWork>(); unitOfWorkMock.SetupGet(u => u.TopicRepository) .Returns(topicRepositoryMock.Object); // Arrange - create target ITopicService target = new TopicService(unitOfWorkMock.Object, this._topicValidationMock.Object); // Act Topic topic = target.GetByName(topicName); // Assert Assert.IsNull(topic); }