public void Release_Date_Less_Than_Expire_Date()
        {
            DateTime now      = DateTime.Now;
            var      schedule = new ContentScheduleCollection();

            Assert.IsFalse(schedule.Add(now, now));
        }
        public void Cannot_Add_Duplicate_Dates_Invariant()
        {
            DateTime now      = DateTime.Now;
            var      schedule = new ContentScheduleCollection();

            schedule.Add(now, null);
            Assert.Throws <ArgumentException>(() => schedule.Add(null, now));
        }
        public void Can_Remove_Invariant()
        {
            DateTime now      = DateTime.Now;
            var      schedule = new ContentScheduleCollection();

            schedule.Add(now, null);
            IEnumerable <ContentSchedule> invariantSched = schedule.GetSchedule(string.Empty);

            schedule.Remove(invariantSched.First());
            Assert.AreEqual(0, schedule.FullSchedule.Count());
        }
示例#4
0
        private ContentSchedule FindSchedule(ContentScheduleCollection currentSchedules, ContentSchedule newSchedule)
        {
            var schedule = currentSchedules.GetSchedule(newSchedule.Culture, newSchedule.Action);

            if (schedule != null && schedule.Any())
            {
                return(schedule.FirstOrDefault());
            }

            return(null);
        }
        public void Can_Clear_Start_Invariant()
        {
            DateTime now      = DateTime.Now;
            var      schedule = new ContentScheduleCollection();

            schedule.Add(now, now.AddDays(1));

            schedule.Clear(ContentScheduleAction.Release);

            Assert.AreEqual(0, schedule.GetSchedule(ContentScheduleAction.Release).Count());
            Assert.AreEqual(1, schedule.GetSchedule(ContentScheduleAction.Expire).Count());
            Assert.AreEqual(1, schedule.FullSchedule.Count());
        }
        public void Can_Remove_Variant()
        {
            var now      = DateTime.Now;
            var schedule = new ContentScheduleCollection();

            schedule.Add(now, null);
            schedule.Add("en-US", now, null);
            var invariantSched = schedule.GetSchedule(string.Empty);

            schedule.Remove(invariantSched.First());
            Assert.AreEqual(0, schedule.GetSchedule(string.Empty).Count());
            Assert.AreEqual(1, schedule.FullSchedule.Count());
            var variantSched = schedule.GetSchedule("en-US");

            schedule.Remove(variantSched.First());
            Assert.AreEqual(0, schedule.GetSchedule("en-US").Count());
            Assert.AreEqual(0, schedule.FullSchedule.Count());
        }
示例#7
0
        /// <summary>
        /// Gets the current status of the Content
        /// </summary>
        public static ContentStatus GetStatus(this IContent content, ContentScheduleCollection contentSchedule, string culture = null)
        {
            if (content.Trashed)
            {
                return(ContentStatus.Trashed);
            }

            if (!content.ContentType.VariesByCulture())
            {
                culture = string.Empty;
            }
            else if (culture.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException($"{nameof(culture)} cannot be null or empty");
            }

            var expires = contentSchedule.GetSchedule(culture, ContentScheduleAction.Expire);

            if (expires != null && expires.Any(x => x.Date > DateTime.MinValue && DateTime.Now > x.Date))
            {
                return(ContentStatus.Expired);
            }

            var release = contentSchedule.GetSchedule(culture, ContentScheduleAction.Release);

            if (release != null && release.Any(x => x.Date > DateTime.MinValue && x.Date > DateTime.Now))
            {
                return(ContentStatus.AwaitingRelease);
            }

            if (content.Published)
            {
                return(ContentStatus.Published);
            }

            return(ContentStatus.Unpublished);
        }
    public virtual void CreateTestData()
    {
        // NOTE Maybe not the best way to create/save test data as we are using the services, which are being tested.
        var template = TemplateBuilder.CreateTextPageTemplate();

        FileService.SaveTemplate(template);

        // Create and Save ContentType "umbTextpage" -> 1051 (template), 1052 (content type)
        ContentType =
            ContentTypeBuilder.CreateSimpleContentType("umbTextpage", "Textpage", defaultTemplateId: template.Id);
        ContentType.Key = new Guid("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522");
        ContentTypeService.Save(ContentType);

        // Create and Save Content "Homepage" based on "umbTextpage" -> 1053
        Textpage     = ContentBuilder.CreateSimpleContent(ContentType);
        Textpage.Key = new Guid("B58B3AD4-62C2-4E27-B1BE-837BD7C533E0");
        ContentService.Save(Textpage, 0);

        // Create and Save Content "Text Page 1" based on "umbTextpage" -> 1054
        Subpage = ContentBuilder.CreateSimpleContent(ContentType, "Text Page 1", Textpage.Id);
        var contentSchedule = ContentScheduleCollection.CreateWithEntry(DateTime.Now.AddMinutes(-5), null);

        ContentService.Save(Subpage, 0, contentSchedule);

        // Create and Save Content "Text Page 1" based on "umbTextpage" -> 1055
        Subpage2 = ContentBuilder.CreateSimpleContent(ContentType, "Text Page 2", Textpage.Id);
        ContentService.Save(Subpage2, 0);


        Subpage3 = ContentBuilder.CreateSimpleContent(ContentType, "Text Page 3", Textpage.Id);
        ContentService.Save(Subpage3, 0);

        // Create and Save Content "Text Page Deleted" based on "umbTextpage" -> 1056
        Trashed         = ContentBuilder.CreateSimpleContent(ContentType, "Text Page Deleted", -20);
        Trashed.Trashed = true;
        ContentService.Save(Trashed, 0);
    }
        public void Can_Clear_End_Variant()
        {
            var now      = DateTime.Now;
            var schedule = new ContentScheduleCollection();

            schedule.Add(now, now.AddDays(1));
            schedule.Add("en-US", now, now.AddDays(1));

            schedule.Clear(ContentScheduleAction.Expire);

            Assert.AreEqual(0, schedule.GetSchedule(ContentScheduleAction.Expire).Count());
            Assert.AreEqual(1, schedule.GetSchedule(ContentScheduleAction.Release).Count());
            Assert.AreEqual(1, schedule.GetSchedule("en-US", ContentScheduleAction.Expire).Count());
            Assert.AreEqual(1, schedule.GetSchedule("en-US", ContentScheduleAction.Release).Count());
            Assert.AreEqual(3, schedule.FullSchedule.Count());

            schedule.Clear("en-US", ContentScheduleAction.Expire);

            Assert.AreEqual(0, schedule.GetSchedule(ContentScheduleAction.Expire).Count());
            Assert.AreEqual(1, schedule.GetSchedule(ContentScheduleAction.Release).Count());
            Assert.AreEqual(0, schedule.GetSchedule("en-US", ContentScheduleAction.Expire).Count());
            Assert.AreEqual(1, schedule.GetSchedule("en-US", ContentScheduleAction.Release).Count());
            Assert.AreEqual(2, schedule.FullSchedule.Count());
        }
    public async Task Publish_Schedule_Is_Mapped_Correctly()
    {
        const string    UsIso               = "en-US";
        const string    DkIso               = "da-DK";
        const string    SweIso              = "sv-SE";
        var             contentTypeService  = GetRequiredService <IContentTypeService>();
        var             contentService      = GetRequiredService <IContentService>();
        var             localizationService = GetRequiredService <ILocalizationService>();
        IJsonSerializer serializer          = GetRequiredService <IJsonSerializer>();

        var contentType = new ContentTypeBuilder()
                          .WithContentVariation(ContentVariation.Culture)
                          .Build();

        contentTypeService.Save(contentType);

        var dkLang = new LanguageBuilder()
                     .WithCultureInfo(DkIso)
                     .WithIsDefault(false)
                     .Build();

        var sweLang = new LanguageBuilder()
                      .WithCultureInfo(SweIso)
                      .WithIsDefault(false)
                      .Build();

        localizationService.Save(dkLang);
        localizationService.Save(sweLang);

        var content = new ContentBuilder()
                      .WithoutIdentity()
                      .WithContentType(contentType)
                      .WithCultureName(UsIso, "Same Name")
                      .WithCultureName(SweIso, "Same Name")
                      .WithCultureName(DkIso, "Same Name")
                      .Build();

        contentService.Save(content);
        var schedule = new ContentScheduleCollection();

        var dkReleaseDate = new DateTime(2022, 06, 22, 21, 30, 42);
        var dkExpireDate  = new DateTime(2022, 07, 15, 18, 00, 00);

        var sweReleaseDate = new DateTime(2022, 06, 23, 22, 30, 42);
        var sweExpireDate  = new DateTime(2022, 07, 10, 14, 20, 00);

        schedule.Add(DkIso, dkReleaseDate, dkExpireDate);
        schedule.Add(SweIso, sweReleaseDate, sweExpireDate);
        contentService.PersistContentSchedule(content, schedule);

        var url = PrepareApiControllerUrl <ContentController>(x => x.GetById(content.Id));

        HttpResponseMessage response = await Client.GetAsync(url);

        Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

        var text = await response.Content.ReadAsStringAsync();

        text = text.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
        var display = serializer.Deserialize <ContentItemDisplayWithSchedule>(text);

        Assert.IsNotNull(display);
        Assert.AreEqual(1, _messageCount);

        var dkVariant = display.Variants.FirstOrDefault(x => x.Language?.IsoCode == DkIso);

        Assert.IsNotNull(dkVariant);
        Assert.AreEqual(dkReleaseDate, dkVariant.ReleaseDate);
        Assert.AreEqual(dkExpireDate, dkVariant.ExpireDate);

        var sweVariant = display.Variants.FirstOrDefault(x => x.Language?.IsoCode == SweIso);

        Assert.IsNotNull(sweVariant);
        Assert.AreEqual(sweReleaseDate, sweVariant.ReleaseDate);
        Assert.AreEqual(sweExpireDate, sweVariant.ExpireDate);

        var usVariant = display.Variants.FirstOrDefault(x => x.Language?.IsoCode == UsIso);

        Assert.IsNotNull(usVariant);
        Assert.IsNull(usVariant.ReleaseDate);
        Assert.IsNull(usVariant.ExpireDate);
    }
示例#11
0
        private IEnumerable <uSyncChange> DeserializeSchedules(IContent item, XElement node, SyncSerializerOptions options)
        {
            logger.LogDebug("Deserialize Schedules");

            var changes          = new List <uSyncChange>();
            var nodeSchedules    = new ContentScheduleCollection();
            var currentSchedules = contentService.GetContentScheduleByContentId(item.Id);
            var cultures         = options.GetDeserializedCultures(node);

            var schedules = node.Element("Info")?.Element("Schedule");

            if (schedules != null && schedules.HasElements)
            {
                foreach (var schedule in schedules.Elements("ContentSchedule"))
                {
                    var importSchedule = GetContentScheduleFromNode(schedule);
                    if (cultures.IsValidOrBlank(importSchedule.Culture))
                    {
                        if (importSchedule.Date < DateTime.Now)
                        {
                            continue; // don't add schedules in the past
                        }
                        logger.LogDebug("Adding {action} {culture} {date}", importSchedule.Action, importSchedule.Culture, importSchedule.Date);
                        nodeSchedules.Add(importSchedule);

                        var existing = FindSchedule(currentSchedules, importSchedule);
                        if (existing != null)
                        {
                            currentSchedules.Remove(existing);
                        }
                        currentSchedules.Add(importSchedule);
                        changes.Add(uSyncChange.Update("Schedule", $"{importSchedule.Culture} {importSchedule.Action}", "", importSchedule.Date.ToString()));
                    }
                }
            }

            if (currentSchedules != null)
            {
                // remove things that are in the current but not the import.

                var toRemove = currentSchedules.FullSchedule.Where(x => FindSchedule(nodeSchedules, x) == null);

                foreach (var oldItem in toRemove)
                {
                    if (cultures.IsValidOrBlank(oldItem.Culture))
                    {
                        logger.LogDebug("Removing Schedule : {culture} {action} {date}", oldItem.Culture, oldItem.Action, oldItem.Date);
                        // only remove a culture if this seralization included it.
                        // we don't remove things we didn't serialize.
                        currentSchedules.Remove(oldItem);

                        changes.Add(uSyncChange.Delete("Schedule", $"{oldItem.Culture} - {oldItem.Action}", oldItem.Date.ToString()));
                    }
                }

                if (changes.Any())
                {
                    contentService.PersistContentSchedule(item, currentSchedules);
                    return(changes);
                }

                return(Enumerable.Empty <uSyncChange>());
            }


            return(Enumerable.Empty <uSyncChange>());
        }
示例#12
0
 public static IEnumerable <(ContentSchedule Model, ContentScheduleDto Dto)> BuildScheduleDto(IContent entity, ContentScheduleCollection contentSchedule, ILanguageRepository languageRepository)
 {
     return(contentSchedule.FullSchedule.Select(x =>
                                                (x, new ContentScheduleDto
     {
         Action = x.Action.ToString(),
         Date = x.Date,
         NodeId = entity.Id,
         LanguageId = languageRepository.GetIdByIsoCode(x.Culture, false),
         Id = x.Id
     })));
 }
示例#13
0
 public static IEnumerable <(ContentSchedule Model, ContentScheduleDto Dto)> BuildScheduleDto(
     IContent entity,
     ContentScheduleCollection contentSchedule,
     ILanguageRepository languageRepository) =>