Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ public void can_bind_datetime_with_custom_format()
binding.Value.As<string>().Should().Be(currentTime.AddDays(1.0).ToString("dd-MM-yyyy").ToString());
}

[Fact]
public void can_bind_datetime_uses_utcnow()
{
using var _ = new AssertionScope();

var expression = "$datetime 'Tzz'";
var code = $@"@var = {{{{{expression}}}}}";

var result = HttpRequestParser.Parse(code);
var currentTime = DateTimeOffset.UtcNow;
var node = result.SyntaxTree.RootNode.DescendantNodesAndTokens().OfType<HttpExpressionNode>().Single();

// Since we want to make sure that the provided expression is evaluated
// and .Now or .UtcNow is used as appropriate, we do not pass our own offset, like we do with other unit tests.
// we can do this since we are passing a custom format which only includes the time zone.
var binding = DynamicExpressionUtilities.ResolveExpressionBinding(node, expression);
binding.Value.As<string>().Should().Be(currentTime.ToString("Tzz").ToString());
}

[Fact]
public void can_bind_datetime_with_iso8601_format()
{
Expand Down Expand Up @@ -110,6 +129,25 @@ public void can_bind_local_datetime_with_custom_format()
binding.Value.As<string>().Should().Be(currentTime.AddDays(1.0).ToString("dd-MM-yyyy").ToString());
}

[Fact]
public void can_bind_local_datetime_uses_now()
{
using var _ = new AssertionScope();

var expression = "$localDatetime 'Tzz'";
var code = $@"@var = {{{{{expression}}}}}";

var result = HttpRequestParser.Parse(code);
var currentTime = DateTimeOffset.Now;
var node = result.SyntaxTree.RootNode.DescendantNodesAndTokens().OfType<HttpExpressionNode>().Single();

// Since we want to make sure that the provided expression is evaluated
// and .Now or .UtcNow is used as appropriate, we do not pass our own offset, like we do with other unit tests.
// we can do this since we are passing a custom format which only includes the time zone.
var binding = DynamicExpressionUtilities.ResolveExpressionBinding(node, expression);
binding.Value.As<string>().Should().Be(currentTime.ToString("Tzz").ToString());
}

[Fact]
public void can_bind_local_datetime_with_iso8601_format()
{
Expand Down