private IPublishTweetParameters GeneratePublishTweetParameter( bool canTweetBePublished, bool hasPlaceIdParameter, bool hasCoordinatesParameter) { var publishTweetParameters = A.Fake <IPublishTweetParameters>(); var text = TestHelper.GenerateString(); _expectedPlaceIdParameter = TestHelper.GenerateString(); _expectedCoordinatesParameter = A.Fake <ICoordinates>(); publishTweetParameters.CallsTo(x => x.Text).Returns(text); //tweet.CallsTo(x => x.Id).Returns(tweetId); if (hasPlaceIdParameter) { publishTweetParameters.CallsTo(x => x.PlaceId).Returns(_expectedPlaceIdParameter); } if (hasCoordinatesParameter) { _expectedCoordinatesParameter.CallsTo(x => x.Latitude).Returns(TestHelper.GenerateRandomInt()); _expectedCoordinatesParameter.CallsTo(x => x.Longitude).Returns(TestHelper.GenerateRandomInt()); publishTweetParameters.CallsTo(x => x.Coordinates).Returns(_expectedCoordinatesParameter); } else { publishTweetParameters.CallsTo(x => x.Coordinates).Returns(null); } _expectedTweetParameter = TestHelper.GenerateString(); _fakeTwitterStringFormatter.CallsTo(x => x.TwitterEncode(text)).Returns(_expectedTweetParameter); _fakeTweetQueryValidator.CallsTo(x => x.ThrowIfTweetCannotBePublished(publishTweetParameters)).Invokes(x => { if (!canTweetBePublished) { throw new ArgumentException(); } }); return(publishTweetParameters); }
private IPublishTweetParameters GeneratePublishTweetParameter( bool canTweetBePublished, bool hasPlaceIdParameter, bool hasCoordinatesParameter) { var publishTweetParameters = A.Fake<IPublishTweetParameters>(); var text = TestHelper.GenerateString(); _expectedPlaceIdParameter = TestHelper.GenerateString(); _expectedCoordinatesParameter = A.Fake<ICoordinates>(); publishTweetParameters.CallsTo(x => x.Text).Returns(text); publishTweetParameters.CallsTo(x => x.QuotedTweet).Returns(null); if (hasPlaceIdParameter) { publishTweetParameters.CallsTo(x => x.PlaceId).Returns(_expectedPlaceIdParameter); } if (hasCoordinatesParameter) { _expectedCoordinatesParameter.CallsTo(x => x.Latitude).Returns(TestHelper.GenerateRandomInt()); _expectedCoordinatesParameter.CallsTo(x => x.Longitude).Returns(TestHelper.GenerateRandomInt()); publishTweetParameters.CallsTo(x => x.Coordinates).Returns(_expectedCoordinatesParameter); } else { publishTweetParameters.CallsTo(x => x.Coordinates).Returns(null); } _expectedTweetParameter = TestHelper.GenerateString(); _fakeTwitterStringFormatter.CallsTo(x => x.TwitterEncode(text)).Returns(_expectedTweetParameter); _fakeTweetQueryValidator.CallsTo(x => x.ThrowIfTweetCannotBePublished(publishTweetParameters)).Invokes(x => { if (!canTweetBePublished) { throw new ArgumentException(); } }); return publishTweetParameters; }