private void CreateCommandTest(Func <ApiCommandFactory, IApiCommandAsync> create, Type commandType, int serializerMapCalls) { // Arrange IApiHttpFactory httpFactory = Substitute.For <IApiHttpFactory>(); IHttpResponseFactory responseFactory = Substitute.For <IHttpResponseFactory>(); IApiHttpClient httpClient = Substitute.For <IApiHttpClient>(); IApiCommandContentSerializer serializer = Substitute.For <IApiCommandContentSerializer>(); IApiCommandContentTypeMap <IApiCommandContentSerializer> serializers = Substitute.For <IApiCommandContentTypeMap <IApiCommandContentSerializer> >(); serializers[_mediaType].Returns(serializer); httpFactory.NewClient(_key).Returns(httpClient); var factory = new ApiCommandFactory(httpFactory, responseFactory, serializers); // Act var command = create(factory); // Assert Assert.NotNull(command); Assert.IsType(commandType, command); httpFactory.Received(1).NewClient(Arg.Any <object>()); httpFactory.Received(1).NewClient(_key); _ = serializers.Received(serializerMapCalls)[_mediaType]; }
public void CreateRequest_Execute_RestursRequest() { // Arrange Uri uri = new("/", UriKind.Relative); object content = new(); IApiHttpFactory httpFactory = Substitute.For <IApiHttpFactory>(); IHttpResponseFactory responseFactory = Substitute.For <IHttpResponseFactory>(); IApiCommandContentSerializer serializer = Substitute.For <IApiCommandContentSerializer>(); IApiCommandContentTypeMap <IApiCommandContentSerializer> serializers = Substitute.For <IApiCommandContentTypeMap <IApiCommandContentSerializer> >(); var factory = new ApiCommandFactory(httpFactory, responseFactory, serializers); // Act var request = factory.CreateRequest(uri, content); // Assert Assert.NotNull(request); Assert.Equal(uri, request.ApiUri); Assert.Same(content, request.Content); }