public void Init()
 {
     _eventRepository = new EventRepository();
     _creatorId       = Guid.NewGuid();
     _tracker         = CreateTrackerWithDefaultCustomization(_creatorId);
     _events          = CreateEvents(_creatorId, _creatorId, EventsNumber);
     _eventRepository.AddRangeOfEvents(_events);
     _worstEventCalculator = new WorstRatingEventCalculator();
     _now = DateTimeOffset.Now;
 }
        public void EarliestEventsAfterThreeMonthAfterMoreThen7DaysAgo_CalculateSuccess()
        {
            //assert
            var userId  = Guid.NewGuid();
            var now     = DateTimeOffset.Now;
            var tracker = CreateTrackerWithScale(userId, "Kg");

            var(events, _, _) =
                CreateEventsWithCommentAndWithRatingFromTo(tracker.Id, userId, MinEventForCalculation,
                                                           now.AddMonths(-MonthsThreshold),
                                                           now.AddDays(-DaysSinceWorstEventThreshold));
            var eventsList        = events.ToList();
            var eventBefore3Month = CreateEventWithRatingWithCommentAndFixDate(tracker.Id, userId, MaxRatingValue,
                                                                               new Comment("Comment"), now.AddMonths(-MonthsThreshold).AddDays(-1));

            eventsList.Add(eventBefore3Month);
            var worstRatingEventInfo
                = events
                  .Where(@event => @event.CustomizationsParameters.Rating.IsSome)
                  .Select(x => new
            {
                Event  = x,
                Rating = x.CustomizationsParameters.Rating.ValueUnsafe()
            })
                  .OrderBy(x => x.Rating).First();
            var expectedDate     = worstRatingEventInfo.Event.HappensDate;
            var expectedRating   = worstRatingEventInfo.Rating;
            var expectedPriority = MaxRating - expectedRating;
            var expectedText     = worstRatingEventInfo.Event.CustomizationsParameters.Comment.ValueUnsafe().Text;

            _eventRepository.AddRangeOfEvents(eventsList);
            var allEvents = _eventRepository.LoadAllTrackerEvents(tracker.Id);

            //act
            var fact = new WorstRatingEventCalculator().Calculate(allEvents, tracker, _now)
                       .ConvertTo <WorstRatingEventFact>().ValueUnsafe();

            //arrange
            Assert.AreEqual("Худшее событие", fact.FactName);
            Assert.AreEqual($"Событие {tracker.Name} с самым низким рейтингом {expectedRating} " +
                            $"произошло {expectedDate:d} с комментарием {expectedText}", fact.Description);
            Assert.AreEqual(expectedPriority, fact.Priority);
            Assert.AreEqual(expectedRating, fact.WorstRating);
            Assert.AreEqual(expectedDate, fact.WorstEventDate);
            Assert.AreEqual(expectedText, fact.WorstEventComment.ValueUnsafe().Text);
        }