Skip to content
Open
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
@@ -0,0 +1,71 @@
using Autofac;
using BrickController2.DeviceManagement;
using BrickController2.DeviceManagement.CaDA;
using BrickController2.DeviceManagement.DI;
using BrickController2.PlatformServices.BluetoothLE;
using FluentAssertions;
using Moq;
using System;
using Xunit;
using CaDAVendor = BrickController2.DeviceManagement.CaDA.CaDA;

namespace BrickController2.Tests.DeviceManagement.DI;

public class CaDAVendorTests : VendorTestsBase
{
private readonly DeviceFactory _deviceFactory;

public CaDAVendorTests()
{
// Act
var container = InitializeContainer().Build();

_deviceFactory = container.Resolve<DeviceFactory>();
}

protected override ContainerBuilder InitializeContainer()
{
var builder = base.InitializeContainer();

// Arrange
builder.RegisterInstance(Mock.Of<IBluetoothLEService>());
builder.RegisterInstance(Mock.Of<ICaDAPlatformService>());

// additional dependencies
builder.RegisterInstance(Random.Shared); // MessageEncoderFactory needs Random.Shared as DI

// execute registration of vendor CaDA
builder.RegisterModule<CaDAVendor>();

return builder;
}

[Theory]
[InlineData("Device", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 })] // devicedata.Length of 18
[InlineData("Device_Rev2", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 })] // devicedata.Length of 16
public void RegisterDevice_CaDARaceCar_ReturnedDevice(string address, byte[] deviceData)
{
DeviceType deviceType = DeviceType.CaDA_RaceCar;
string name = "TestDevice";

var device = _deviceFactory(deviceType, name, address, deviceData, []);

device.Should().NotBeNull();
device.Should().BeOfType<CaDARaceCar>();
}

[Theory]
[InlineData("IllegalDevice", new byte[] { 1, 2, 3, 4 })] // MessageEncoderFactory.Create needs devicedata.Length of 16 or 18
public void RegisterDevice_CaDARaceCar_IllegalDeviceDataSize(string address, byte[] deviceData)
{
DeviceType deviceType = DeviceType.CaDA_RaceCar;
string name = "TestDevice";

Action act = () => _deviceFactory(deviceType, name, address, deviceData, []);

act.Should().Throw<Autofac.Core.DependencyResolutionException>()
.WithInnerException<Autofac.Core.DependencyResolutionException>()
.WithInnerException<InvalidOperationException>()
.Which.Message.Should().Be("Unsupported device data format.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using Autofac;
using BrickController2.DeviceManagement;
using BrickController2.DeviceManagement.DI;
using BrickController2.DeviceManagement.JieStar;
using BrickController2.PlatformServices.BluetoothLE;
using FluentAssertions;
using Moq;
using System;
using Xunit;
using JieStarVendor = BrickController2.DeviceManagement.JieStar.JieStar;

namespace BrickController2.Tests.DeviceManagement.DI;

public class JieStarVendorTests : VendorTestsBase
{
private readonly DeviceFactory _deviceFactory;

public JieStarVendorTests()
{
// Act
var container = InitializeContainer().Build();

_deviceFactory = container.Resolve<DeviceFactory>();
}

protected override ContainerBuilder InitializeContainer()
{
var builder = base.InitializeContainer();

// Arrange
builder.RegisterInstance(Mock.Of<IBluetoothLEService>());
builder.RegisterInstance(Mock.Of<IJieStarPlatformService>());

// execute registration of vendor JIESTAR
builder.RegisterModule<JieStarVendor>();

return builder;
}

[Theory]
[InlineData("Device1")]
[InlineData("Device2")]
[InlineData("Device3")]
public void RegisterDevice_JieStar_SCM4_ReturnedDevice(string address)
{
DeviceType deviceType = DeviceType.JieStarSCM4;
string name = "TestDevice";
byte[] deviceData = [1, 2, 3];

var device = _deviceFactory(deviceType, name, address, deviceData, []);

device.Should().NotBeNull();
device.Should().BeOfType<JieStarSCM4>();
}

[Theory]
[InlineData("Device")]
[InlineData("IllegalDevice")]
public void RegisterDevice_JieStar_SCM4_IllegalDevice(string address)
{
DeviceType deviceType = DeviceType.JieStarSCM4;
string name = "TestDevice";
byte[] deviceData = [1, 2, 3];

Action act = () => _deviceFactory(deviceType, name, address, deviceData, []);

act.Should().Throw<Autofac.Core.DependencyResolutionException>()
.WithInnerException<Autofac.Core.DependencyResolutionException>()
.WithInnerException<ArgumentException>()
.Which.ParamName.Should().Be(nameof(address));
}

[Theory]
[InlineData("Device1")]
[InlineData("Device2")]
[InlineData("Device3")]
public void RegisterDevice_JieStar_SCM8_ReturnedDevice(string address)
{
DeviceType deviceType = DeviceType.JieStarSCM8;
string name = "TestDevice";
byte[] deviceData = [1, 2, 3];

var device = _deviceFactory(deviceType, name, address, deviceData, []);

device.Should().NotBeNull();
device.Should().BeOfType<JieStarSCM8>();
}

[Theory]
[InlineData("Device")]
[InlineData("IllegalDevice")]
public void RegisterDevice_JieStar_SCM8_IllegalDevice(string address)
{
DeviceType deviceType = DeviceType.JieStarSCM8;
string name = "TestDevice";
byte[] deviceData = [1, 2, 3];

Action act = () => _deviceFactory(deviceType, name, address, deviceData, []);

act.Should().Throw<Autofac.Core.DependencyResolutionException>()
.WithInnerException<Autofac.Core.DependencyResolutionException>()
.WithInnerException<ArgumentException>()
.Which.ParamName.Should().Be(nameof(address));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
using Autofac;
using BrickController2.DeviceManagement;
using BrickController2.DeviceManagement.DI;
using BrickController2.DeviceManagement.MouldKing;
using BrickController2.PlatformServices.BluetoothLE;
using FluentAssertions;
using Moq;
using System;
using Xunit;
using MouldKingVendor = BrickController2.DeviceManagement.MouldKing.MouldKing;

namespace BrickController2.Tests.DeviceManagement.DI;

public class MouldKingVendorTests : VendorTestsBase
{
private readonly DeviceFactory _deviceFactory;

public MouldKingVendorTests()
{
// Act
var container = InitializeContainer().Build();

_deviceFactory = container.Resolve<DeviceFactory>();
}

protected override ContainerBuilder InitializeContainer()
{
var builder = base.InitializeContainer();

// Arrange
builder.RegisterInstance(Mock.Of<IBluetoothLEService>());
builder.RegisterInstance(Mock.Of<IMKPlatformService>());

// execute registration of vendor MouldKing
builder.RegisterModule<MouldKingVendor>();

return builder;
}

[Theory]
[InlineData("Device")] // The address is not relevant for this device
[InlineData("IllegalDevice")] // The address is not relevant for this device
public void RegisterDevice_MK3_8_ReturnedDevice(string address)
{
DeviceType deviceType = DeviceType.MK3_8;
string name = "TestDevice";
byte[] deviceData = [1, 2, 3];

var device = _deviceFactory(deviceType, name, address, deviceData, []);

device.Should().NotBeNull();
device.Should().BeOfType<MK3_8>();
}

[Theory]
[InlineData("Device")]
[InlineData("IllegalDevice")]
public void RegisterDevice_MK4_IllegalDevice(string address)
{
DeviceType deviceType = DeviceType.MK4;
string name = "TestDevice";
byte[] deviceData = [1, 2, 3];

Action act = () => _deviceFactory(deviceType, name, address, deviceData, []);

act.Should().Throw<Autofac.Core.DependencyResolutionException>()
.WithInnerException<Autofac.Core.DependencyResolutionException>()
.WithInnerException<ArgumentException>()
.Which.ParamName.Should().Be(nameof(address));
}

[Theory]
[InlineData("Device1")]
[InlineData("Device2")]
[InlineData("Device3")]
public void RegisterDevice_MK4_ReturnedDevice(string address)
{
DeviceType deviceType = DeviceType.MK4;
string name = "TestDevice";
byte[] deviceData = [1, 2, 3];

var device = _deviceFactory(deviceType, name, address, deviceData, []);

device.Should().NotBeNull();
device.Should().BeOfType<MK4>();
}

[Theory]
[InlineData("Device")] // The address is not relevant for this device
[InlineData("IllegalDevice")] // The address is not relevant for this device
public void RegisterDevice_MK5_ReturnedDevice(string address)
{
DeviceType deviceType = DeviceType.MK5;
string name = "TestDevice";
byte[] deviceData = [1, 2, 3];

var device = _deviceFactory(deviceType, name, address, deviceData, []);

device.Should().NotBeNull();
device.Should().BeOfType<MK5>();
}

[Theory]
[InlineData("Device1")]
[InlineData("Device2")]
[InlineData("Device3")]
public void RegisterDevice_MK6_ReturnedDevice(string address)
{
DeviceType deviceType = DeviceType.MK6;
string name = "TestDevice";
byte[] deviceData = [1, 2, 3];

var device = _deviceFactory(deviceType, name, address, deviceData, []);

device.Should().NotBeNull();
device.Should().BeOfType<MK6>();
}

[Theory]
[InlineData("Device")]
[InlineData("IllegalDevice")]
public void RegisterDevice_MK6_IllegalDevice(string address)
{
DeviceType deviceType = DeviceType.MK6;
string name = "TestDevice";
byte[] deviceData = [1, 2, 3];

Action act = () => _deviceFactory(deviceType, name, address, deviceData, []);

act.Should().Throw<Autofac.Core.DependencyResolutionException>()
.WithInnerException<Autofac.Core.DependencyResolutionException>()
.WithInnerException<ArgumentException>()
.Which.ParamName.Should().Be(nameof(address));
}

[Theory]
[InlineData("MK_DIY_Address")]
public void RegisterDevice_MKDIY_ReturnedDevice(string address)
{
DeviceType deviceType = DeviceType.MK_DIY;
string name = "TestDevice";
byte[] deviceData = [1, 2, 3];

var device = _deviceFactory(deviceType, name, address, deviceData, []);

device.Should().NotBeNull();
device.Should().BeOfType<MK_DIY>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Autofac;
using BrickController2.DeviceManagement;
using BrickController2.DeviceManagement.DI;
using BrickController2.DeviceManagement.PowerFunctions;
using BrickController2.PlatformServices.Infrared;
using BrickController2.UI.Images;
using FluentAssertions;
using Moq;
using Xunit;
using PowerFunctionsVendor = BrickController2.DeviceManagement.PowerFunctions.PowerFunctions;

namespace BrickController2.Tests.DeviceManagement.DI;

public class PowerFunctionsVendorTests : VendorTestsBase
{
private readonly DeviceFactory _deviceFactory;

public PowerFunctionsVendorTests()
{
// Act
var container = InitializeContainer().Build();

_deviceFactory = container.Resolve<DeviceFactory>();
}

protected override ContainerBuilder InitializeContainer()
{
var builder = base.InitializeContainer();

// Arrange
builder.RegisterInstance(Mock.Of<IInfraredService>());
builder.RegisterInstance(Mock.Of<IDeviceImageRegistry>()); // needed because RegisterDevice<PowerFunctionsDevice>().WithImages("powerfunctions_image.png", "powerfunctions_image_small.png")

// execute registration of vendor PowerFunctions
builder.RegisterModule<PowerFunctionsVendor>();

return builder;
}


[Theory]
[InlineData("0", "PF Infra 1")]
[InlineData("1", "PF Infra 2")]
[InlineData("2", "PF Infra 3")]
[InlineData("3", "PF Infra 4")]
public void RegisterDevice_PowerFunctionsDevice_ReturnedDevice(string address, string name)
{
DeviceType deviceType = DeviceType.Infrared;

var device = _deviceFactory(deviceType, name, address, [], []);

device.Should().NotBeNull();
device.Should().BeOfType<PowerFunctionsDevice>();
}
}
Loading
Loading