...
 
Commits (2)
......@@ -63,11 +63,13 @@ agent-test-results:
after_script:
- export PATH="$PATH:/root/.dotnet/tools"
- dotnet tool install --global dotnet-reportgenerator-globaltool --version 4.0.0-rc4
- dotnet tool install -g trx2junit
- trx2junit $AGENT_TEST_DIR/TestResults/agent.trx $ADAPTER_CONTRACT_TEST_DIR/TestResults/adapter.trx --output ./testresults
- dotnet tool install -g trx2junit --version 1.2.2
- mv $AGENT_TEST_DIR/coverage.opencover.xml .
- reportgenerator -reports:coverage.opencover.xml -targetdir:./coverage
- sed -n '3p' < coverage.opencover.xml | awk -F 'sequenceCoverage="' '{split($2, a, "\""); printf "%.2f", a[1]*100; print "%\n"}'
- mv $AGENT_TEST_DIR/TestResults/*.trx $AGENT_TEST_DIR/TestResults/agent.trx
- mv $ADAPTER_CONTRACT_TEST_DIR/TestResults/*.trx $ADAPTER_CONTRACT_TEST_DIR/TestResults/adapter.trx
- trx2junit $AGENT_TEST_DIR/TestResults/agent.trx $ADAPTER_CONTRACT_TEST_DIR/TestResults/adapter.trx --output ./testresults
artifacts:
expire_in: 1 week
paths:
......
using Bogus;
using Foci.Orbital.Adapters.Contract.Exceptions;
using Foci.Orbital.Adapters.Contract.Faults;
using Foci.Orbital.Agent.Exceptions;
using Foci.Orbital.Agent.Factories.Faults;
using System;
using System.Diagnostics.CodeAnalysis;
......@@ -27,9 +28,13 @@ namespace Foci.Orbital.Agent.Tests.Factories.Faults
{
var exceptionTypes = Assembly.GetAssembly(typeof(OrbitalException)).GetTypes().Where(t => t.IsSubclassOf(typeof(OrbitalException)));
var agentexceptionTypes = Assembly.GetAssembly(typeof(OrbitalFileException)).GetTypes().Where(t => t.IsSubclassOf(typeof(OrbitalException)));
var allExceptionTypes = exceptionTypes.Union(agentexceptionTypes);
var Target = new AgentFaultFactory();
foreach (var exceptionType in exceptionTypes)
foreach (var exceptionType in allExceptionTypes)
{
var inputException = Activator.CreateInstance(exceptionType) as OrbitalException;
......@@ -41,3 +46,4 @@ namespace Foci.Orbital.Agent.Tests.Factories.Faults
}
}
}
......@@ -11,6 +11,7 @@ using Foci.Orbital.Agent.Services.Interface;
using Foci.Orbital.Agent.Services.Interfaces;
using NSubstitute;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
......@@ -25,54 +26,36 @@ namespace Foci.Orbital.Agent.Tests.Services
private readonly Faker faker = new Faker();
/// <summary>
/// Test passing null configuration service to ServiceDefinitionService
/// Test passing null ConfigurationService, BusService, ServiceDefinitionRepository and OperationsHandler to DefinitionService
/// </summary>
[Fact]
[Trait("Category", "Failure")]
public void DefinitionServiceNullConfiguration()
[Theory]
[ClassData(typeof(ServiceDefinitionServiceData))]
internal void DefinitionServiceNull(IConfigurationService configuration,
IBusService busService,
IServiceDefinitionRepository serviceDefinitionRepository,
IOperationsHandler operationsHandler)
{
#region Substitutions
IBusService subBusService = Substitute.For<IBusService>();
IServiceDefinitionRepository serviceDefinitionRepository = Substitute.For<IServiceDefinitionRepository>();
IOperationsHandler operationsHandler = Substitute.For<IOperationsHandler>();
#endregion
Assert.Throws<ArgumentNullException>(() => new ServiceDefinitionService(null, subBusService, serviceDefinitionRepository, operationsHandler));
Assert.Throws<ArgumentNullException>(() => new ServiceDefinitionService(configuration, busService, serviceDefinitionRepository, operationsHandler));
}
/// <summary>
/// Test passing null bus service to DefinitionService
/// </summary>
[Fact]
[Trait("Category", "Failure")]
public void DefinitionServiceNullBusService()
{
#region Substitutions
IConfigurationService subConfiguration = Substitute.For<IConfigurationService>();
IBusService subBusService = Substitute.For<IBusService>();
IServiceDefinitionRepository serviceDefinitionRepository = Substitute.For<IServiceDefinitionRepository>();
IOperationsHandler operationsHandler = Substitute.For<IOperationsHandler>();
#endregion
Assert.Throws<ArgumentNullException>(() => new ServiceDefinitionService(subConfiguration, null, serviceDefinitionRepository, operationsHandler));
}
/// <summary>
/// Test passing null file repository to DefinitionService
/// </summary>
[Fact]
[Trait("Category", "Failure")]
public void DefinitionServiceNullDefinitionRepository()
public class ServiceDefinitionServiceData : IEnumerable<object[]>
{
#region Substitutions
IConfigurationService subConfiguration = Substitute.For<IConfigurationService>();
IBusService subBusService = Substitute.For<IBusService>();
IOperationsHandler operationsHandler = Substitute.For<IOperationsHandler>();
#endregion
public IEnumerator<object[]> GetEnumerator()
{
IConfigurationService subConfiguration = Substitute.For<IConfigurationService>();
IBusService subBusService = Substitute.For<IBusService>();
IServiceDefinitionRepository serviceDefinitionRepository = Substitute.For<IServiceDefinitionRepository>();
IOperationsHandler operationsHandler = Substitute.For<IOperationsHandler>();
yield return new object[] { subConfiguration, subBusService, serviceDefinitionRepository, null };
yield return new object[] { subConfiguration, subBusService, null, operationsHandler };
yield return new object[] { subConfiguration, null, serviceDefinitionRepository, operationsHandler };
yield return new object[] { null, subBusService, serviceDefinitionRepository, operationsHandler };
}
Assert.Throws<ArgumentNullException>(() => new ServiceDefinitionService(subConfiguration, subBusService, null, operationsHandler));
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
/// <summary>
......@@ -253,6 +236,7 @@ namespace Foci.Orbital.Agent.Tests.Services
subConfiguration.GetConfigurationProperties().Returns(config);
subBusService.BootstrapService(Arg.Any<BusConnectionDetails>(), Arg.Any<SubscriberDetails[]>()).Returns(subBus);
#endregion
......@@ -261,6 +245,58 @@ namespace Foci.Orbital.Agent.Tests.Services
Assert.Throws<ArgumentException>(() => Target.BootStrapSubscriberDetails(null, Input.Details));
}
/// <summary>
/// Test passing null input details to BootStrapSubscriberDetails method
/// </summary>
[Fact]
[Trait("Category", "Success")]
public void BootStrapServiceDetailsNull()
{
#region Substitutions
IConfigurationService subConfiguration = Substitute.For<IConfigurationService>();
IBusService subBusService = Substitute.For<IBusService>();
IOperationsHandler subOperationsHandler = Substitute.For<IOperationsHandler>();
IServiceDefinitionRepository serviceDefinitionRepository = Substitute.For<IServiceDefinitionRepository>();
IBus subBus = Substitute.For<IBus>();
#endregion
#region Setup
var Input = new
{
RabbitConfiguration = new Faker<BrokerConfiguration>()
.RuleFor(r => r.SslEnabled, f => true)
.RuleFor(r => r.Password, f => f.Internet.Password())
.RuleFor(r => r.Username, f => f.Internet.UserName())
.RuleFor(r => r.BusHostIp, f => f.Internet.Ip())
.RuleFor(r => r.BusHostPort, f => f.Random.Int(1, 65535))
.Generate(),
ServiceId = "testid",
Details = new List<SubscriberDetails>()
{
SubscriberDetails.Create<string>(s => string.IsNullOrEmpty(s), string.Empty),
SubscriberDetails.Create<string, string>(s => s,string.Empty)
}
};
var config = new OrbitalConfiguration
{
BrokerConfiguration = Input.RabbitConfiguration
};
subConfiguration.GetConfigurationProperties().Returns(config);
subBusService.BootstrapService(Arg.Any<BusConnectionDetails>(), Arg.Any<SubscriberDetails[]>()).Returns(subBus);
#endregion
var Target = new ServiceDefinitionService(subConfiguration, subBusService, serviceDefinitionRepository, subOperationsHandler);
var Expected = subBus;
var Actual = Target.BootStrapSubscriberDetails(Input.ServiceId, null);
Assert.Equal(Expected, Actual);
}
/// <summary>
/// Registers services with them all failing to load. Application continues to live.
/// </summary>
......@@ -414,6 +450,7 @@ namespace Foci.Orbital.Agent.Tests.Services
Actual.Select(s => s.RegisteredServices.Count()));
Assert.Equal(Expected.Select(s => s.ServiceName),
Actual.Select(s => s.ServiceName));
}
/// <summary>
......