public async Task AddTutorial_WithDuplicateTitle_ShouldTrow() { //Arrange var db = this.SetDb(); var repo = new Repository <Tutorial>(db); var service = new TutorialService(repo, this.Mapper, null); var model1 = new AddTutorialViewModel { Title = "Lotus Flower", Description = "Lotus Test Descripion", Url = "https://someurl.bg" }; var model2 = new AddTutorialViewModel { Title = "Lotus Flower", Description = "Lotus Test Descripion", Url = "https://otherurl.bg" }; await service.AddTutorial(model1); //Act //Assert await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.AddTutorial(model2)); }
public void AddTutorial_Success_Test() { // Arrange TutorialDTO dto = SampleTutorialDTO(1); // create mock for repository var mock = new Mock <ITutorialRepository>(); mock.Setup(s => s.AddTutorial(Moq.It.IsAny <R_Tutorial>())).Returns(1); // service TutorialService tutorialService = new TutorialService(); TutorialService.Repository = mock.Object; // Act int id = tutorialService.AddTutorial(dto); // Assert Assert.AreEqual(1, id); Assert.AreEqual(1, dto.TutorialId); }
public async Task AddTutorial_WithValidModel_ShouldBeSuccessful() { //Arrange var db = this.SetDb(); var repo = new Repository <Tutorial>(db); var service = new TutorialService(repo, this.Mapper, null); var model = new AddTutorialViewModel { Title = "Lotus Flower", Description = "Lotus Test Descripion", Url = "https://someurl.bg" }; //Act await service.AddTutorial(model); var expectedTutorialsCount = 1; var actualTutorialsCount = repo.All().Count(); //Assert Assert.Equal(expectedTutorialsCount, actualTutorialsCount); }