You're right.  I did that test after I posted this and discovered they
didn't equal.  I also found this bug report with timezoneinfo:

http://connect.microsoft.com/VisualStudio/feedback/details/516441/timezoneinfo-does-not-properly-implement-equality

Thanks!
Ryan

On Apr 18, 7:08 am, Patrick Steele <[email protected]> wrote:
> I think you're correct in assuming the TimeZoneInfo equality checks.
> I just did a quick test of this:
>
> [TestMethod]
> public void Check()
> {
>         var tzi1 = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard 
> Time");
>         var tzi2 = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard 
> Time");
>
>         Assert.AreSame(tzi1, tzi2);
>
> }
>
> And the test failed.  So FindSystemTimeZoneById is returning a new
> object even if it represents the same timezone.  You may have to write
> a wrapper for TimeZoneInfo that overrides Equals and do your own
> equality comparison.
>
> ---
> Patrick Steelehttp://weblogs.asp.net/psteele
>
>
>
>
>
> On Sun, Apr 18, 2010 at 12:46 AM, Ryan W <[email protected]> wrote:
> > I'm having a hard time getting expectations to work for TimeZoneInfo,
> > and was hoping someone could take a look and verify I'm doing this
> > correctly?  Here's some sample code:
>
> > public interface IServiceThatUsesTimeZoneInfo
> > {
> >    string MethodWithTimeZoneInfoParameter(TimeZoneInfo tzInfo);
> > }
>
> > public class CodeUnderTest
> > {
> >    IServiceThatUsesTimeZoneInfo _service;
>
> >    public CodeUnderTest(IServiceThatUsesTimeZoneInfo service)
> >    {
> >        _service = service;
> >    }
>
> >    public string MethodToTest()
> >    {
> >        return
> > _service.MethodWithTimeZoneInfoParameter(TimeZoneInfo.FindSystemTimeZoneByI 
> > d("Pacific
> > Standard Time"));
> >    }
> > }
>
> > [TestFixture]
> > public class TimeZoneInfoTest
> > {
> >    [Test]
> >    public void TestTimeZoneInfoMock()
> >    {
> >        RhinoMocks.Logger = new
> > TextWriterExpectationLogger(Console.Out);
> >        IServiceThatUsesTimeZoneInfo fakeService =
> > MockRepository.GenerateMock<IServiceThatUsesTimeZoneInfo>();
> >        fakeService.Expect(service =>
> > service.MethodWithTimeZoneInfoParameter(TimeZoneInfo.FindSystemTimeZoneById 
> > ("Pacific
> > Standard Time"))).Return("hello world");
> >        //fakeService.Expect(service =>
> > service.MethodWithTimeZoneInfoParameter(TimeZoneInfo.FindSystemTimeZoneById 
> > ("Pacific
> > Standard Time"))).IgnoreArguments().Return("hello world");
> >        CodeUnderTest c = new CodeUnderTest(fakeService);
> >        string s = c.MethodToTest();
> >        Assert.AreEqual("hello world", s);
> >        fakeService.VerifyAllExpectations();
> >    }
> > }
>
> > This test fails, unless I add the IgnoreArguments.  But you'll see
> > with the Expectation Logger that they appear to be equal instances of
> > TimeZoneInfo.  Perhaps this is a problem with TimeZoneInfo, and doing
> > equality checks with them?  How can I get to TimeZoneInfo instances to
> > match up with Rhino Mocks expectations?
>
> > Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Rhino.Mocks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group 
> athttp://groups.google.com/group/rhinomocks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rhinomocks?hl=en.

Reply via email to