Esempio n. 1
0
        public async Task InvokeNullable_Should_Execute_When_ParameterIsValid()
        {
            var thing   = new ActionThing();
            var context = Factory.Create(thing, new ThingOption());

            thing.ThingContext = context;

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

            context.Actions.Should().NotBeEmpty();

            context.Actions.Should().ContainKey(nameof(ActionThing.InvokeNullable));

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

            context.Actions[nameof(ActionThing.InvokeNullable)].TryAdd(jsonElement, out var info).Should().BeTrue();


            info.Should().NotBeNull();
            info.Status.Should().Be(ActionStatus.Created);
            await info.ExecuteAsync(thing, Provider).ConfigureAwait(false);

            info.Status.Should().Be(ActionStatus.Completed);
            thing.NullableValue.Should().Be(value);
        }
Esempio n. 2
0
        public async Task InvokeNullable_Should_Execute_When_ParameterIsNull()
        {
            var thing   = new ActionThing();
            var context = Factory.Create(thing, new ThingOption());

            thing.ThingContext = context;

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

            context.Actions.Should().NotBeEmpty();

            context.Actions.Should().ContainKey(nameof(ActionThing.InvokeNullable));

            var jsonElement = JsonSerializer.Deserialize <JsonElement>(
                @"{ ""invokeNullable"": { ""input"": { ""value"": null } } }").GetProperty("invokeNullable");

            context.Actions[nameof(ActionThing.InvokeNullable)].TryAdd(jsonElement, out var info).Should().BeTrue();

            info.Should().NotBeNull();
            info.Status.Should().Be(ActionStatus.Created);
            await info.ExecuteAsync(thing, Provider).ConfigureAwait(false);

            info.Status.Should().Be(ActionStatus.Completed);
            thing.NullableValue.Should().Be(null);
        }
Esempio n. 3
0
        public void CreateWithActions()
        {
            var thing  = new ActionThing();
            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
            .DidNotReceive()
            .Add(Arg.Any <PropertyInfo>(), Arg.Any <JsonSchema>());

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

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

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

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

            _action
            .Received(2)
            .Add(Arg.Any <ParameterInfo>(), Arg.Any <JsonSchema>());

            _response
            .Received(2)
            .Add(Arg.Any <MethodInfo>(), Arg.Any <ThingActionAttribute>());

            _response
            .Received(2)
            .Add(Arg.Any <ParameterInfo>(), Arg.Any <ThingParameterAttribute>(), Arg.Any <JsonSchema>());
        }
Esempio n. 4
0
        public void EnumNull_Should_ReturnError_When_ParameterIsInvalid()
        {
            var thing   = new ActionThing();
            var context = Factory.Create(thing, new ThingOption());

            thing.ThingContext = context;

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

            context.Actions.Should().NotBeEmpty();

            context.Actions.Should().ContainKey(nameof(ActionThing.EnumNull));

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

            context.Actions[nameof(ActionThing.EnumNull)].TryAdd(jsonElement, out var info).Should().BeFalse();
        }
        public void InvokeWithService_Should_ReturnError_When_ParameterIsNull()
        {
            var thing   = new ActionThing();
            var context = Factory.Create(thing, new ThingOption());

            thing.ThingContext = context;

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

            context.Actions.Should().NotBeEmpty();
            context.Actions.Should().HaveCount(6);
            context.Actions.Should().ContainKey(nameof(ActionThing.InvokeWithService));

            var jsonElement = JsonSerializer.Deserialize <JsonElement>(
                @"{ ""invoke"": { ""input"": { ""value"": null } } }").GetProperty("invoke");

            context.Actions[nameof(ActionThing.InvokeWithService)].TryAdd(jsonElement, out var info).Should().BeFalse();
            thing.Value.Should().NotBeNull();
        }
Esempio n. 6
0
        public void ExecuteMethod_Should_ReturnError_When_ParameterIsInvalid(string method)
        {
            var thing   = new ActionThing();
            var context = Factory.Create(thing, new ThingOption());

            thing.ThingContext = context;

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

            context.Actions.Should().NotBeEmpty();

            context.Actions.Should().ContainKey(method);

            var jsons = CreateInvalidJson();

            foreach (var element in jsons)
            {
                context.Actions[method].TryAdd(element, out _).Should().BeFalse();
            }
        }
Esempio n. 7
0
        public void Enum_Should_ReturnError_When_ParameterIsNull()
        {
            var thing = new ActionThing
            {
                Value = Fixture.Create <string>()
            };
            var context = Factory.Create(thing, new ThingOption());

            thing.ThingContext = context;

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

            context.Actions.Should().NotBeEmpty();

            context.Actions.Should().ContainKey(nameof(ActionThing.Enum));

            var jsonElement = JsonSerializer.Deserialize <JsonElement>(
                @"{ ""invoke"": { ""input"": { ""value"": null } } }").GetProperty("invoke");

            context.Actions[nameof(ActionThing.Enum)].TryAdd(jsonElement, out _).Should().BeFalse();

            thing.Value.Should().NotBeNull();
        }