コード例 #1
0
ファイル: BrandSteps.cs プロジェクト: singlag888/aft-regov2
        public void ThenNewContentTranslationIsSuccessfullyCreated()
        {
            var contentName   = TestDataGenerator.GetRandomString();
            var contentSource = TestDataGenerator.GetRandomString();

            ScenarioContext.Current.Should().ContainKey("cultureCode");
            var cultureCode = ScenarioContext.Current.Get <string>("cultureCode");

            var translation = new AddContentTranslationData()
            {
                ContentName   = contentName,
                ContentSource = contentSource,
                Language      = cultureCode,
                Translation   = TestDataGenerator.GetRandomString()
            };

            var data = new AddContentTranslationModel()
            {
                Languages     = new List <string>(),
                Translations  = new[] { translation },
                ContentName   = contentName,
                ContentSource = contentSource
            };

            var result = AdminApiProxy.CreateContentTranslation(data);

            result.Should().NotBeNull();
            result.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.OK);
        }
コード例 #2
0
        public void CreateContentTranslation(AddContentTranslationData addContentTranslationData)
        {
            if (_repository.ContentTranslations.Any(
                    t =>
                    t.Name == addContentTranslationData.ContentName &&
                    t.Source == addContentTranslationData.ContentSource &&
                    t.Language == addContentTranslationData.Language))
            {
                throw new RegoException("Translation already exist");
            }

            var validationResult = new AddContentTranslationValidator(_repository).Validate(addContentTranslationData);

            if (!validationResult.IsValid)
            {
                throw new RegoValidationException(validationResult);
            }

            var language = _repository.Cultures.SingleOrDefault(
                cc =>
                cc.Code == addContentTranslationData.Language);

            if (language == null)
            {
                throw new RegoException("Language not found");
            }

            var contentTranslation = new ContentTranslation
            {
                Id          = Guid.NewGuid(),
                Name        = addContentTranslationData.ContentName,
                Source      = addContentTranslationData.ContentSource,
                Language    = language.Code,
                Translation = addContentTranslationData.Translation,
                Status      = TranslationStatus.Disabled,
                Created     = DateTimeOffset.Now,
                CreatedBy   = _actorInfoProvider.Actor.UserName
            };

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                _repository.ContentTranslations.Add(contentTranslation);
                _eventBus.Publish(new ContentTranslationCreated(contentTranslation));
                _repository.SaveChanges();
                scope.Complete();
            }
        }
コード例 #3
0
        public ValidationResult ValidateThatContentTranslationCanBeAdded(AddContentTranslationData addContentTranslationData)
        {
            var validator = new AddContentTranslationValidator(_repository);

            return(validator.Validate(addContentTranslationData));
        }