public void TestAddPicture() { var service = new PictureService(carpentryWebsiteContext); Picture itemToAdd = new Picture { PictureId = 105, PictureName = "Different name" }; service.AddPicture(itemToAdd); Picture result = service.GetPictureDetails(105); Assert.Equal(itemToAdd, result); }
public void ThrowArgumentNullExceptionWhenPlaceIsNull() { // Arrange var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedRepository = new Mock <IEfGenericRepository <Picture> >(); var service = new PictureService(mockedRepository.Object, mockedUnitOfWork.Object); // Act var message = Assert.Throws <ArgumentNullException>(() => service.AddPicture(null)); // Assert StringAssert.IsMatch("picture", message.ParamName); }
public void CallUnitOfWorkMethodCommitOnce() { // Arrange var mockedUnitOfWork = new Mock <IUnitOfWork>(); var mockedRepository = new Mock <IEfGenericRepository <Picture> >(); var service = new PictureService(mockedRepository.Object, mockedUnitOfWork.Object); var mockedPicture = new Mock <Picture>(); // Act service.AddPicture(mockedPicture.Object); // Assert mockedUnitOfWork.Verify(x => x.Commit(), Times.Once); }
public void TestEditPictures() { string expectedName = "Different Picture Name"; var service = new PictureService(carpentryWebsiteContext); Picture itemToAdd = new Picture { PictureId = 11, PictureName = "Different name" }; service.AddPicture(itemToAdd); carpentryWebsiteContext.Entry(service.GetPictureDetails(11)).State = EntityState.Detached; service.UpdatePicture(new Picture(11, "Different Picture Name")); Picture result = service.GetPictureDetails(11); Assert.Equal(expectedName, result.PictureName); }
public int Create([FromBody] Picture picture) { return(pictureService.AddPicture(picture)); }