Skip to content

Commit

Permalink
tiny tweaks. added a test - which fails - to test for serializatoin o…
Browse files Browse the repository at this point in the history
…f wanted/offer messages
  • Loading branch information
utunga committed Jan 31, 2010
1 parent c6eed22 commit 3e8f368
Show file tree
Hide file tree
Showing 31 changed files with 2,902 additions and 2,967 deletions.
66 changes: 35 additions & 31 deletions Offr.Tests/MockLocationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -975,45 +975,49 @@ public class MockLocationProvider:GoogleLocationProvider
public MockLocationProvider()
{
dummyResultSetMap=new Dictionary<string, GoogleResultSet>();
dummyResultSetMap.Add("1600 Amphitheatre Parkway, Mountain View, CA",deserialize(cali));
dummyResultSetMap.Add("20 Lambton Quay", deserialize(lambton));
dummyResultSetMap.Add("20 Pitt Street,Sydney", deserialize(sydney));
dummyResultSetMap.Add("30 Borough Rd, London", deserialize(london));
dummyResultSetMap.Add("30 Fitzroy Street, New Plymouth", deserialize(fitzroy));
dummyResultSetMap.Add("30+Rue+Baudin,+Paris,+France",deserialize(france));
dummyResultSetMap.Add("Sheikh+Zayed+Road,+Dubai,+UAE",deserialize(dubai));
dummyResultSetMap.Add("30 Borough Rd",deserialize(borough));
dummyResultSetMap.Add("Paekakariki", deserialize(pae));
dummyResultSetMap.Add("Wellington City", deserialize(welCity));
dummyResultSetMap.Add("Waiheke Island", deserialize(waiheke));

dummyResultSetMap.Add("1600 Amphitheatre Parkway, Mountain View, CA",Deserialize(cali));
dummyResultSetMap.Add("20 Lambton Quay", Deserialize(lambton));
dummyResultSetMap.Add("20 Pitt Street,Sydney", Deserialize(sydney));
dummyResultSetMap.Add("30 Borough Rd, London", Deserialize(london));
dummyResultSetMap.Add("30 Fitzroy Street, New Plymouth", Deserialize(fitzroy));
dummyResultSetMap.Add("30+Rue+Baudin,+Paris,+France",Deserialize(france));
dummyResultSetMap.Add("Sheikh+Zayed+Road,+Dubai,+UAE",Deserialize(dubai));
dummyResultSetMap.Add("30 Borough Rd",Deserialize(borough));
dummyResultSetMap.Add("Paekakariki", Deserialize(pae));
dummyResultSetMap.Add("Wellington City", Deserialize(welCity));
dummyResultSetMap.Add("Waiheke Island", Deserialize(waiheke));
dummyResultSetMap.Add("Cardboard box in town", Deserialize(london));
}
private GoogleResultSet deserialize(string data)

private GoogleResultSet Deserialize(string data)
{
return JSON.Deserialize<GoogleResultSet>(data);

}

public override ILocation Parse(string addressText)
{
return Parse(addressText, null);
}
{
return Parse(addressText, null);
}

public override ILocation Parse(string addressText, string scopeLocation)
{
ILocation previouslyFound = LocationRepository.Get(addressText);
if (previouslyFound != null) return previouslyFound;
GoogleResultSet resultSet=null;
try
{
resultSet = dummyResultSetMap[addressText];
}
catch (KeyNotFoundException)
{
resultSet = GetResultSet(addressText);
Console.WriteLine("Mock location provider had to request address from Google for: \n" + addressText + "\n should've been found in hard coded location lookups to point to:" + resultSet);
{
ILocation previouslyFound = LocationRepository.Get(addressText);
if (previouslyFound != null) return previouslyFound;
GoogleResultSet resultSet = null;
try
{
resultSet = dummyResultSetMap[addressText];
}
catch (KeyNotFoundException)
{
resultSet = GetResultSet(addressText);
Console.WriteLine("Mock location provider had to request address from Google for: \n" + addressText +
"\n should've been found in hard coded location lookups to point to:" + resultSet.ToString());

}
return GetNewLocation(addressText, scopeLocation, resultSet);
}

}
return GetNewLocation(addressText, scopeLocation, resultSet);
}
}
}
2 changes: 1 addition & 1 deletion Offr.Tests/MockMessageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public IMessage Parse(IRawMessage source)
msg.Location = mockRaw.Location;
msg.MoreInfoURL = mockRaw.MoreInfoURL;
msg.CreatedBy = mockRaw.CreatedBy;
msg.OfferText = mockRaw.OfferText;
msg.MessageText = mockRaw.OfferText;
if (mockRaw.EndBy.HasValue)
{
msg.SetEndBy(mockRaw.EndByText, mockRaw.EndBy.Value);
Expand Down
6 changes: 3 additions & 3 deletions Offr.Tests/TestMessageExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand Down Expand Up @@ -254,7 +254,7 @@ public void TestMessageExpiry()
message.Timestamp = DateTime.MinValue;
message.MessagePointer = new OpenSocialMessagePointer("ooooby");
message.RawText = "";
message.OfferText = "";
message.MessageText = "";
message.MoreInfoURL = "";
message.SetEndBy("",DateTime.Now.AddMonths(-1));
message.AddTag(tag);
Expand All @@ -267,7 +267,7 @@ public void TestMessageExpiry()
message2.Timestamp = DateTime.MinValue;
message2.MessagePointer = new OpenSocialMessagePointer("ooooby2");
message2.RawText = "";
message2.OfferText = "";
message2.MessageText = "";
message2.MoreInfoURL = "";
message2.SetEndBy("", DateTime.Now.AddMonths(3));
message2.AddTag(tag);
Expand Down
44 changes: 25 additions & 19 deletions Offr.Tests/TestRegexParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void TestRegexMethodSimpleTest()
Assert.That(expectedTags.Contains(tag), "Messages contains unexpected tag" + tag.MatchTag);
}

Assert.AreEqual(raw.Text, message.OfferText,
Assert.AreEqual(raw.Text, message.MessageText,
"Expect extracted message to work for " + raw);
}

Expand Down Expand Up @@ -118,28 +118,34 @@ public void TestGetMoreInfoUrl()
[Test]
public void TestMessageType()
{
// a specific real example for which i know the query was failing
RegexMessageParser regexMessageParser = new RegexMessageParser(null, null);
MockRawMessage raw = new MockRawMessage(0)
{
Timestamp = DateTime.Now.AddHours(-5),
CreatedBy = MockData.User0,
Location = MockData.Location0,
MoreInfoURL = "http://bit.ly/message0Info",
Text = "WANTED #ooooby mulch available now in l:Cardboard box in town: for #free http://bit.ly/message0Info #mulch",
EndByText = null,
EndBy = null
};
//List<ITag> expectedTags = new List<ITag>();
{
Timestamp = DateTime.Now.AddHours(-5),
CreatedBy = MockData.User0,
Location = MockData.Location0,
MoreInfoURL = "http://bit.ly/message0Info",
Text = "WANTED #ooooby mulch available now in l:Cardboard box in town: for #free http://bit.ly/message0Info #mulch",
EndByText = null,
EndBy = null
};

IMessage message = _target.Parse(raw);

Type type = typeof(WantedMessage);
Assert.That(message.GetType() == type);
raw.Text = "#ooooby #wanted mulch available now in l:Cardboard box in town: for #free http://bit.ly/message0Info #mulch";
Assert.That(message.GetType() == typeof(WantedMessage), "expected to receive message of type 'WantedMessage'");

raw.Text = "#ooooby #wanted mulch in l:Cardboard box in town: for #free http://bit.ly/message0Info #mulch";
message = _target.Parse(raw);
Assert.That(message.GetType() == typeof(WantedMessage), "expected to receive message of type 'WantedMessage'");

raw.Text = "#offer mulch available now in l:Cardboard box in town: for #free http://bit.ly/message0Info #mulch #ooooby";
message = _target.Parse(raw);
type = typeof(WantedMessage);
Assert.That(message.GetType() == type);
Assert.That(message.GetType() == typeof(OfferMessage), "expected to receive message of type 'OfferMessage'");

raw.Text = "OFFER: mulch available now in l:Cardboard box in town: for #free http://bit.ly/message0Info #mulch #ooooby";
message = _target.Parse(raw);
Assert.That(message.GetType() == typeof(OfferMessage), "expected to receive message of type 'OfferMessage'");
}


[Test]
public void TestGetImageUrl()
{
Expand Down
28 changes: 27 additions & 1 deletion Offr.Tests/TestSerialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,32 @@ public void TwitterMessagePointerRoundTrip()
Assert.AreEqual(orig, deserialized, "Round trip serialization for Raw Message false");
}

[Test]
public void TestMessageTypesRoundTrip()
{
WantedMessage wantedMessage = new WantedMessage();
wantedMessage.AddTag(new Tag(TagType.group, "ooooby"));
wantedMessage.AddTag(new Tag(TagType.loc, "wellington"));
wantedMessage.RawText = "WANTED mulch in l:Cardboard box in town: for #free http://bit.ly/message0Info #mulch #ooooby";
wantedMessage.MessageText = "mulch in l:Cardboard box in town: for #free";

string serialized = JSON.Serialize(wantedMessage);
WantedMessage deserializedWanted = JSON.Deserialize<WantedMessage>(serialized);
Assert.AreEqual(wantedMessage, deserializedWanted, "Expected to deserialize to the same object");

OfferMessage offerMessage = new OfferMessage();
offerMessage.AddTag(new Tag(TagType.group, "ooooby"));
offerMessage.AddTag(new Tag(TagType.loc, "wellington"));
offerMessage.RawText = "OFFER mulch available now in l:Cardboard box in town: for #free http://bit.ly/message0Info #mulch #ooooby";
offerMessage.MessageText = "mulch available now in l:Cardboard box in town: for #free";


serialized = JSON.Serialize(offerMessage);
OfferMessage deserializedOffer = JSON.Deserialize<OfferMessage>(serialized);
Assert.AreEqual(offerMessage, deserializedOffer, "Expected to deserialize to the same object");

}

[Test]
public void TestTagListRoundTrip()
{
Expand Down Expand Up @@ -190,7 +216,7 @@ private void AssertMessagesAreTheSame(List<OfferMessage> expectedList, List<Offe
OfferMessage expected = expectedList[i];
OfferMessage actual = actualList[i];
Assert.AreEqual(expected.Location, actual.Location, "Location was not the same");
Assert.AreEqual(expected.OfferText, actual.OfferText, "Offer text was not the same");
Assert.AreEqual(expected.MessageText, actual.MessageText, "Offer text was not the same");
Assert.AreEqual(expected.MoreInfoURL, actual.MoreInfoURL, "MoreInfoURL was not the same");
Assert.AreEqual(expected.LocationTags, actual.LocationTags, "LocationTags not the same");
//Assert.AreEqual(expected.OfferedBy,actual.OfferedBy,"OfferedBy not the same");
Expand Down
53 changes: 0 additions & 53 deletions Offr.Tests/data/initial_tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,57 +51,4 @@
"tag": "wanted",
"type": "msg_type"
}
}{
"barter": {
"tag": "barter",
"type": "type"
},
"cash": {
"tag": "cash",
"type": "type"
},
"cash_only": {
"tag": "cash_only",
"type": "type"
},
"etc": {
"tag": "etc",
"type": "msg_type"
},
"free": {
"tag": "free",
"type": "type"
},
"freecycle": {
"tag": "freecycle",
"type": "group"
},
"nzd": {
"tag": "nzd",
"type": "type"
},
"offer": {
"tag": "offer",
"type": "msg_type"
},
"ooooby": {
"tag": "ooooby",
"type": "group"
},
"recipient_feedback": {
"tag": "recipient_feedback",
"type": "msg_type"
},
"supplier_feedback": {
"tag": "supplier_feedback",
"type": "msg_type"
},
"takedown": {
"tag": "takedown",
"type": "msg_type"
},
"wanted": {
"tag": "wanted",
"type": "msg_type"
}
}
Binary file modified OffrConsole/bin/Debug/Newtonsoft.Json.dll
Binary file not shown.
Binary file modified OffrConsole/bin/Debug/Newtonsoft.Json.pdb
Binary file not shown.
Loading

0 comments on commit 3e8f368

Please sign in to comment.