TimeZonesTest.cs :  » Bloggers » dasBlog » newtelligence » DasBlog » RadioImport » Test » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » dasBlog 
dasBlog » newtelligence » DasBlog » RadioImport » Test » TimeZonesTest.cs
using System;
using System.Globalization;
using newtelligence.DasBlog.Util;
using NUnit.Framework;

namespace UnitTests.Subtext.Framework.Util{
  [TestFixture]
  public class TimeZonesTest
  {
    [Test]
    public void CanEnumerateTimezones()
    {
      Console.WriteLine(WindowsTimeZone.TimeZones.Count + " timezones.");
      Assert.IsTrue(WindowsTimeZone.TimeZones.Count > 10, "Expected more than ten.");
    }
    
    [Test]
    public void SimplePstConversionTest()
    {
      WindowsTimeZone pst = WindowsTimeZone.TimeZones.GetByZoneIndex(4); //PST
      Console.WriteLine(pst.ToLocalTime(DateTime.UtcNow));

      Console.WriteLine(TimeZone.CurrentTimeZone.ToLocalTime(DateTime.UtcNow));
    }
    
    [Test]
    public void ToLocalTimeReturnsProperTime()
    {
      IFormatProvider culture = new CultureInfo("en-US", true);
      DateTime utcDate = DateTime.Parse("12/30/2006 19:30", culture, DateTimeStyles.AllowWhiteSpaces);
      utcDate = utcDate.ToLocalTime().ToUniversalTime();
      Assert.AreEqual("12/30/2006 19:30", utcDate.ToString("MM/dd/yyyy HH:mm", culture), "An assumption about round tripping the UTC date was wrong.");

      WindowsTimeZone pst = WindowsTimeZone.TimeZones.GetByZoneIndex(4); //PST

      DateTime pstDate = pst.ToLocalTime(utcDate);

      string formattedPstDate = pstDate.ToString("MM/dd/yyyy HH:mm", culture);
      Assert.AreEqual("12/30/2006 11:30", formattedPstDate);
    }
    
    [Test]
    public void ToLocalTimeReturnsProperTimeDuringDaylightSavings()
    {
      IFormatProvider culture = new CultureInfo("en-US", true);
      DateTime utcDate = DateTime.Parse("10/01/2006 19:30", culture, DateTimeStyles.AllowWhiteSpaces);
      utcDate = utcDate.ToLocalTime().ToUniversalTime();
      Assert.AreEqual("10/01/2006 19:30", utcDate.ToString("MM/dd/yyyy HH:mm", culture), "An assumption about round tripping the UTC date was wrong.");
            
      WindowsTimeZone pst = WindowsTimeZone.TimeZones.GetByZoneIndex(4); //PST

      DateTime pstDate = pst.ToLocalTime(utcDate);
      
      string formattedPstDate = pstDate.ToString("MM/dd/yyyy HH:mm", culture);
      Assert.AreEqual("10/01/2006 12:30", formattedPstDate);
    }
    
    [Test]
    public void ToUniversalTimeReturnsProperTime()
    {
      IFormatProvider culture = new CultureInfo("en-US", true);
      DateTime localDate = DateTime.Parse("10/01/2006 12:30", culture, DateTimeStyles.AllowWhiteSpaces);
      
      WindowsTimeZone pst = WindowsTimeZone.TimeZones.GetByZoneIndex(4); //PST

      DateTime utcDate = pst.ToUniversalTime(localDate);
      
      string formattedPstDate = utcDate.ToString("MM/dd/yyyy HH:mm", culture);
      Assert.AreEqual("10/01/2006 19:30", formattedPstDate);
    }

    [Test]
    public void GetDaylightChangesReturnsProperDaylightSavingsInfo()
    {
      WindowsTimeZone pst = WindowsTimeZone.TimeZones.GetByZoneIndex(4); //PST
      DaylightTime daylightChanges = pst.GetDaylightChanges(2006);
      DateTime start = DateTime.Parse("4/2/2006 2:00:00 AM");
      DateTime end = DateTime.Parse("10/29/2006 2:00:00 AM");
      Assert.AreEqual(start, daylightChanges.Start);
      Assert.AreEqual(end, daylightChanges.End);
    }
    
    [Test]
    public void GetZoneByIndexReturnsProperPSTInfo()
    {
      WindowsTimeZone pst = WindowsTimeZone.TimeZones.GetByZoneIndex(4); //PST
      Assert.AreEqual("Pacific Daylight Time", pst.DaylightName);
      Assert.AreEqual("Pacific Daylight Time", pst.DaylightZoneName);
      Assert.AreEqual(new TimeSpan(1, 0, 0), pst.DaylightBias, "Expected a one hour bias");

    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.