public void Add_ValidEvent_Inserts(string rawEvent)
        {
            var postcrossingEvent = EventBaseHelper.MapToEventBase(rawEvent);

            var result = _eventRepository.Add(postcrossingEvent);

            Check.That(result).Not.IsNull();
            Check.That(MemoryRepositoryService.GetRepository().Database.GetCollection(PostcrossingTrackerConstants.EventCollectionName).Count()).IsEqualTo(1);
        }
        public void MapToEventBase_UnknownEvent_ReturnsEventBase()
        {
            var rawEvent = @"Account closed for <a href=""/user/user"">user</a> from  <i title=""country"" class=""flag flag-XX""></i> <a href=""/country/XX"">country</a>";

            var result = EventBaseHelper.MapToEventBase(rawEvent);

            Check.That(result)
            .IsNotNull()
            .And.IsInstanceOf <EventBase>();
            Check.That(result.EventType).IsEqualTo(PostcrossingEventTypeEnum.Unknown);
        }
        private EventBase MapToEventBase(List <string> postcrossingEvent)
        {
            var @event = EventBaseHelper.MapToEventBase(postcrossingEvent[1]);

            if (@event != null)
            {
                @event.EventId = long.Parse(postcrossingEvent[0]);
            }

            return(@event);
        }
        public void Get_EventExists_ReturnsEvent()
        {
            var postcrossingEvent = EventBaseHelper.MapToEventBase(@"Account closed for <a href=""/user/user"">user</a> from  <i title=""country"" class=""flag flag-XX""></i> <a href=""/country/XX"">country</a>");

            postcrossingEvent.EventId = 999;

            _eventRepository.Add(postcrossingEvent);

            var result = _eventRepository.Get <EventBase>(postcrossingEvent.EventId);

            Check.That(result).IsNotNull();
        }
        public void MapToEventBase_SignUpEvent_ReturnsSignUp()
        {
            var userName = "******";
            var rawEvent = $@"<a href =""/user/user"">{userName}</a> from <i title=""country flag"" class=""flag flag-XX""></i> <a href=""/country/XX"">country</a> just signed up";

            var result = EventBaseHelper.MapToEventBase(rawEvent) as SignUp;

            Check.That(result)
            .IsNotNull()
            .And.IsInstanceOf <SignUp>();
            Check.That(result.EventType).IsEqualTo(PostcrossingEventTypeEnum.SignUp);
            Check.That(result.User.Name).IsEqualTo(userName);
        }
        public void MapToEventBase_UploadEvent_ReturnsUpload()
        {
            var userName   = "******";
            var postcardId = "postcard_id";
            var rawEvent   = $@"<a title=""country flag"" href=""/country/XX""><i class=""flag flag-XX""></i></a> <a href=""/user/user"">{userName}</a> uploaded postcard <a title=""country flag"" href=""/country/XX""><i class=""flag flag-XX""></i></a> <a href=""/postcards/{postcardId}"">card</a>";

            var result = EventBaseHelper.MapToEventBase(rawEvent) as Upload;

            Check.That(result)
            .IsNotNull()
            .And.IsInstanceOf <Upload>();
            Check.That(result.EventType).IsEqualTo(PostcrossingEventTypeEnum.Upload);
            Check.That(result.User.Name).IsEqualTo(userName);
            Check.That(result.Postcard.PostcardId).IsEqualTo(postcardId);
        }
        public void MapToEventBase_SendEvent_ReturnsSend()
        {
            var fromUser  = "******";
            var toCountry = "to_country";
            var rawEvent  = $@"<a title=""country flag"" href=""/country/XX""><i class=""flag flag-XX""></i></a> <a href=""/user/user"">{fromUser}</a> sent a postcard to <i title=""country flag"" class=""flag flag-XX""></i> <a href=""/country/XX"">{toCountry}</a>";

            var result = EventBaseHelper.MapToEventBase(rawEvent) as Send;

            Check.That(result)
            .IsNotNull()
            .And.IsInstanceOf <Send>();
            Check.That(result.EventType).IsEqualTo(PostcrossingEventTypeEnum.Send);
            Check.That(result.User.Name).IsEqualTo(fromUser);
            Check.That(result.ToCountry.Name).IsEqualTo(toCountry);
        }
        public void MapToEventBase_RegisterEvent_ReturnsRegister()
        {
            var toUser     = "******";
            var fromUser   = "******";
            var postcardId = "postcard_id";
            var rawEvent   = $@"<a title=""country flag"" href=""/country/XX""><i class=""flag flag-XX""></i></a> <a href=""/user/{toUser}"">{toUser}</a> received a <a href=""/postcards/{postcardId}"">postcard</a> from <a title=""country flag"" href=""/country/XX""><i class=""flag flag-XX""></i></a> <a href=""/user/{fromUser}"">{fromUser}</a>";

            var result = EventBaseHelper.MapToEventBase(rawEvent) as Register;

            Check.That(result)
            .IsNotNull()
            .And.IsInstanceOf <Register>();
            Check.That(result.EventType).IsEqualTo(PostcrossingEventTypeEnum.Register);
            Check.That(result.User.Name).IsEqualTo(toUser);
            Check.That(result.FromUser.Name).IsEqualTo(fromUser);
            Check.That(result.Postcard.PostcardId).IsEqualTo(postcardId);
        }
        public void FindEventsWithIdGreaterThan_()
        {
            var postcrossingEvent1 = EventBaseHelper.MapToEventBase(@"Account closed for <a href=""/user/user1"">user1</a> from  <i title=""country"" class=""flag flag-YY""></i> <a href=""/country/YY"">countryYY</a>");

            postcrossingEvent1.EventId = 998;
            var postcrossingEvent2 = EventBaseHelper.MapToEventBase(@"Account closed for <a href=""/user/user2"">user2</a> from  <i title=""country"" class=""flag flag-XX""></i> <a href=""/country/XX"">countryXX</a>");

            postcrossingEvent2.EventId = 999;

            _eventRepository.Add(postcrossingEvent1);
            _eventRepository.Add(postcrossingEvent2);

            var result = _eventRepository.FindEventsWithIdGreaterThan <EventBase>(postcrossingEvent1.EventId);

            Check.That(result).Not.IsEmpty();
            Check.That(result).CountIs(1);
            Check.That(result.First()).HasFieldsWithSameValues(postcrossingEvent2);
        }
        public void MapToEventBase_InvalidRawEvent_ReturnsNull(string rawEvent)
        {
            var result = EventBaseHelper.MapToEventBase(rawEvent);

            Check.That(result).IsNull();
        }