Exemplo n.º 1
0
        public async Task Invoke_Should_Return404_When_ActionDoesNotContainsAction()
        {
            int code = default;

            _response.StatusCode = Arg.Do <int>(args => code = args);

            var thingId = _fixture.Create <string>();
            var thing   = Substitute.For <Thing>();

            _thingActivator.CreateInstance(_service, thingId)
            .Returns(thing);

            thing.Actions
            .Returns(new ActionCollection());

            _routeValue.GetValue <string>("thing")
            .Returns(thingId);

            _routeValue.GetValue <string>("name")
            .Returns(_fixture.Create <string>());

            await GetAction.Invoke(_httpContext);

            code.Should().Be((int)HttpStatusCode.NotFound);

            _thingActivator
            .Received(1)
            .CreateInstance(_service, thingId);
        }
Exemplo n.º 2
0
        public async Task Invoke_Should_ReturnNotFound_When_ThingNotExists()
        {
            int code = default;

            _response.StatusCode = Arg.Do <int>(args => code = args);

            var thing = _fixture.Create <string>();

            _thingActivator.CreateInstance(_service, thing)
            .Returns(null as Thing);

            _routeValue.GetValue <string>("thing")
            .Returns(thing);

            _routeValue.GetValue <string>("name")
            .Returns(_fixture.Create <string>());

            await GetAction.Invoke(_httpContext);

            code.Should().Be((int)HttpStatusCode.NotFound);

            _thingActivator
            .Received(1)
            .CreateInstance(_service, thing);
        }
Exemplo n.º 3
0
        public LoadRedis(Func <string> action, ContainerBuilder builder)
            : base(action, builder)
        {
            var connection = GetAction.Invoke();

            RedisManager.Initialize(connection);
        }
Exemplo n.º 4
0
 public static object Get(string url, GetAction action)
 {
     try
     {
         WebClient wc = new WebClient();
         ServicePointManager.SecurityProtocol = (System.Net.SecurityProtocolType)SecurityProtocolType.Tls | (System.Net.SecurityProtocolType)SecurityProtocolType.Ssl3 | (System.Net.SecurityProtocolType)SecurityProtocolType.Tls11 | (System.Net.SecurityProtocolType)SecurityProtocolType.Tls12;
         ServicePointManager.ServerCertificateValidationCallback = CheckValidationResult;
         string cmd = wc.DownloadString(url);
         wc.Dispose();
         return(action?.Invoke(cmd));
     }
     catch { return(null); }
 }
Exemplo n.º 5
0
 // Person go to home.
 public string Move(GetAction getAct)
 {
     return(getAct.Invoke());
 }
Exemplo n.º 6
0
        public async Task Invoke_Should_Return200_When_ActionContainsAction()
        {
            int code = default;

            _response.StatusCode = Arg.Do <int>(args => code = args);

            var thingId = _fixture.Create <string>();
            var thing   = _fixture.Create <Thing>();

            _thingActivator.CreateInstance(_service, thingId)
            .Returns(thing);

            var actionName = _fixture.Create <string>();
            var action     = Substitute.For <Action>();
            var actionId   = _fixture.Create <string>();

            action.Id.Returns(actionId);
            action.Name.Returns(actionName);

            thing.Actions.Add(action);

            _routeValue.GetValue <string>("thing")
            .Returns(thingId);

            _routeValue.GetValue <string>("name")
            .Returns(actionName);

            var descriptor = Substitute.For <IDescriptor <Action> >();

            descriptor.CreateDescription(action)
            .Returns(_fixture.Create <Dictionary <string, object> >());

            _service.GetService(typeof(IDescriptor <Action>))
            .Returns(descriptor);

            var cancel = CancellationToken.None;

            _httpContext.RequestAborted
            .Returns(cancel);

            var writer = Substitute.For <IHttpBodyWriter>();

            writer.WriteAsync(Arg.Any <LinkedList <Dictionary <string, object> > >(), cancel)
            .Returns(new ValueTask());

            _service.GetService(typeof(IHttpBodyWriter))
            .Returns(writer);

            await GetAction.Invoke(_httpContext);

            code.Should().Be((int)HttpStatusCode.OK);

            _thingActivator
            .Received(1)
            .CreateInstance(_service, thingId);

            descriptor
            .Received(1)
            .CreateDescription(action);

            await writer
            .Received(1)
            .WriteAsync(Arg.Any <LinkedList <Dictionary <string, object> > >(), cancel);
        }