public PropertyInterceptFactoryTest() { _fixture = new Fixture(); _thing = new LampThing(); _factory = new PropertiesInterceptFactory(_thing, new ThingOption { }); }
public ConverterInterceptorTest() { _fixture = new Fixture(); _thing = new LampThing(); _factory = new ConverterInterceptorFactory(_thing, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, IgnoreNullValues = true, }); }
public ActionInterceptFactoryTest() { _fixture = new Fixture(); _thing = new LampThing(); _factory = new ActionInterceptFactory(new ThingOption()); var logger = Substitute.For <ILogger <ActionInfo> >(); _provider = Substitute.For <IServiceProvider>(); _provider.GetService(typeof(ILogger <ActionInfo>)) .Returns(logger); }
public void Valid() { var thing = new LampThing(); var eventFactory = new EventInterceptFactory(thing, _options); CodeGeneratorFactory.Generate(thing, new [] { eventFactory }); thing.ThingContext = new Context(Substitute.For <IThingConverter>(), Substitute.For <IProperties>(), eventFactory.Events, new Dictionary <string, ActionContext>()); var @int = _fixture.Create <int>(); thing.Emit(@int); var events = thing.ThingContext.Events[nameof(LampThing.Int)].ToArray(); events.Should().HaveCount(1); events[0].Data.Should().Be(@int); var @decimal = _fixture.Create <decimal>(); thing.Emit(@decimal); events = thing.ThingContext.Events[nameof(LampThing.Decimal)].ToArray(); events.Should().HaveCount(1); events[0].Data.Should().Be(@decimal); thing.Emit((decimal?)null); events = thing.ThingContext.Events[nameof(LampThing.Decimal)].ToArray(); events.Should().HaveCount(2); events[1].Data.Should().Be(null); var @dateTime = _fixture.Create <DateTime>(); thing.Emit(dateTime); events = thing.ThingContext.Events[nameof(LampThing.DateTime)].ToArray(); events.Should().HaveCount(1); events[0].Data.Should().Be(@dateTime); var @obj = _fixture.Create <object>(); thing.Emit(obj); events = thing.ThingContext.Events[nameof(LampThing.Any)].ToArray(); events.Should().HaveCount(1); events[0].Data.Should().Be(@obj); }
public void Ignore() { var thing = new LampThing(); var eventFactory = new EventInterceptFactory(thing, _options); CodeGeneratorFactory.Generate(thing, new [] { eventFactory }); thing.ThingContext = new Context(Substitute.For <IThingConverter>(), Substitute.For <IProperties>(), eventFactory.Events, new Dictionary <string, ActionContext>()); var @int = _fixture.Create <int>(); thing.EmitIgnore(@int); var events = thing.ThingContext.Events[nameof(LampThing.Int)].ToArray(); events.Should().BeEmpty(); }