Skip to content

Commit

Permalink
fixed tests NextDateTimeTests
Browse files Browse the repository at this point in the history
  • Loading branch information
georgimanov committed Oct 29, 2016
1 parent 141e08f commit 4f67d09
Showing 1 changed file with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,60 +1,56 @@
namespace MoreDotNet.Tests.Extensions.Common.RandomExtensions
{
using System;
using System.Collections.Generic;
using System.Linq;

using MoreDotNet.Extensions.Common;

using Xunit;

public class NextDateTime
{
private const int Counter = 1000;
private DateTime minDate = new DateTime(1999, 10, 31);
private DateTime maxDate = new DateTime(1999, 10, 31);

[Fact]
public void NextDateTime_ShouldThrow_ArgumentNullException()
public void NextDateTime_RandomIsNull_ShouldThrow_ArgumentNullException()
{
Random random = null;

Assert.Throws<ArgumentNullException>(() => random.NextDateTime());
}

// TODO: minValue => null / maxValue => null ;

[Fact]
public void NextDateTime_ShouldReturnDateTime()
public void NextDateTime_MinValueIsGreaterThanMaxValue_ShouldThrow_ArgumentException()
{
var random = new Random();
var result = random.NextDateTime();
Random random = new Random();

Assert.IsType<DateTime>(result);
Assert.Throws<ArgumentException>(() => random.NextDateTime(this.maxDate, this.minDate));
}

[Fact]
public void NextDateTime_ShouldReturnDateTime_OneHundredDistinctValues()
public void NextDateTime_ShouldReturnDateTime_99PercentOfTimes()
{
// TODO: Fix test
var random = new Random();
var dates = new DateTime[Counter];
var dates = new HashSet<DateTime>();
for (int i = 0; i < Counter; i++)
{
dates[i] = random.NextDateTime();
dates.Add(random.NextDateTime());
}

Assert.Equal(Counter, dates.Distinct().Count());
Assert.True(dates.Count() >= (Counter * 99 / 100));
}

[Fact]
public void NextDateTime_ShouldReturnDateTime_BetweenMinAndMaxValue()
{
var random = new Random();
var mivValue = new DateTime(2016, 1, 1, 0, 0, 0);
var maxValue = new DateTime(2018, 1, 1, 0, 0, 0);
for (int i = 0; i < Counter; i++)
{
var result = random.NextDateTime(mivValue, maxValue);
var result = random.NextDateTime(this.minDate, this.maxDate);

Assert.True(result >= mivValue && result < maxValue);
Assert.True(result >= this.minDate && result < this.maxDate);
}
}
}
Expand Down

0 comments on commit 4f67d09

Please # to comment.