コード例 #1
0
        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];
        }
コード例 #2
0
        /// <summary>
        /// Create a new instance of the <see cref="IApiCommandAsync"/> that is for deleting.
        /// </summary>
        /// <param name="apiClientKey">An option api client key that will be used to resolve the ApiHttpClient. Default is no key (null)</param>
        public IApiCommandAsync CreateDeleteCommand(object apiClientKey = null)
        {
            var client = _httpFactory.NewClient(apiClientKey);

            return(new ApiDeleteCommandAsync(client, _responseFactory));
        }