Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -10,4 +10,8 @@
global using NetDaemon.HassModel.Entities;
global using Microsoft.CodeAnalysis;
global using static NetDaemon.HassModel.CodeGenerator.Helpers.NamingHelper;
global using static NetDaemon.HassModel.CodeGenerator.Helpers.SyntaxFactoryHelper;
global using static NetDaemon.HassModel.CodeGenerator.Helpers.SyntaxFactoryHelper;

// This is needed to allow integration tests to run code generation and parsing without major refactoring
using System.Runtime.CompilerServices;
[assembly:InternalsVisibleTo("NetDaemon.Tests.Integration")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using NetDaemon.Client;
using NetDaemon.Client.HomeAssistant.Extensions;
using NetDaemon.HassModel.CodeGenerator.Model;
using NetDaemon.Tests.Integration.Helpers;
using Xunit;

namespace NetDaemon.Tests.Integration;

public class CodegenIntegrationTests : IClassFixture<MakeSureNetDaemonIsRunningFixture>
{
private readonly IHomeAssistantConnection _haConnection;

public CodegenIntegrationTests(
MakeSureNetDaemonIsRunningFixture _,
IHomeAssistantConnection haConnection
)
{
_haConnection = haConnection;
}

/// <summary>
/// Tests the code generator. We had som problems with websocket interface changing and this should at least allert us on changes when it reaches
/// beta stage
/// </summary>
[Fact]
public async Task Codegen_ShouldBeAbleToParseServiceDescriptions()
{
var element = await _haConnection.GetServicesAsync(new CancellationTokenSource(TimeSpan.FromSeconds(20)).Token).ConfigureAwait(false) ?? throw new InvalidOperationException("Failed to get services");
var serviceMetadata = ServiceMetaDataParser.Parse(element);
serviceMetadata.Count.Should().NotBe(0);

var lightDomain = serviceMetadata.FirstOrDefault(n => n.Domain == "switch") ?? throw new InvalidOperationException("Expected domain light to be present");

var turnOnService = lightDomain.Services.FirstOrDefault(n => n.Service == "turn_on") ?? throw new InvalidOperationException("Expected domain light to be present");

Assert.NotNull(turnOnService?.Target?.Entity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

<ItemGroup>
<ProjectReference Include="..\..\..\src\AppModel\NetDaemon.AppModel\NetDaemon.AppModel.csproj" />
<ProjectReference Include="..\..\..\src\HassModel\NetDaemon.HassModel.CodeGenerator\NetDaemon.HassModel.CodeGenerator.csproj" />
<ProjectReference Include="..\..\..\src\Runtime\NetDaemon.Runtime\NetDaemon.Runtime.csproj" />
</ItemGroup>

Expand Down