Skip to content

Commit a182bbb

Browse files
committed
Add test and customizers
1 parent 7c40ecd commit a182bbb

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using AutoFixture;
2+
using AutoFixture.Xunit2;
3+
4+
namespace RealTimeWeatherMonitoringTest.Common;
5+
6+
public class CustomAutoDataAttribute : AutoDataAttribute
7+
{
8+
public CustomAutoDataAttribute(params Type[] customizationTypes)
9+
: base(() =>
10+
{
11+
var fixture = new Fixture();
12+
13+
var customizations = customizationTypes
14+
.Select(t => Activator.CreateInstance(t) as ICustomization)
15+
.Where(c => c != null);
16+
17+
foreach (var customization in customizations)
18+
fixture.Customize(customization);
19+
20+
return fixture;
21+
})
22+
{
23+
}
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using AutoFixture;
2+
3+
namespace RealTimeWeatherMonitoringTest.Domain.Common;
4+
5+
/// <summary>
6+
/// This customization ensures that generated BotControllers will always
7+
/// react DataChangeEventArgs (Except when data is null).
8+
/// </summary>
9+
public class ReactiveBotControllerCustomization<TEvaluated> : ICustomization
10+
{
11+
public void Customize(IFixture fixture)
12+
{
13+
fixture.Customize(new BotCustomization<TEvaluated>(enabled: true));
14+
fixture.Customize(new FixedEvaluatorCustomization<TEvaluated>(true));
15+
}
16+
}

RealTimeWeatherMonitoringTest/Domain/Service/BotControllerServiceShould.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
using AutoFixture.AutoMoq;
12
using AutoFixture.Xunit2;
23
using FluentAssertions;
34
using Moq;
5+
using RealTimeWeatherMonitoringApp.Domain.Common;
46
using RealTimeWeatherMonitoringApp.Domain.Interfaces.Repository;
57
using RealTimeWeatherMonitoringApp.Domain.Interfaces.Service;
68
using RealTimeWeatherMonitoringApp.Domain.Models;
79
using RealTimeWeatherMonitoringApp.Domain.Models.Controller;
810
using RealTimeWeatherMonitoringApp.Domain.Service;
911
using RealTimeWeatherMonitoringTest.Common;
12+
using RealTimeWeatherMonitoringTest.Domain.Common;
1013
using RealTimeWeatherMonitoringTest.Domain.Models;
1114
using Xunit;
1215

@@ -48,4 +51,24 @@ public void GetBotControllers_WithPublishingService_ReturnPublisherControllersLa
4851
.And.HaveCount(bots.Count)
4952
.And.OnlyHaveUniqueItems();
5053
}
54+
55+
[Theory, CustomAutoData(
56+
typeof(AutoMoqCustomization),
57+
typeof(ReactiveBotControllerCustomization<TestData>))]
58+
public void GetBotControllers_WithPublishingService_ControllersEventsPublishedOnService(
59+
List<Bot<TestData>> bots,
60+
Mock<IBotPublishingService> publishingServiceMock,
61+
DataChangeEventArgs<TestData> dataChangeEventArgs,
62+
[Frozen] Mock<IBotRepository<TestData>> repositoryMock,
63+
BotControllerService<TestData> service)
64+
{
65+
repositoryMock.Setup(r => r.GetAll()).Returns(bots);
66+
var botControllers = service.GetBotControllers(publishingServiceMock.Object);
67+
68+
foreach (var controller in botControllers)
69+
{
70+
var eventArgs = controller.React(dataChangeEventArgs);
71+
publishingServiceMock.Verify(s => s.Publish(eventArgs), Times.Once);
72+
}
73+
}
5174
}

0 commit comments

Comments
 (0)