Skip to main content
Tweeted twitter.com/StackCodeReview/status/690419363170668545
Rollback to Revision 1
Source Link
t3chb0t
  • 44.3k
  • 9
  • 84
  • 190

Some of my tests require that I need to test the date time results (like time stamps etc.). In order to be able to test the date time string I created a simple DateTime abstraction that I'm going to use in other projects later. It should replace direct calls to DateTime.(Utc)Now. Or should I rather call it TestValue instead of ConstValue?

public abstract class DateTimeProvider
{
    public abstract DateTime Value { get; }

    public static implicit operator DateTime(DateTimeProvider dateTimeProvider)
  ? ConstValue {
    get; set; }  return dateTimeProvider.Value;
    }
}

public class NowDateTimeProvider : DateTimeProvider
{
  public static publicimplicit overrideoperator DateTime(DateTimeProvider ValuedateTimeProvider)
    {
        get { return DateTimedateTimeProvider.Now; }Value;
    }
}

public class UtcNowDateTimeProviderNowDateTimeProvider : DateTimeProvider
{
    public override DateTime Value
    {
        get { return ConstValue ?? DateTime.UtcNow;Now; }
    }
}

public class ConstDateTimeProviderUtcNowDateTimeProvider : DateTimeProvider
{
    private readonly DateTime _value;

    public ConstDateTimeProvider(override DateTime dateTime)Value
    {
        _valueget ={ dateTime;
return ConstValue ?? DateTime.UtcNow; }
 
    public override DateTime Value { get { return _value; } }
}

Some of my tests require that I need to test the date time results (like time stamps etc.). In order to be able to test the date time string I created a simple DateTime abstraction that I'm going to use in other projects later. It should replace direct calls to DateTime.(Utc)Now.

public abstract class DateTimeProvider
{
    public abstract DateTime Value { get; }

    public static implicit operator DateTime(DateTimeProvider dateTimeProvider)
    {
        return dateTimeProvider.Value;
    }
}

public class NowDateTimeProvider : DateTimeProvider
{
    public override DateTime Value
    {
        get { return DateTime.Now; }
    }
}

public class UtcNowDateTimeProvider : DateTimeProvider
{
    public override DateTime Value
    {
        get { return DateTime.UtcNow; }
    }
}

public class ConstDateTimeProvider : DateTimeProvider
{
    private readonly DateTime _value;

    public ConstDateTimeProvider(DateTime dateTime)
    {
        _value = dateTime;
    }
 
    public override DateTime Value { get { return _value; } }
}

Some of my tests require that I need to test the date time results (like time stamps etc.). In order to be able to test the date time string I created a simple DateTime abstraction that I'm going to use in other projects later. It should replace direct calls to DateTime.(Utc)Now. Or should I rather call it TestValue instead of ConstValue?

public abstract class DateTimeProvider
{
    public abstract DateTime Value { get; }

    public DateTime? ConstValue { get; set; }       

    public static implicit operator DateTime(DateTimeProvider dateTimeProvider)
    {
        return dateTimeProvider.Value;
    }
}

public class NowDateTimeProvider : DateTimeProvider
{
    public override DateTime Value
    {
        get { return ConstValue ?? DateTime.Now; }
    }
}

public class UtcNowDateTimeProvider : DateTimeProvider
{
    public override DateTime Value
    {
        get { return ConstValue ?? DateTime.UtcNow; }
    }
}
added 172 characters in body
Source Link
t3chb0t
  • 44.3k
  • 9
  • 84
  • 190

Some of my tests require that I need to test the date time results (like time stamps etc.). In order to be able to test the date time string I created a simple DateTime abstraction that I'm going to use in other projects later. It should replace direct calls to DateTime.(Utc)Now. Or should I rather call it TestValue instead of ConstValue?

public abstract class DateTimeProvider
{
    public abstract DateTime Value { get; }

    public static implicit operator DateTime?(DateTimeProvider ConstValuedateTimeProvider)
    { 
 get; set; }     return dateTimeProvider.Value;
    }
}

public class NowDateTimeProvider : publicDateTimeProvider
{
 static implicit operator public override DateTime(DateTimeProvider dateTimeProvider)Value
    {
        get { return dateTimeProviderDateTime.Value;Now; }
    }
}

public class NowDateTimeProviderUtcNowDateTimeProvider : DateTimeProvider
{
    public override DateTime Value
    {
        get { return ConstValue ?? DateTime.Now;UtcNow; }
    }
}

public class UtcNowDateTimeProviderConstDateTimeProvider : DateTimeProvider
{
    publicprivate overridereadonly DateTime Value_value;

    public ConstDateTimeProvider(DateTime dateTime)
    {
        get_value {= returndateTime;
 ConstValue ?? DateTime.UtcNow; } 

    public override DateTime Value { get { return _value; } }
}

Some of my tests require that I need to test the date time results (like time stamps etc.). In order to be able to test the date time string I created a simple DateTime abstraction that I'm going to use in other projects later. It should replace direct calls to DateTime.(Utc)Now. Or should I rather call it TestValue instead of ConstValue?

public abstract class DateTimeProvider
{
    public abstract DateTime Value { get; }

    public DateTime? ConstValue { get; set; }       

    public static implicit operator DateTime(DateTimeProvider dateTimeProvider)
    {
        return dateTimeProvider.Value;
    }
}

public class NowDateTimeProvider : DateTimeProvider
{
    public override DateTime Value
    {
        get { return ConstValue ?? DateTime.Now; }
    }
}

public class UtcNowDateTimeProvider : DateTimeProvider
{
    public override DateTime Value
    {
        get { return ConstValue ?? DateTime.UtcNow; }
    }
}

Some of my tests require that I need to test the date time results (like time stamps etc.). In order to be able to test the date time string I created a simple DateTime abstraction that I'm going to use in other projects later. It should replace direct calls to DateTime.(Utc)Now.

public abstract class DateTimeProvider
{
    public abstract DateTime Value { get; }

    public static implicit operator DateTime(DateTimeProvider dateTimeProvider)
    { 
        return dateTimeProvider.Value;
    }
}

public class NowDateTimeProvider : DateTimeProvider
{
    public override DateTime Value
    {
        get { return DateTime.Now; }
    }
}

public class UtcNowDateTimeProvider : DateTimeProvider
{
    public override DateTime Value
    {
        get { return DateTime.UtcNow; }
    }
}

public class ConstDateTimeProvider : DateTimeProvider
{
    private readonly DateTime _value;

    public ConstDateTimeProvider(DateTime dateTime)
    {
        _value = dateTime;
    } 

    public override DateTime Value { get { return _value; } }
}
Source Link
t3chb0t
  • 44.3k
  • 9
  • 84
  • 190

Simple DateTime abstraction

Some of my tests require that I need to test the date time results (like time stamps etc.). In order to be able to test the date time string I created a simple DateTime abstraction that I'm going to use in other projects later. It should replace direct calls to DateTime.(Utc)Now. Or should I rather call it TestValue instead of ConstValue?

public abstract class DateTimeProvider
{
    public abstract DateTime Value { get; }

    public DateTime? ConstValue { get; set; }       

    public static implicit operator DateTime(DateTimeProvider dateTimeProvider)
    {
        return dateTimeProvider.Value;
    }
}

public class NowDateTimeProvider : DateTimeProvider
{
    public override DateTime Value
    {
        get { return ConstValue ?? DateTime.Now; }
    }
}

public class UtcNowDateTimeProvider : DateTimeProvider
{
    public override DateTime Value
    {
        get { return ConstValue ?? DateTime.UtcNow; }
    }
}