BlogDataServiceTests.cs :  » Bloggers » dasBlog » newtelligence » DasBlog » Runtime » 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 » Runtime » Test » BlogDataServiceTests.cs
using System;
using System.Collections;
using System.IO;
using newtelligence.DasBlog.Runtime;
using NUnit.Framework;
using System.Collections.Generic;

namespace newtelligence.DasBlog.Runtime.Test{
  /// <summary>
  /// Summary description for EntryTests.
  /// </summary>
  [TestFixture]
  public class BlogDataServiceTests : TestBaseLocal
  {
    #region Tests
    DirectoryInfo createEntries;

    [SetUp]
    public void EntriesSetup()
    {
      createEntries = new DirectoryInfo(Path.Combine(this.testContent.FullName, "CreateEntries"));
      // delete old entries
      if (createEntries.Exists)
      {
        createEntries.Delete(true);
        createEntries.Create();
      }
      else
      {
        createEntries.Create();
      }
    }

    [Test]
    public void GetEntriesForDay()
    {
      IBlogDataService dataService = BlogDataServiceFactory.GetService(createEntries.FullName, null);
      // this will create an entry for each hour of the day in local time
      for (int i = 0; i < 24; i++)
      {
        Entry entry = TestEntry.CreateEntry(String.Format("Test Entry {0}", i), 5, 2);
        entry.CreatedUtc = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, i, 0, 0).ToUniversalTime();
        dataService.SaveEntry(entry, null);
      }

      EntryCollection entries = dataService.GetEntriesForDay(DateTime.Now, TimeZone.CurrentTimeZone, String.Empty, int.MaxValue, int.MaxValue, String.Empty);

      Assert.AreEqual(24, entries.Count);

      foreach (Entry entry in entries)
      {
        // this test will make sure that the entries are all in the right day
        Entry lookup = dataService.GetEntry(entry.EntryId);
        Assert.IsNotNull(lookup);
        Assert.AreEqual(0, lookup.CompareTo(entry));
        Assert.AreEqual(DateTime.Now.Date, entry.CreatedLocalTime.Date);
      }
    }

    [Test]
    public void GetEntry()
    {
      IBlogDataService dataService = BlogDataServiceFactory.GetService(createEntries.FullName, null);
      
      Entry entry = TestEntry.CreateEntry(String.Format("Test Entry"), 5, 2);
      dataService.SaveEntry(entry, null);
    
      DateTime dt = DateTime.Now;
      Entry returnEntry = dataService.GetEntry(entry.EntryId);
      TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - dt.Ticks);
      Console.WriteLine(ts.Milliseconds);
      Assert.AreEqual(0, entry.CompareTo(returnEntry));
    }

//    [Test]
//    public void GetEntryTitle()
//    {
//      IBlogDataService dataService = BlogDataServiceFactory.GetService(createEntries.FullName, null);
//      
//      Entry entry = TestEntry.CreateEntry(String.Format("Test Entry"), 5, 2);
//      dataService.SaveEntry(entry, null);
//    
//      DateTime dt = DateTime.Now;
//      string title = dataService.GetEntryTitle(entry.EntryId);
//      TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - dt.Ticks);
//      Console.WriteLine(ts.Milliseconds);
//      Assert.AreEqual(entry.Title, title);
//    }

    // Ignoring this test: The comment mentions something about hours, but the test increments days.
    // Also, the logic seems messed up if the current day of the month is less than 12 days from the end of the month.
        [Test, Ignore("Test does not make sense.")]
        public void GetDaysWithEntries()
        {
            List<int> dayNumbers = new List<int>();
            IBlogDataService dataService = BlogDataServiceFactory.GetService(createEntries.FullName, null);
            // this will create an entry for each hour of the day in local time
            for (int i = 0; i < 24; i++)
            {
                Entry entry = TestEntry.CreateEntry(String.Format("Test Entry {0}", i), 5, 2);
                entry.CreatedUtc = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.AddDays(i).Day, 1, 0, 0).ToUniversalTime();
                dayNumbers.Add(DateTime.Now.AddDays(i).Day);
                i++;
                dataService.SaveEntry(entry, null);
            }
            
            DateTime[] days = dataService.GetDaysWithEntries(TimeZone.CurrentTimeZone);
            
            for (int i = 0; i < 12; i++)
            {
                int num = (int)dayNumbers[11 - i];
                Assert.AreEqual(num, days[i].Day);
                i++;
            }
        }
    
    [TearDown]
    public void EntriesDelete()
    {
      // delete old entries
      if (createEntries.Exists)
      {
        createEntries.Delete(true);
      }
    }
    #endregion Tests
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.