public void CreateEventWhenEventAndTrackerCustomizationEqualsAndCustomizationIsRequired_CreatesEvent()
        {
            var tracker = TestingMethods.CreateTrackerWithRequiredCustomization(Guid.NewGuid(), "tracker",
                                                                                new TrackerCustomizationSettings(
                                                                                    true,
                                                                                    true,
                                                                                    Option <string> .Some("meter"),
                                                                                    false,
                                                                                    true,
                                                                                    false,
                                                                                    true));

            _trackerRepository.SaveTracker(tracker);
            var newEventCustomization = new EventCustomParameters(
                Option <Photo> .Some(new Photo(photoBytes: new byte[5])),
                Option <double> .Some(1),
                Option <double> .None,
                Option <GeoTag> .Some(new GeoTag(10, 20)),
                Option <Comment> .None);

            var createdEventId = _eventService.CreateEvent(
                tracker.CreatorId,
                tracker.Id,
                DateTimeOffset.Now,
                newEventCustomization);

            Assert.True(_eventRepository.IsContainEvent(createdEventId));
            Assert.AreEqual(newEventCustomization.GetHashCode(),
                            _eventRepository.LoadEvent(createdEventId).CustomizationsParameters.GetHashCode());
            Assert.True(tracker.IsUpdated);
        }
 public EventTracker CreateTrackerWithRating()
 {
     return(TestingMethods.CreateTrackerWithRequiredCustomization(Guid.NewGuid(), "Tracker name",
                                                                  new TrackerCustomizationSettings(
                                                                      false,
                                                                      false,
                                                                      Option <string> .None,
                                                                      false,
                                                                      false,
                                                                      false,
                                                                      false)));
 }
        public void CreateEventWhenEventAndTrackerCustomizationDiffersAndCustomizationIsRequired_ThrowsException()
        {
            var tracker = TestingMethods.CreateTrackerWithRequiredCustomization(Guid.NewGuid(), "tracker",
                                                                                new TrackerCustomizationSettings(
                                                                                    true,
                                                                                    true,
                                                                                    Option <string> .Some("meter"),
                                                                                    true,
                                                                                    false,
                                                                                    true,
                                                                                    true));

            _trackerRepository.SaveTracker(tracker);

            Assert.Throws <InvalidEventForTrackerException>(() =>
                                                            _eventService.CreateEvent(tracker.CreatorId, tracker.Id, DateTimeOffset.Now,
                                                                                      new EventCustomParameters()));
        }
        public void CreateEventWhenEventAndTrackerCustomizationDiffersAndCustomizationIsNotRequired_CreatesEvent()
        {
            var tracker = TestingMethods.CreateTrackerWithRequiredCustomization(Guid.NewGuid(), "tracker",
                                                                                new TrackerCustomizationSettings(
                                                                                    true,
                                                                                    true,
                                                                                    Option <string> .Some("meter"),
                                                                                    true,
                                                                                    false,
                                                                                    true,
                                                                                    false));

            _trackerRepository.SaveTracker(tracker);

            var createdEventId = _eventService.CreateEvent(tracker.CreatorId, tracker.Id, DateTimeOffset.Now,
                                                           new EventCustomParameters());

            Assert.True(_eventRepository.IsContainEvent(createdEventId));
            Assert.True(tracker.IsUpdated);
        }
        EditEventWhenNewCustomizationMatchTrackerCustomizationAndCustomizationIsRequired_EventInRepositoryUpdated()
        {
            var tracker = TestingMethods.CreateTrackerWithRequiredCustomization(Guid.NewGuid(), "tracker",
                                                                                new TrackerCustomizationSettings(
                                                                                    true,
                                                                                    true,
                                                                                    Option <string> .Some("meter"),
                                                                                    false,
                                                                                    true,
                                                                                    false,
                                                                                    true));

            _trackerRepository.SaveTracker(tracker);
            var oldEvent = new Event(Guid.NewGuid(), tracker.CreatorId, tracker.Id, DateTimeOffset.Now,
                                     new EventCustomParameters(
                                         Option <Photo> .Some(new Photo(photoBytes: new byte[5])),
                                         Option <double> .Some(1),
                                         Option <double> .None,
                                         Option <GeoTag> .Some(new GeoTag(10, 20)),
                                         Option <Comment> .None));

            _eventRepository.SaveEvent(oldEvent);

            var updatedCustomizationParameters = new EventCustomParameters(
                Option <Photo> .Some(new Photo(photoBytes: new byte[7])),
                Option <double> .Some(15),
                Option <double> .None,
                Option <GeoTag> .Some(new GeoTag(30, 40)),
                Option <Comment> .None);

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

            Assert.AreEqual(updatedCustomizationParameters.GetHashCode(),
                            _eventRepository.LoadEvent(oldEvent.Id).CustomizationsParameters.GetHashCode());
            Assert.True(tracker.IsUpdated);
        }
        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);
        }