示例#1
0
        public void Should_call_validator()
        {
            var language      = new Language();
            var command       = new HideLanguage();
            var validatorMock = new Mock <IValidator <HideLanguage> >();

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

            language.Hide(command, validatorMock.Object);

            validatorMock.Verify(x => x.Validate(command));
        }
示例#2
0
        public void Should_set_language_status_to_hidden()
        {
            var language      = new Language();
            var command       = new HideLanguage();
            var validatorMock = new Mock <IValidator <HideLanguage> >();

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

            language.Hide(command, validatorMock.Object);

            Assert.AreEqual(true, language.Status == LanguageStatus.Hidden);
        }
示例#3
0
        public void Should_throw_exception_when_already_hidden()
        {
            var language      = new Language();
            var command       = new HideLanguage();
            var validatorMock = new Mock <IValidator <HideLanguage> >();

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

            language.Hide(command, validatorMock.Object);

            Assert.Throws <Exception>(() => language.Hide(command, validatorMock.Object));
        }
        public void Should_have_validation_error_when_site_id_is_empty()
        {
            var command = new HideLanguage
            {
                SiteId = Guid.Empty,
                Id     = Guid.NewGuid()
            };

            var siteRulesMock = new Mock <ISiteRules>();
            var validator     = new HideLanguageValidator(siteRulesMock.Object);

            validator.ShouldHaveValidationErrorFor(x => x.SiteId, command);
        }
示例#5
0
        public void Should_set_id_in_language_hidden_event()
        {
            var language      = new Language();
            var command       = new HideLanguage();
            var validatorMock = new Mock <IValidator <HideLanguage> >();

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

            language.Hide(command, validatorMock.Object);

            var @event = language.Events.OfType <LanguageHidden>().SingleOrDefault();

            Assert.AreEqual(language.Id, @event.AggregateRootId);
        }
示例#6
0
        public void Should_add_language_hidden_event()
        {
            var language      = new Language();
            var command       = new HideLanguage();
            var validatorMock = new Mock <IValidator <HideLanguage> >();

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

            language.Hide(command, validatorMock.Object);

            var @event = language.Events.OfType <LanguageHidden>().SingleOrDefault();

            Assert.IsNotNull(@event);
        }
        public void Should_have_validation_error_when_site_does_not_exist()
        {
            var command = new HideLanguage
            {
                SiteId = Guid.NewGuid(),
                Id     = Guid.NewGuid()
            };

            var siteRulesMock = new Mock <ISiteRules>();

            siteRulesMock.Setup(x => x.DoesSiteExist(command.SiteId)).Returns(false);

            var validator = new HideLanguageValidator(siteRulesMock.Object);

            validator.ShouldHaveValidationErrorFor(x => x.SiteId, command);
        }
示例#8
0
        public void Should_throw_exception_when_deleted()
        {
            var language      = new Language();
            var command       = new HideLanguage();
            var validatorMock = new Mock <IValidator <HideLanguage> >();

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

            var deleteLanguageCommand = new DeleteLanguage
            {
                SiteId = language.SiteId,
                Id     = language.Id
            };
            var deleteLanguageValidatorMock = new Mock <IValidator <DeleteLanguage> >();

            deleteLanguageValidatorMock.Setup(x => x.Validate(deleteLanguageCommand)).Returns(new ValidationResult());
            language.Delete(deleteLanguageCommand, deleteLanguageValidatorMock.Object);

            Assert.Throws <Exception>(() => language.Hide(command, validatorMock.Object));
        }
示例#9
0
        public void Should_throw_exception_when_language_is_not_found()
        {
            var command = new HideLanguage
            {
                SiteId = Guid.NewGuid(),
                Id     = Guid.NewGuid()
            };

            var repositoryMock = new Mock <ILanguageRepository>();

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

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

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

            var hideLanguageHandler = new HideLanguageHandler(repositoryMock.Object, validatorMock.Object);

            Assert.Throws <Exception>(() => hideLanguageHandler.Handle(command));
        }
示例#10
0
        public void Hide(HideLanguage cmd, IValidator <HideLanguage> validator)
        {
            validator.ValidateCommand(cmd);

            if (Status == LanguageStatus.Hidden)
            {
                throw new Exception("Language already hidden.");
            }

            if (Status == LanguageStatus.Deleted)
            {
                throw new Exception("Language is deleted.");
            }

            AddEvent(new LanguageHidden
            {
                SiteId          = SiteId,
                AggregateRootId = Id
            });
        }
示例#11
0
        public void Should_update_language()
        {
            var command = new HideLanguage
            {
                SiteId = Guid.NewGuid(),
                Id     = Guid.NewGuid()
            };

            var languageMock = new Mock <Language>();

            var repositoryMock = new Mock <ILanguageRepository>();

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

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

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

            var hideLanguageHandler = new HideLanguageHandler(repositoryMock.Object, validatorMock.Object);

            hideLanguageHandler.Handle(command);

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