Ejemplo n.º 1
0
        public void GetEventWhenUserAskNotHisOwnEvent_ThrowsException()
        {
            var eventOfAnotherUser = TestingMethods.CreateEvent(Guid.NewGuid(), Guid.NewGuid());

            _eventRepository.SaveEvent(eventOfAnotherUser);

            Assert.Throws <NoPermissionsForEventException>(() =>
                                                           _eventService.GetEvent(Guid.NewGuid(), eventOfAnotherUser.Id));
        }
Ejemplo n.º 2
0
        private List <Event> InitializeEvents()
        {
            var event1 = TestingMethods.CreateEvent(_tracker.Id, _tracker.CreatorId);
            var event2 = TestingMethods.CreateEvent(_tracker.Id, _tracker.CreatorId);

            return(new List <Event>()
            {
                event1, event2
            });
        }
Ejemplo n.º 3
0
 public void Init()
 {
     _trackerRepository = new TrackerRepository();
     _eventRepository   = new EventRepository();
     _eventService      =
         new EventService(_eventRepository, _trackerRepository,
                          EventFiltrationDapperRepository()); //TODO replace by in memory repository
     _tracker = TestingMethods.CreateTrackerWithDefaultCustomization(Guid.NewGuid());
     _event   = TestingMethods.CreateEvent(_tracker.Id, _tracker.CreatorId);
 }
Ejemplo n.º 4
0
        public void GetAllTrackerEventsGoodCase_ReturnsCollectionOfEvents()
        {
            _trackerRepository.SaveTracker(_tracker);
            var event2 = TestingMethods.CreateEvent(_tracker.Id, _tracker.CreatorId);

            _eventRepository.AddRangeOfEvents(new[] { _event, event2 });
            const int expected = 2;

            var events = _eventService.GetAllTrackerEvents(_tracker.CreatorId, _tracker.Id);

            Assert.AreEqual(expected, events.Count);
            Assert.AreEqual(_event.GetHashCode(), events.First().GetHashCode());
            Assert.AreEqual(event2.GetHashCode(), events.Last().GetHashCode());
        }
Ejemplo n.º 5
0
        public void GetFactsFromTrackerWithEvents_ReturnsFacts()
        {
            InitializeFactProviderWithCalculators();
            var       tracker  = TestingMethods.CreateTrackerWithDefaultCustomization(Guid.NewGuid());
            var       event1   = TestingMethods.CreateEvent(tracker.Id, tracker.CreatorId);
            var       event2   = TestingMethods.CreateEvent(tracker.Id, tracker.CreatorId);
            const int expected = 2;

            var facts = _factProvider
                        .GetFacts(new [] { new TrackerWithItsEvents(tracker, new [] { event1, event2 }) });
            var firstFact  = facts.First();
            var secondFact = facts.Last();

            Assert.AreEqual(expected, facts.Count);
            Assert.AreEqual("Самая насыщенная событиями неделя", firstFact.FactName);
            Assert.AreEqual("Самый насыщенный событиями день", secondFact.FactName);
        }
Ejemplo n.º 6
0
        EditEventWhenNewCustomizationDontMatchTrackerCustomizationAndCustomizationIsRequired_ThrowsException()
        {
            var tracker = TestingMethods.CreateTrackerWithRequiredCustomization(Guid.NewGuid(), "tracker",
                                                                                new TrackerCustomizationSettings(
                                                                                    true,
                                                                                    true,
                                                                                    Option <string> .Some("meter"),
                                                                                    true,
                                                                                    false,
                                                                                    true,
                                                                                    true));

            _trackerRepository.SaveTracker(tracker);
            var oldEvent = TestingMethods.CreateEvent(tracker.Id, tracker.CreatorId);

            _eventRepository.SaveEvent(oldEvent);

            Assert.Throws <InvalidEventForTrackerException>(() =>
                                                            _eventService.EditEvent(tracker.CreatorId, oldEvent.Id, DateTimeOffset.Now,
                                                                                    new EventCustomParameters()));
        }
Ejemplo n.º 7
0
        EditEventWhenNewCustomizationDontMatchTrackerCustomizationAndCustomizationNotRequired_EventInRepositoryUpdated()
        {
            var tracker = TestingMethods.CreateTrackerWithRequiredCustomization(Guid.NewGuid(), "tracker",
                                                                                new TrackerCustomizationSettings(
                                                                                    true,
                                                                                    true,
                                                                                    Option <string> .Some("meter"),
                                                                                    true,
                                                                                    false,
                                                                                    true,
                                                                                    false));

            _trackerRepository.SaveTracker(tracker);
            var oldEvent = TestingMethods.CreateEvent(tracker.Id, tracker.CreatorId);

            _eventRepository.SaveEvent(oldEvent);

            _eventService.EditEvent(tracker.CreatorId, oldEvent.Id, DateTimeOffset.Now,
                                    new EventCustomParameters());

            Assert.AreNotEqual(oldEvent.GetHashCode(),
                               _eventRepository.LoadEvent(oldEvent.Id).GetHashCode());
            Assert.True(tracker.IsUpdated);
        }