Пример #1
0
        public void Should_throw_exception_when_page_is_not_found()
        {
            var command = new HidePage
            {
                SiteId = Guid.NewGuid(),
                Id     = Guid.NewGuid()
            };

            var repositoryMock = new Mock <IPageRepository>();

            repositoryMock.Setup(x => x.GetById(command.SiteId, command.Id)).Returns((Page)null);

            var validatorMock = new Mock <IValidator <HidePage> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            var hidePageHandler = new HidePageHandler(repositoryMock.Object, validatorMock.Object);

            Assert.Throws <Exception>(() => hidePageHandler.Handle(command));
        }
Пример #2
0
        public void Should_update_page()
        {
            var command = new HidePage
            {
                SiteId = Guid.NewGuid(),
                Id     = Guid.NewGuid()
            };

            var pageMock = new Mock <Page>();

            var repositoryMock = new Mock <IPageRepository>();

            repositoryMock.Setup(x => x.GetById(command.SiteId, command.Id)).Returns(pageMock.Object);

            var validatorMock = new Mock <IValidator <HidePage> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            var hidePageHandler = new HidePageHandler(repositoryMock.Object, validatorMock.Object);

            hidePageHandler.Handle(command);

            repositoryMock.Verify(x => x.Update(It.IsAny <Page>()));
        }