Пример #1
0
        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);
        }
Пример #2
0
        public void EditEvent(Guid actorId,
                              Guid eventId,
                              DateTimeOffset timeStamp,
                              EventCustomParameters customParameters)
        {
            if (!_eventRepository.IsContainEvent(eventId))
            {
                throw new EventNotFoundException(eventId);
            }

            var @event = _eventRepository.LoadEvent(eventId);

            if (actorId != @event.CreatorId)
            {
                throw new NoPermissionsForEventException(actorId, eventId);
            }

            var tracker      = _trackerRepository.LoadTracker(@event.TrackerId);
            var updatedEvent = new Event(eventId, @event.CreatorId, @event.TrackerId, timeStamp, customParameters);

            if (tracker.CustomizationSettings.IsCustomizationRequired &&
                !tracker.IsTrackerCustomizationAndEventCustomizationMatch(updatedEvent))
            {
                throw new InvalidEventForTrackerException(tracker.Id);
            }

            _eventRepository.UpdateEvent(updatedEvent);
            tracker.IsUpdated = true;
        }
Пример #3
0
        public Event Convert(EventDto source, Event destination, ResolutionContext context)
        {
            var scale   = source.Scale ?? Option <double> .None;
            var rating  = source.Rating ?? Option <double> .None;
            var comment = source.Comment.IsNull()
                ? Option <Comment> .None
                : Option <Comment> .Some(new Comment(source.Comment));

            Option <GeoTag> geoTag;

            if (source.LatitudeGeo.IsNull() || source.LongitudeGeo.IsNull())
            {
                geoTag = Option <GeoTag> .None;
            }
            else
            {
                geoTag = Option <GeoTag> .Some(new GeoTag(source.LatitudeGeo.Value, source.LongitudeGeo.Value)); //TODO  Possible 'System.InvalidOperationException'
            }

            var photo = source.Photo.Length != 0 ? Option <Photo> .Some(new Photo(source.Photo)) : Option <Photo> .None;

            var eventCustomParameters = new EventCustomParameters(photo, scale, rating, geoTag, comment);

            return(new Event(source.Id, source.CreatorId, source.TrackerId, source.HappensDate,
                             eventCustomParameters));
        }
Пример #4
0
        public Guid CreateEvent(Guid actorId, Guid trackerId, DateTimeOffset eventHappensDate,
                                EventCustomParameters customParameters)
        {
            if (!_trackerRepository.IsContainTracker(trackerId))
            {
                throw new TrackerNotFoundException(trackerId);
            }

            var tracker = _trackerRepository.LoadTracker(trackerId);

            if (tracker.CreatorId != actorId)
            {
                throw new NoPermissionsForTrackerException(actorId, trackerId);
            }

            var newEvent = new Event(Guid.NewGuid(), actorId, trackerId, eventHappensDate, customParameters);

            if (!tracker.IsTrackerCustomizationAndEventCustomizationMatch(newEvent))
            {
                throw new InvalidEventForTrackerException(trackerId);
            }

            _eventRepository.SaveEvent(newEvent);
            tracker.IsUpdated = true;
            return(newEvent.Id);
        }
Пример #5
0
        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);
        }