Ejemplo n.º 1
0
        public void TestInitialize()
        {
            _target = new MessageRepository();
              _target.FilePath = "data/initial_offers.json";
              _target.InitializeFromFile();

              Console.Out.WriteLine("Initialized from file with following data");
              Console.Out.WriteLine(JSON.Serialize(_target.AllMessages()));

              List<IMessage> messages = new List<IMessage>(_target.AllMessages());

              //Assert.AreEqual(9, messages.Count, "Expected 6 messages after initializing from " + _target.FilePath );
        }
Ejemplo n.º 2
0
 public void InitializeWithRecentOffers_BlowsUpWithWrongFile()
 {
     try
     {
         //Global.InitializeWithRecentOffers("data/typo_asdfuihsg.json"); // should be copied to bin/Debug output directory because of build action properties on that file
         _target = new MessageRepository();
         _target.FilePath = "data/typo_asdfuihsg.json";
         _target.InitializeFromFile();
         Assert.Fail("Expected to get an  exception from trying to trying to load bad file");
     }
     catch (IOException)
     {
         //expected
     }
     catch (Exception ex)
     {
         Assert.Fail("Expected to get an IOexception from trying to trying to load bad file, instead got:" + ex);
     }
 }
Ejemplo n.º 3
0
        public void TestVariableTypeSerialization()
        {
            MessageRepository messageRepository = new MessageRepository(); // need to keep this seperate so as not to mess up other tests
            TagRepository tempTagRepository = new TagRepository(); //ditto
            IMessageParser messageParser = new RegexMessageParser(_singletonTagProvider, new MockLocationProvider());
            IRawMessageReceiver messageReceiver = new IncomingMessageProcessor(messageRepository, tempTagRepository, messageParser);

            //add two messages of different types
            messageReceiver.Notify(DemoData.RawMessages[0]);
            messageReceiver.Notify(MockData.RawMessages[0]);
            var openSocialRawMessage = new OpenSocialRawMessage("ooooby", "i have vegetables available in wellington. for #free. #ooooby", "utunga", "", "");
            messageReceiver.Notify(openSocialRawMessage);

            //serialize out
            string tempFileName = "testOffers.json";
            messageRepository.FilePath = tempFileName;
            messageRepository.SerializeToFile();

            // ok great now check that we can deserialize
            messageRepository = new MessageRepository(); // need to keep this seperate so as not to mess up other tests
            messageRepository.FilePath = tempFileName;
            messageRepository.InitializeFromFile();

            Assert.AreEqual(messageRepository.MessageCount, 3, "expected to find 3 messages after deserialization");

            //TwitterStatusXml twitterStatus = new TwitterStatusXml();
            //twitterStatus.CreatedAt = DateUtils.TwitterTimeStampFromUTCDateTime(DateTime.Now);
            //twitterStatus. = DateUtils.TwitterTimeStampFromUTCDateTime(DateTime.Now);
        }