public void AddOneVideo() { var mockVideo = new Mock <IVideoLogic>(MockBehavior.Strict); mockVideo.Setup(res => res.Get(videoList[0].Id)).Returns(videoList[0]); VideoController controller = new VideoController(mockVideo.Object); var result = controller.Add(videoList[0]); var okResult = result as OkObjectResult; Assert.AreEqual(new ObjectResult("").ToString(), controller.Add(videoList[0]).ToString()); }
public void ReturnJsonWithErrorMessage_IfVideoTitleIsNotValid() { // Arrange var galleryName = "Valid name"; var videoUrl = "url"; var galleryId = "id"; var mockedService = new Mock <IVideoService>(); mockedService.Setup(s => s.GetGalleryNameById(It.IsAny <string>())).Returns(galleryName); mockedService.Setup(s => s.AddVideoToGallery(It.IsAny <string>(), It.IsAny <Video>())).Verifiable(); var mockedVideoFactory = new Mock <IVideoFactory>(); var mockedDateProvider = new Mock <IDateProvider>(); var mockedModel = new AddVideoViewModel() { VideoUrl = videoUrl, GalleryId = galleryId }; var controller = new VideoController(mockedService.Object, mockedVideoFactory.Object, mockedDateProvider.Object); controller.ModelState.AddModelError("VideoTitle", "Error"); // Act var result = controller.Add(mockedModel) as JsonResult; dynamic dResult = result.Data; // Assert Assert.AreEqual(GlobalMessages.InvalidVideoTitleMessage, dResult.message); Assert.AreEqual("error", dResult.status); mockedService.Verify(s => s.AddVideoToGallery(It.IsAny <string>(), It.IsAny <Video>()), Times.Never); mockedVideoFactory.Verify(f => f.CreateVideo(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>()), Times.Never); mockedDateProvider.Verify(p => p.GetDate(), Times.Never); }
public void AddVideoError() { videoList[0].Name = ""; var mockVideo = new Mock <IVideoLogic>(MockBehavior.Strict); mockVideo.Setup(r => r.Add(videoList[0])).Throws(new FieldEnteredNotCorrect("")); VideoController controller = new VideoController(mockVideo.Object); var result = controller.Add(videoList[0]); Assert.AreEqual(new UnprocessableEntityObjectResult("").ToString(), result.ToString()); }
public void DeleteVideoIdNegative() { var mockVideo = new Mock <IVideoLogic>(MockBehavior.Strict); var controller = new VideoController(mockVideo.Object); controller.Add(videoList[0]); var result = controller.Delete(-2); Assert.AreEqual(new NotFoundObjectResult("").ToString(), result.ToString()); }
public void DeleteVideoOk() { var mockVideo = new Mock <IVideoLogic>(MockBehavior.Strict); mockVideo.Setup(t => t.Get(1)).Returns(videoList[0]); mockVideo.Setup(t => t.Delete(videoList[0])); var controller = new VideoController(mockVideo.Object); controller.Add(videoList[0]); var result = controller.Delete(1); Assert.AreEqual(new OkObjectResult("").ToString(), result.ToString()); }
public void CallAddVideoToGalleryFromVideoService_AndReturnSuccessMessage_IfVideoIsAdded() { // Arrange var galleryName = "Valid name"; var videoUrl = "url"; var galleryId = "id"; var videoTitle = "Title"; var mockedService = new Mock <IVideoService>(); mockedService.Setup(s => s.GetGalleryNameById(It.IsAny <string>())).Returns(galleryName).Verifiable(); mockedService.Setup(s => s.AddVideoToGallery(It.IsAny <string>(), It.IsAny <Video>())).Verifiable(); mockedService.Setup(s => s.Save()).Verifiable(); var mockedVideoFactory = new Mock <IVideoFactory>(); mockedVideoFactory.Setup(f => f.CreateVideo(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>())).Verifiable(); var mockedDateProvider = new Mock <IDateProvider>(); mockedDateProvider.Setup(p => p.GetDate()).Verifiable(); var controller = new VideoController(mockedService.Object, mockedVideoFactory.Object, mockedDateProvider.Object); var mockedModel = new AddVideoViewModel() { VideoUrl = videoUrl, GalleryId = galleryId, VideoTitle = videoTitle }; // Act var result = controller.Add(mockedModel) as JsonResult; dynamic dResult = result.Data; // Assert Assert.AreEqual(GlobalMessages.AddVideoSuccessMessage, dResult.message); Assert.AreEqual("success", dResult.status); mockedService.Verify(s => s.GetGalleryNameById(It.IsAny <string>()), Times.Once); mockedService.Verify(s => s.AddVideoToGallery(It.IsAny <string>(), It.IsAny <Video>()), Times.Once); mockedService.Verify(s => s.Save(), Times.Once); mockedDateProvider.Verify(p => p.GetDate(), Times.Once); mockedVideoFactory.Verify(f => f.CreateVideo(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>()), Times.Once); }
public void GetAllGalleryNames_AndStoreItToViewModel() { // Arrange var galleryNames = new VideoGalleryModel[] { new VideoGalleryModel { Name = "Test" }, new VideoGalleryModel { Name = "Test2" } }; var mockedService = new Mock <IVideoService>(); mockedService.Setup(s => s.GetAll()).Returns(galleryNames).Verifiable(); var mockedVideoFactory = new Mock <IVideoFactory>(); var mockedDateProvider = new Mock <IDateProvider>(); var controller = new VideoController(mockedService.Object, mockedVideoFactory.Object, mockedDateProvider.Object); // Act var view = controller.Add() as ViewResult; var model = view.ViewData.Model as AddVideoViewModel; // Assert Assert.IsAssignableFrom <AddVideoViewModel>(model); Assert.IsTrue(model.GalleryNames.Count() == 3); Assert.IsTrue(model.GalleryNames.Last().Text == "Test2"); }