Skip to content

Commit

Permalink
Merge branch 'release/0.73.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jericho committed Jan 20, 2024
2 parents 54f05c0 + ab203f2 commit 977c5e6
Show file tree
Hide file tree
Showing 17 changed files with 1,142 additions and 7 deletions.
156 changes: 156 additions & 0 deletions Source/ZoomNet.UnitTests/Extensions/InternalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,167 @@
using Xunit;
using ZoomNet.Models;
using ZoomNet.Utilities;
using static ZoomNet.Internal;

namespace ZoomNet.UnitTests.Extensions
{
public class InternalTests
{
public class FromUnixTime
{
// Note to self:
// I'm using TheoryData because can't use DateTime with InlineData:
// Error CS0182 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
public static TheoryData<long, DateTime> FromMilliseconds = new TheoryData<long, DateTime>()
{
{ 0, new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc) },
{ 1000, new DateTime(1970, 1, 1, 0, 0, 1, 0, DateTimeKind.Utc) },
{ 16040, new DateTime(1970, 1, 1, 0, 0, 16, 40, DateTimeKind.Utc) },
};

public static TheoryData<long, DateTime> FromSeconds = new TheoryData<long, DateTime>()
{
{ 0, new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc) },
{ 1000, new DateTime(1970, 1, 1, 0, 16, 40, 0, DateTimeKind.Utc) },
};

[Theory, MemberData(nameof(FromMilliseconds))]
public void Converts_from_milliseconds(long numberOfMilliseconds, DateTime expected)
{
// Act
var result = numberOfMilliseconds.FromUnixTime(UnixTimePrecision.Milliseconds);

// Assert
result.ShouldBe(expected);
}

[Theory, MemberData(nameof(FromSeconds))]
public void Converts_from_seconds(long numberOfSeconds, DateTime expected)
{
// Act
var result = numberOfSeconds.FromUnixTime(UnixTimePrecision.Seconds);

// Assert
result.ShouldBe(expected);
}

[Fact]
public void Throws_when_unknown_precision()
{
// Arrange
var unknownPrecision = (UnixTimePrecision)3;

// Act
Should.Throw<ArgumentException>(() => 123L.FromUnixTime(unknownPrecision));
}
}

public class ToUnixTime
{
// Note to self:
// I'm using TheoryData because can't use DateTime with InlineData:
// Error CS0182 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
public static TheoryData<DateTime, long> ToMilliseconds = new TheoryData<DateTime, long>()
{
{ new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), 0 },
{ new DateTime(1970, 1, 1, 0, 0, 1, 0, DateTimeKind.Utc), 1000 },
{ new DateTime(1970, 1, 1, 0, 0, 16, 40, DateTimeKind.Utc), 16040 },
};

public static TheoryData<DateTime, long> ToSeconds = new TheoryData<DateTime, long>()
{
{ new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), 0 },
{ new DateTime(1970, 1, 1, 0, 0, 1, 0, DateTimeKind.Utc), 1 },
{ new DateTime(1970, 1, 1, 0, 0, 16, 40, DateTimeKind.Utc), 16 },
};

[Theory, MemberData(nameof(ToMilliseconds))]
public void Converts_to_milliseconds(DateTime date, long expected)
{
// Act
var result = date.ToUnixTime(UnixTimePrecision.Milliseconds);

// Assert
result.ShouldBe(expected);
}

[Theory, MemberData(nameof(ToSeconds))]
public void Converts_to_seconds(DateTime date, long expected)
{
// Act
var result = date.ToUnixTime(UnixTimePrecision.Seconds);

// Assert
result.ShouldBe(expected);
}

[Fact]
public void Throws_when_unknown_precision()
{
// Arrange
var unknownPrecision = (UnixTimePrecision)3;

// Act
Should.Throw<ArgumentException>(() => DateTime.UtcNow.ToUnixTime(unknownPrecision));
}
}

public class ToZoomFormat
{
// Note to self:
// I'm using TheoryData because can't use DateTime with InlineData:
// Error CS0182 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
public static TheoryData<DateTime, string, string> SampleUtcDates = new TheoryData<DateTime, string, string>()
{
{ new DateTime(2023, 12, 12, 12, 14, 0, 0, DateTimeKind.Utc), "2023-12-12", "2023-12-12T12:14:00Z" },
};

[Theory, MemberData(nameof(SampleUtcDates))]
public void Successfully_converts_UTC_to_string(DateTime date, string expectedDateOnly, string expectedWithTime)
{
// Act
var resultDateOnly = date.ToZoomFormat(TimeZones.UTC, true);
var resultWithTime = date.ToZoomFormat(TimeZones.UTC, false);

// Assert
resultDateOnly.ShouldBe(expectedDateOnly);
resultWithTime.ShouldBe(expectedWithTime);
}

// Note to self:
// I'm using TheoryData because can't use DateTime with InlineData:
// Error CS0182 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
public static TheoryData<DateTime, string, string> SampleLocalDates = new TheoryData<DateTime, string, string>()
{
{ new DateTime(2023, 12, 12, 12, 14, 0, 0, DateTimeKind.Local), "2023-12-12", "2023-12-12T12:14:00" },
};

[Theory, MemberData(nameof(SampleLocalDates))]
public void Successfully_converts_Local_to_string(DateTime date, string expectedDateOnly, string expectedWithTime)
{
// Act
var resultDateOnly = date.ToZoomFormat(TimeZones.America_Montreal, true);
var resultWithTime = date.ToZoomFormat(TimeZones.America_Montreal, false);

// Assert
resultDateOnly.ShouldBe(expectedDateOnly);
resultWithTime.ShouldBe(expectedWithTime);
}

[Fact]
public void Returns_null_when_null()
{
// Arrange
var date = (DateTime?)null;

// Act
var result = date.ToZoomFormat();

// Assert
result.ShouldBeNull();
}
}

public class AsPaginatedResponse
{
[Fact]
Expand Down
Loading

0 comments on commit 977c5e6

Please sign in to comment.