Пример #1
0
        public void InvalidValidProperty()
        {
            var thing   = new PropertyThing();
            var context = Factory.Create(thing, new ThingOption());

            thing.ThingContext = context;

            context.Actions.Should().BeEmpty();
            context.Events.Should().BeEmpty();

            context.Properties.Should().NotBeEmpty();
            context.Properties.Should().ContainKey(nameof(PropertyThing.Value));

            var value       = Fixture.Create <T>();
            var jsonElement = CreateInvalidJson();

            var defaultValue = Fixture.Create <T>();

            thing.Value = defaultValue;
            foreach (var element in jsonElement)
            {
                context.Properties[nameof(PropertyThing.Value)].TrySetValue(element).Should().Be(SetPropertyResult.InvalidValue);
                thing.Value.Should().NotBe(value);
                thing.Value.Should().Be(defaultValue);
                context.Properties[nameof(PropertyThing.Value)].TryGetValue(out var getValue).Should().BeTrue();
                getValue.Should().Be(defaultValue);
            }
        }
Пример #2
0
        public void ValidProperty()
        {
            var thing   = new PropertyThing();
            var context = Factory.Create(thing, new ThingOption());

            thing.ThingContext = context;

            context.Actions.Should().BeEmpty();
            context.Events.Should().BeEmpty();

            context.Properties.Should().NotBeEmpty();
            context.Properties.Should().HaveCount(2);
            context.Properties.Should().ContainKey(nameof(PropertyThing.Value));
            context.Properties.Should().ContainKey(nameof(PropertyThing.NullableValue));

            var value       = CreateValue();
            var jsonElement = CreateJson(value);

            context.Properties[nameof(PropertyThing.Value)].TrySetValue(jsonElement).Should().Be(SetPropertyResult.Ok);
            thing.Value.Should().Be(value);
            context.Properties[nameof(PropertyThing.Value)].TryGetValue(out var getValue).Should().BeTrue();
            getValue.Should().Be(value);

            context.Properties[nameof(PropertyThing.NullableValue)].TrySetValue(jsonElement).Should().Be(SetPropertyResult.Ok);
            thing.NullableValue.Should().Be(value);
            context.Properties[nameof(PropertyThing.NullableValue)].TryGetValue(out getValue).Should().BeTrue();
            getValue.Should().Be(value);

            jsonElement = JsonSerializer.Deserialize <JsonElement>(@"{ ""input"": null }").GetProperty("input");
            context.Properties[nameof(PropertyThing.NullableValue)].TrySetValue(jsonElement).Should().Be(SetPropertyResult.Ok);
            thing.NullableValue.Should().BeNull();
            context.Properties[nameof(PropertyThing.NullableValue)].TryGetValue(out getValue).Should().BeTrue();
            getValue.Should().BeNull();
        }
Пример #3
0
        public void CreateWithProperty()
        {
            var thing  = new PropertyThing();
            var option = new ThingOption();

            var context = _factory.Create(thing, option);

            context.Should().NotBeNull();

            _property
            .Received(1)
            .Build();

            _action
            .Received(1)
            .Build();

            _response
            .Received(1)
            .Build();

            _event
            .Received(1)
            .Build();

            _property
            .Received(5)
            .Add(Arg.Any <PropertyInfo>(), Arg.Any <JsonSchema>());

            _response
            .Received(5)
            .Add(Arg.Any <PropertyInfo>(), Arg.Any <ThingPropertyAttribute>(), Arg.Any <JsonSchema>());

            _event
            .DidNotReceive()
            .Add(Arg.Any <EventInfo>(), Arg.Any <ThingEventAttribute>());

            _action
            .DidNotReceive()
            .Add(Arg.Any <MethodInfo>(), Arg.Any <ThingActionAttribute>());

            _action
            .DidNotReceive()
            .Add(Arg.Any <ParameterInfo>(), Arg.Any <JsonSchema>());
        }