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>()); _routeValue.GetValue <string>("id") .Returns(_fixture.Create <string>()); await GetActionById.Invoke(_httpContext); code.Should().Be((int)HttpStatusCode.NotFound); _thingActivator .Received(1) .CreateInstance(_service, thing); }
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>()); _routeValue.GetValue <string>("id") .Returns(_fixture.Create <string>()); await GetActionById.Invoke(_httpContext); code.Should().Be((int)HttpStatusCode.NotFound); _thingActivator .Received(1) .CreateInstance(_service, thingId); }
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); _routeValue.GetValue <string>("id") .Returns(actionId); 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 <Dictionary <string, object> >(), cancel) .Returns(new ValueTask()); _service.GetService(typeof(IHttpBodyWriter)) .Returns(writer); await GetActionById.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 <Dictionary <string, object> >(), cancel); }