Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
 public int Create([FromBody] Picture picture)
 {
     return(pictureService.AddPicture(picture));
 }