Пример #1
0
        public void Should_throw_exception_when_page_is_not_found()
        {
            var command = new AddModule
            {
                SiteId       = Guid.NewGuid(),
                PageId       = Guid.NewGuid(),
                ModuleTypeId = Guid.NewGuid(),
                Zone         = "Zone",
                SortOrder    = 1,
                Title        = "Title"
            };

            var moduleRepositoryMock = new Mock <IModuleRepository>();
            var pageRepositoryMock   = new Mock <IPageRepository>();

            pageRepositoryMock.Setup(x => x.GetById(command.SiteId, command.PageId)).Returns((Page)null);
            var createModuleValidatorMock = new Mock <IValidator <CreateModule> >();

            createModuleValidatorMock.Setup(x => x.Validate(It.IsAny <CreateModule>())).Returns(new ValidationResult());
            var addPageModuleValidatorMock = new Mock <IValidator <AddPageModule> >();

            addPageModuleValidatorMock.Setup(x => x.Validate(It.IsAny <AddPageModule>())).Returns(new ValidationResult());

            var addModuleHandler = new AddModuleHandler(moduleRepositoryMock.Object,
                                                        pageRepositoryMock.Object,
                                                        createModuleValidatorMock.Object,
                                                        addPageModuleValidatorMock.Object);

            Assert.Throws <Exception>(() => addModuleHandler.Handle(command));
        }
Пример #2
0
        public void Should_update_page()
        {
            var command = new AddModule
            {
                SiteId       = Guid.NewGuid(),
                PageId       = Guid.NewGuid(),
                ModuleTypeId = Guid.NewGuid(),
                Zone         = "Zone",
                SortOrder    = 1,
                Title        = "Title"
            };

            var moduleRepositoryMock = new Mock <IModuleRepository>();
            var pageRepositoryMock   = new Mock <IPageRepository>();

            pageRepositoryMock.Setup(x => x.GetById(command.SiteId, command.PageId)).Returns(new Page());
            pageRepositoryMock.Setup(x => x.Update(It.IsAny <Page>()));
            var createModuleValidatorMock = new Mock <IValidator <CreateModule> >();

            createModuleValidatorMock.Setup(x => x.Validate(It.IsAny <CreateModule>())).Returns(new ValidationResult());
            var addPageModuleValidatorMock = new Mock <IValidator <AddPageModule> >();

            addPageModuleValidatorMock.Setup(x => x.Validate(It.IsAny <AddPageModule>())).Returns(new ValidationResult());

            var addModuleHandler = new AddModuleHandler(moduleRepositoryMock.Object,
                                                        pageRepositoryMock.Object,
                                                        createModuleValidatorMock.Object,
                                                        addPageModuleValidatorMock.Object);

            addModuleHandler.Handle(command);

            pageRepositoryMock.Verify(x => x.Update(It.IsAny <Page>()));
        }
Пример #3
0
        public void Should_return_events()
        {
            var command = new AddModule
            {
                SiteId       = Guid.NewGuid(),
                PageId       = Guid.NewGuid(),
                ModuleTypeId = Guid.NewGuid(),
                Zone         = "Zone",
                SortOrder    = 1,
                Title        = "Title"
            };

            var moduleRepositoryMock = new Mock <IModuleRepository>();
            var pageRepositoryMock   = new Mock <IPageRepository>();

            pageRepositoryMock.Setup(x => x.GetById(command.SiteId, command.PageId)).Returns(new Page());
            var createModuleValidatorMock = new Mock <IValidator <CreateModule> >();

            createModuleValidatorMock.Setup(x => x.Validate(It.IsAny <CreateModule>())).Returns(new ValidationResult());
            var addPageModuleValidatorMock = new Mock <IValidator <AddPageModule> >();

            addPageModuleValidatorMock.Setup(x => x.Validate(It.IsAny <AddPageModule>())).Returns(new ValidationResult());

            var addModuleHandler = new AddModuleHandler(moduleRepositoryMock.Object,
                                                        pageRepositoryMock.Object,
                                                        createModuleValidatorMock.Object,
                                                        addPageModuleValidatorMock.Object);

            var events = addModuleHandler.Handle(command);

            Assert.AreEqual(2, events.Count);
            Assert.AreEqual(typeof(ModuleCreated), events.FirstOrDefault().GetType());
            Assert.AreEqual(typeof(PageModuleAdded), events.Skip(1).FirstOrDefault().GetType());
        }
Пример #4
0
        public void Should_add_module_to_page()
        {
            var command = new AddModule
            {
                SiteId       = Guid.NewGuid(),
                PageId       = Guid.NewGuid(),
                ModuleTypeId = Guid.NewGuid(),
                Zone         = "Zone",
                SortOrder    = 2,
                Title        = "Title"
            };

            var page = PageFactory.Page(command.SiteId, command.PageId, "My Page");

            page.Events.Clear();

            var moduleRepositoryMock = new Mock <IModuleRepository>();

            var pageRepositoryMock = new Mock <IPageRepository>();

            pageRepositoryMock.Setup(x => x.GetById(command.SiteId, command.PageId)).Returns(page);
            pageRepositoryMock.Setup(x => x.Update(It.IsAny <Page>()));

            var createModuleValidatorMock = new Mock <IValidator <CreateModule> >();

            createModuleValidatorMock.Setup(x => x.Validate(It.IsAny <CreateModule>())).Returns(new ValidationResult());

            var addPageModuleValidatorMock = new Mock <IValidator <AddPageModule> >();

            addPageModuleValidatorMock.Setup(x => x.Validate(It.IsAny <AddPageModule>())).Returns(new ValidationResult());

            var addModuleHandler = new AddModuleHandler(moduleRepositoryMock.Object,
                                                        pageRepositoryMock.Object,
                                                        createModuleValidatorMock.Object,
                                                        addPageModuleValidatorMock.Object);

            addModuleHandler.Handle(command);

            var @event = page.Events.OfType <PageModuleAdded>().SingleOrDefault();

            Assert.IsNotNull(@event);
        }