public override int GetHashCode() { int hash = 1; if (OwnerAddress.Length != 0) { hash ^= OwnerAddress.GetHashCode(); } if (ExchangeId != 0L) { hash ^= ExchangeId.GetHashCode(); } if (TokenId.Length != 0) { hash ^= TokenId.GetHashCode(); } if (Quant != 0L) { hash ^= Quant.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
/// <summary> /// Creates an identifier for an ETD option instrument. /// <para> /// This takes into account the expiry of the underlying instrument. If the underlying expiry /// is the same as the expiry of the option, the identifier is the same as the normal one. /// Otherwise, the underlying expiry is added after the option expiry. For example: /// {@code 'OG-ETD~O-ECAG-OGBS-201706-P1.50-U201709'}. /// /// </para> /// </summary> /// <param name="exchangeId"> the MIC code of the exchange where the instruments are traded </param> /// <param name="contractCode"> the code supplied by the exchange for use in clearing and margining, such as in SPAN </param> /// <param name="expiryMonth"> the month of expiry </param> /// <param name="variant"> the variant of the ETD, such as 'Monthly', 'Weekly, 'Daily' or 'Flex' </param> /// <param name="version"> the non-negative version, zero by default </param> /// <param name="putCall"> the Put/Call flag </param> /// <param name="strikePrice"> the strike price </param> /// <param name="underlyingExpiryMonth"> the expiry of the underlying instrument, such as a future, may be null </param> /// <returns> the identifier </returns> public static SecurityId optionId(ExchangeId exchangeId, EtdContractCode contractCode, YearMonth expiryMonth, EtdVariant variant, int version, PutCall putCall, double strikePrice, YearMonth underlyingExpiryMonth) { ArgChecker.notNull(exchangeId, "exchangeId"); ArgChecker.notNull(contractCode, "contractCode"); ArgChecker.notNull(expiryMonth, "expiryMonth"); ArgChecker.notNull(variant, "variant"); ArgChecker.notNull(putCall, "putCall"); string putCallStr = putCall == PutCall.PUT ? "P" : "C"; string versionCode = version > 0 ? "V" + version + SEPARATOR : ""; NumberFormat f = NumberFormat.getIntegerInstance(Locale.ENGLISH); f.GroupingUsed = false; f.MaximumFractionDigits = 8; string strikeStr = f.format(strikePrice).replace('-', 'M'); string underlying = ""; if (underlyingExpiryMonth != null && !underlyingExpiryMonth.Equals(expiryMonth)) { underlying = SEPARATOR + "U" + underlyingExpiryMonth.format(YM_FORMAT); } string id = (new StringBuilder(40)).Append(OPT_PREFIX).Append(exchangeId).Append(SEPARATOR).Append(contractCode).Append(SEPARATOR).Append(expiryMonth.format(YM_FORMAT)).Append(variant.Code).Append(SEPARATOR).Append(versionCode).Append(putCallStr).Append(strikeStr).Append(underlying).ToString(); return(SecurityId.of(ETD_SCHEME, id)); }
private static async Task SerializerExampleAsync() { var storeDirectory = Path.Combine(Directory.GetCurrentDirectory(), "ProtocolBuffer"); Directory.CreateDirectory(storeDirectory); var networkHandler = new NetworkHandler(); var messageStore = new HttpMessageStore(new FileSystemStore(storeDirectory), new HttpMessageMapper(), new ProtocolBufferSerializer()); var logger = new HttpMessageLogger(messageStore); var loggingHandler = new LoggingHandler(logger) { InnerHandler = networkHandler }; using (var httpClient = new HttpClient(loggingHandler)) { var responseFromClient = await httpClient.GetAsync("http://httpbin.org/ip"); using (responseFromClient) { Console.WriteLine("Response from client:"); Console.WriteLine(await responseFromClient.Content.ReadAsStringAsync()); } ExchangeId exchangeId = responseFromClient.RequestMessage.GetExchangeId(); var responseOrExceptionFromStore = await messageStore.GetResponseOrExceptionAsync(exchangeId, CancellationToken.None); using (responseOrExceptionFromStore.Response) { Console.WriteLine("Response from store:"); Console.WriteLine(await responseOrExceptionFromStore.Response.Content.ReadAsStringAsync()); } } }
public override void ToStream(Stream output) { output.Write(TLUtils.SignatureToBytes(Signature)); output.Write(ExchangeId.ToBytes()); output.Write(GB.ToBytes()); output.Write(KeyFingerprint.ToBytes()); }
public override byte[] ToBytes() { return(TLUtils.Combine( TLUtils.SignatureToBytes(Signature), ExchangeId.ToBytes(), KeyFingerprint.ToBytes())); }
public override int GetHashCode() { int hash = 1; if (BrokerId.Length != 0) { hash ^= BrokerId.GetHashCode(); } if (InvestorId.Length != 0) { hash ^= InvestorId.GetHashCode(); } if (InstrumentId.Length != 0) { hash ^= InstrumentId.GetHashCode(); } if (ExchangeId.Length != 0) { hash ^= ExchangeId.GetHashCode(); } if (HedgeFlag != 0) { hash ^= HedgeFlag.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public void ConvertsToString() { // ARRANGE var exchangeId = new ExchangeId(new DateTimeOffset(2000, 1, 1, 8, 0, 0, TimeSpan.FromHours(8)), new Guid("F7E38533-F06B-407C-B26D-DC8EE9E961D4")); // ACT, ASSERT exchangeId.ToString().Should().Be("2000-01-01T00:00:00.0000000+00:00 f7e38533-f06b-407c-b26d-dc8ee9e961d4"); }
public void Empty() { // ARRANGE var exchangeId = new ExchangeId(); // ACT, ASSERT exchangeId.Should().Be(ExchangeId.Empty); }
public void ConvertsToUniversalTime() { // ARRANGE var exchangeId = new ExchangeId(new DateTimeOffset(2000, 1, 1, 8, 0, 0, TimeSpan.FromHours(8)), new Guid("F7E38533-F06B-407C-B26D-DC8EE9E961D4")); // ACT, ASSERT exchangeId.When.EqualsExact(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero)).Should().BeTrue(); }
public void ConsistentHashCode() { // ARRANGE var a = new ExchangeId(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), new Guid("F7E38533-F06B-407C-B26D-DC8EE9E961D4")); var b = new ExchangeId(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), new Guid("F7E38533-F06B-407C-B26D-DC8EE9E961D4")); // ACT, ASSERT a.GetHashCode().Should().Be(b.GetHashCode()); }
public void Properties() { // ARRANGE var exchangeId = new ExchangeId(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), new Guid("F7E38533-F06B-407C-B26D-DC8EE9E961D4")); // ACT, ASSERT exchangeId.When.EqualsExact(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero)).Should().BeTrue(); exchangeId.Unique.Should().Be(new Guid("F7E38533-F06B-407C-B26D-DC8EE9E961D4")); }
public TestState() { // data Request = new HttpRequestMessage(); ExchangeId = new ExchangeId(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), new Guid("E63B6D2C-BD08-4BCD-849E-67E929E1147D")); // setup Request.Properties[LoggingHandler.ExchangeIdPropertyKey] = ExchangeId; }
public void DifferentWhen() { // ARRANGE var a = new ExchangeId(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), new Guid("F7E38533-F06B-407C-B26D-DC8EE9E961D4")); var b = new ExchangeId(new DateTimeOffset(2000, 2, 2, 0, 0, 0, TimeSpan.Zero), new Guid("F7E38533-F06B-407C-B26D-DC8EE9E961D4")); // ACT, ASSERT a.Should().NotBe(b); }
public void DifferentUnique() { // ARRANGE var a = new ExchangeId(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), new Guid("F7E38533-F06B-407C-B26D-DC8EE9E961D4")); var b = new ExchangeId(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), new Guid("BA6F0E9D-38CE-4119-B74F-2E8315B322C7")); // ACT, ASSERT a.Should().NotBe(b); }
public override int GetHashCode() { unchecked { var hashCode = (Id != null ? Id.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ExchangeId != null ? ExchangeId.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ExchangeApiKey != null ? ExchangeApiKey.GetHashCode() : 0); return(hashCode); } }
public override int GetHashCode() { unchecked { var hashCode = (ExchangeId != null ? ExchangeId.GetHashCode() : 0); hashCode = (hashCode * 397) ^ PairsAsBaseCount; hashCode = (hashCode * 397) ^ PairsAsQuoteCount; return(hashCode); } }
public async Task SetAsync(ExchangeId exchangeId, Exception exception, CancellationToken cancellationToken) { // write the model var exceptionString = exception.ToString(); var storedModel = new HttpResponseOrException { Response = null, ExceptionString = exceptionString }; var modelKey = GetResponseOrExceptionKey(exchangeId); await SetModelAsync(modelKey, storedModel, cancellationToken).ConfigureAwait(false); }
public void New() { // ARRANGE var before = DateTimeOffset.UtcNow; var exchangeId = ExchangeId.NewExchangeId(); var after = DateTimeOffset.UtcNow; // ACT, ASSERT exchangeId.When.Should().BeOnOrAfter(before); exchangeId.When.Should().BeOnOrBefore(after); exchangeId.Unique.Should().NotBeEmpty(); }
public void ToDescendingString() { // ARRANGE var before = new ExchangeId(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), new Guid("DACD1424-DAA5-485B-81A4-E99C2BD66F1E")); var after = new ExchangeId(new DateTimeOffset(2000, 1, 2, 0, 0, 0, TimeSpan.Zero), new Guid("DACD1424-DAA5-485B-81A4-E99C2BD66F1E")); // ACT var beforeString = before.ToString("D"); var afterString = after.ToString("D"); string.Compare(beforeString, afterString, StringComparison.Ordinal).Should().BePositive(); }
/// <summary> /// Creates an identifier for an ETD future instrument. /// <para> /// A typical monthly ETD will have the format: /// {@code 'OG-ETD~O-ECAG-OGBS-201706'}. /// </para> /// <para> /// A more complex flex ETD (12th of the month, Physical settlement) will have the format: /// {@code 'OG-ETD~O-ECAG-OGBS-20170612E'}. /// /// </para> /// </summary> /// <param name="exchangeId"> the MIC code of the exchange where the instruments are traded </param> /// <param name="contractCode"> the code supplied by the exchange for use in clearing and margining, such as in SPAN </param> /// <param name="expiryMonth"> the month of expiry </param> /// <param name="variant"> the variant of the ETD, such as 'Monthly', 'Weekly, 'Daily' or 'Flex' </param> /// <returns> the identifier </returns> public static SecurityId futureId(ExchangeId exchangeId, EtdContractCode contractCode, YearMonth expiryMonth, EtdVariant variant) { ArgChecker.notNull(exchangeId, "exchangeId"); ArgChecker.notNull(contractCode, "contractCode"); ArgChecker.notNull(expiryMonth, "expiryMonth"); ArgChecker.isTrue(expiryMonth.Year >= 1000 && expiryMonth.Year <= 9999, "Invalid expiry year: ", expiryMonth); ArgChecker.notNull(variant, "variant"); string id = (new StringBuilder(40)).Append(FUT_PREFIX).Append(exchangeId).Append(SEPARATOR).Append(contractCode).Append(SEPARATOR).Append(expiryMonth.format(YM_FORMAT)).Append(variant.Code).ToString(); return(SecurityId.of(ETD_SCHEME, id)); }
public override int GetHashCode() { unchecked { var hashCode = (SymbolId != null ? SymbolId.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ExchangeId != null ? ExchangeId.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ExchangeSymbol != null ? ExchangeSymbol.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (BaseAsset != null ? BaseAsset.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (QuoteAsset != null ? QuoteAsset.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (TradeTypeAsString != null ? TradeTypeAsString.GetHashCode() : 0); return(hashCode); } }
public override int GetHashCode() { int hash = 1; if (BrokerId.Length != 0) { hash ^= BrokerId.GetHashCode(); } if (InvestorId.Length != 0) { hash ^= InvestorId.GetHashCode(); } if (UserId.Length != 0) { hash ^= UserId.GetHashCode(); } if (InstrumentId.Length != 0) { hash ^= InstrumentId.GetHashCode(); } if (ExchangeId.Length != 0) { hash ^= ExchangeId.GetHashCode(); } if (OrderSysId.Length != 0) { hash ^= OrderSysId.GetHashCode(); } if (OrderRef.Length != 0) { hash ^= OrderRef.GetHashCode(); } if (FrontId != 0) { hash ^= FrontId.GetHashCode(); } if (SessionId != 0) { hash ^= SessionId.GetHashCode(); } if (ActionFlag != 0) { hash ^= ActionFlag.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { unchecked { var hashCode = (ExchangeId != null ? ExchangeId.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (BaseAsset != null ? BaseAsset.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (QuoteAsset != null ? QuoteAsset.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (TradeTypeAsString != null ? TradeTypeAsString.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (TradeDirectionAsString != null ? TradeDirectionAsString.GetHashCode() : 0); hashCode = (hashCode * 397) ^ EventTime.GetHashCode(); hashCode = (hashCode * 397) ^ (ExchangeSequenceId != null ? ExchangeSequenceId.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Price.GetHashCode(); hashCode = (hashCode * 397) ^ Amount.GetHashCode(); return(hashCode); } }
//------------------------------------------------------------------------- /// <summary> /// Creates an identifier for a contract specification. /// <para> /// This will have the format: /// {@code 'OG-ETD~F-ECAG-FGBS'} or {@code 'OG-ETD~O-ECAG-OGBS'}. /// /// </para> /// </summary> /// <param name="type"> type of the contract - future or option </param> /// <param name="exchangeId"> the MIC code of the exchange where the instruments are traded </param> /// <param name="contractCode"> the code supplied by the exchange for use in clearing and margining, such as in SPAN </param> /// <returns> the identifier </returns> public static EtdContractSpecId contractSpecId(EtdType type, ExchangeId exchangeId, EtdContractCode contractCode) { ArgChecker.notNull(type, "type"); ArgChecker.notNull(exchangeId, "exchangeId"); ArgChecker.notNull(contractCode, "contractCode"); switch (type.innerEnumValue) { case com.opengamma.strata.product.etd.EtdType.InnerEnum.FUTURE: return(EtdContractSpecId.of(ETD_SCHEME, FUT_PREFIX + exchangeId + SEPARATOR + contractCode)); case com.opengamma.strata.product.etd.EtdType.InnerEnum.OPTION: return(EtdContractSpecId.of(ETD_SCHEME, OPT_PREFIX + exchangeId + SEPARATOR + contractCode)); default: throw new System.ArgumentException("Unknown ETD type: " + type); } }
public async Task SetAsync(ExchangeId exchangeId, HttpRequestMessage request, CancellationToken cancellationToken) { // map to a simpler model var storedModel = await _mapper.ToHttpAsync(request, cancellationToken).ConfigureAwait(false); // write the content if (storedModel.HasContent) { var contentKey = GetRequestContentKey(exchangeId); request.Content = await SetAndGetContentAsync(contentKey, storedModel.Content, request.Content.Headers, cancellationToken).ConfigureAwait(false); } // write the model var modelKey = GetRequestKey(exchangeId); await SetModelAsync(modelKey, storedModel, cancellationToken).ConfigureAwait(false); }
public override int GetHashCode() { unchecked { var hash = 17; hash = hash * 29 + RequestId != null?RequestId.GetHashCode() : 0; hash = hash * 29 + Symbol.GetHashCode(); hash = hash * 29 + ExchangeId.GetHashCode(); hash = hash * 29 + SecurityType.GetHashCode(); hash = hash * 29 + (Last.HasValue ? Last.GetHashCode() : 0); hash = hash * 29 + (TradeSize.HasValue ? TradeSize.GetHashCode() : 0); hash = hash * 29 + (TradedMarket.HasValue ? TradedMarket.GetHashCode() : 0); hash = hash * 29 + (TradeDate.HasValue ? TradeDate.GetHashCode() : 0); hash = hash * 29 + (TradeTime.HasValue ? TradeTime.GetHashCode() : 0); hash = hash * 29 + (Open.HasValue ? Open.GetHashCode() : 0); hash = hash * 29 + (High.HasValue ? High.GetHashCode() : 0); hash = hash * 29 + (Low.HasValue ? Low.GetHashCode() : 0); hash = hash * 29 + (Close.HasValue ? Close.GetHashCode() : 0); hash = hash * 29 + (Bid.HasValue ? Bid.GetHashCode() : 0); hash = hash * 29 + (BidMarket.HasValue ? BidMarket.GetHashCode() : 0); hash = hash * 29 + (BidSize.HasValue ? BidSize.GetHashCode() : 0); hash = hash * 29 + (Ask.HasValue ? Ask.GetHashCode() : 0); hash = hash * 29 + (AskMarket.HasValue ? AskMarket.GetHashCode() : 0); hash = hash * 29 + (AskSize.HasValue ? AskSize.GetHashCode() : 0); hash = hash * 29 + (Volume.HasValue ? Volume.GetHashCode() : 0); hash = hash * 29 + (PDayVolume.HasValue ? PDayVolume.GetHashCode() : 0); hash = hash * 29 + (UpVolume.HasValue ? UpVolume.GetHashCode() : 0); hash = hash * 29 + (DownVolume.HasValue ? DownVolume.GetHashCode() : 0); hash = hash * 29 + (NeutralVolume.HasValue ? NeutralVolume.GetHashCode() : 0); hash = hash * 29 + (TradeCount.HasValue ? TradeCount.GetHashCode() : 0); hash = hash * 29 + (UpTrades.HasValue ? UpTrades.GetHashCode() : 0); hash = hash * 29 + (DownTrades.HasValue ? DownTrades.GetHashCode() : 0); hash = hash * 29 + (NeutralTrades.HasValue ? NeutralTrades.GetHashCode() : 0); hash = hash * 29 + (VWAP.HasValue ? VWAP.GetHashCode() : 0); hash = hash * 29 + (MutualDiv.HasValue ? MutualDiv.GetHashCode() : 0); hash = hash * 29 + (SevenDayYield.HasValue ? SevenDayYield.GetHashCode() : 0); hash = hash * 29 + (OpenInterest.HasValue ? OpenInterest.GetHashCode() : 0); hash = hash * 29 + (Settlement.HasValue ? Settlement.GetHashCode() : 0); hash = hash * 29 + (SettlementDate.HasValue ? SettlementDate.GetHashCode() : 0); hash = hash * 29 + (ExpirationDate.HasValue ? ExpirationDate.GetHashCode() : 0); hash = hash * 29 + (Strike.HasValue ? Strike.GetHashCode() : 0); return(hash); } }
public async Task SetAsync(ExchangeId exchangeId, HttpResponseMessage response, CancellationToken cancellationToken) { // map to a simpler model var responseModel = await _mapper.ToHttpAsync(response, cancellationToken).ConfigureAwait(false); // write the content if (responseModel.HasContent) { var contentKey = GetResponseContentKey(exchangeId); response.Content = await SetAndGetContentAsync(contentKey, responseModel.Content, response.Content.Headers, cancellationToken).ConfigureAwait(false); } // write the model var storedModel = new HttpResponseOrException { Response = responseModel, ExceptionString = null }; var modelKey = GetResponseOrExceptionKey(exchangeId); await SetModelAsync(modelKey, storedModel, cancellationToken).ConfigureAwait(false); }
public async Task <HttpRequestMessage> GetRequestAsync(ExchangeId exchangeId, CancellationToken cancellationToken) { // get the model var modelKey = GetRequestKey(exchangeId); var storedModel = await GetModelAsync <HttpRequest>(modelKey, cancellationToken).ConfigureAwait(false); if (storedModel == null) { return(null); } // get the content if (storedModel.HasContent) { var contentKey = GetRequestContentKey(exchangeId); var content = await _store.GetAsync(contentKey, cancellationToken).ConfigureAwait(false); storedModel.Content = content; } return(_mapper.ToHttpMessage(storedModel)); }
public override int GetHashCode() { unchecked { var hashCode = ExchangeId != null?ExchangeId.GetHashCode() : 0; hashCode = (hashCode * 397) ^ (TradeType != null ? TradeType.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (BaseAsset != null ? BaseAsset.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (QuoteAsset != null ? QuoteAsset.GetHashCode() : 0); hashCode = (hashCode * 397) ^ TimePeriodStart.GetHashCode(); hashCode = (hashCode * 397) ^ TimePeriodEnd.GetHashCode(); hashCode = (hashCode * 397) ^ TimeOpen.GetHashCode(); hashCode = (hashCode * 397) ^ TimeClose.GetHashCode(); hashCode = (hashCode * 397) ^ PriceOpen.GetHashCode(); hashCode = (hashCode * 397) ^ PriceClose.GetHashCode(); hashCode = (hashCode * 397) ^ PriceLow.GetHashCode(); hashCode = (hashCode * 397) ^ PriceHigh.GetHashCode(); hashCode = (hashCode * 397) ^ VolumeTraded.GetHashCode(); hashCode = (hashCode * 397) ^ TradesCount.GetHashCode(); hashCode = (hashCode * 397) ^ (Id != null ? Id.GetHashCode() : 0); return(hashCode); } }
public TestState() { // dependencies Store = new Mock <IStore>(); Mapper = new Mock <IHttpMessageMapper>(); Serializer = new Mock <IProtocolBufferSerializer>(); // data CancellationToken = new CancellationToken(); ExchangeId = new ExchangeId(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), new Guid("4ae0fbbaaeba4db1bd98d106ece1a6e0")); RequestMessage = new HttpRequestMessage { Content = new StreamContent(Stream.Null) { Headers = { { "Content-Type", "text/plain" }, { "Content-Length", "7" } } } }; Request = new HttpRequest { Method = "POST", Url = "http://example/path", Version = "1.1", Headers = new[] { new HttpHeader { Name = "User-Agent", Value = "HttpMessageStore" }, new HttpHeader { Name = "Content-Type", Value = "text/plain" }, new HttpHeader { Name = "Content-Length", Value = "1" } }, HasContent = true, Content = GetStream("original-request") }; ResponseMessage = new HttpResponseMessage { Content = new StreamContent(Stream.Null) { Headers = { { "Content-Type", "text/plain" }, { "Content-Length", "8" } } } }; Response = new HttpResponse { Version = "1.1", StatusCode = 200, ReasonPhrease = "OK", Headers = new[] { new HttpHeader { Name = "Server", Value = "HttpMessageStore" }, new HttpHeader { Name = "Content-Type", Value = "text/plain" }, new HttpHeader { Name = "Content-Length", Value = "2" } }, HasContent = true, Content = GetStream("original-response") }; Exception = new Exception("some exception"); ResponseOrException = new HttpResponseOrException { Response = Response, ExceptionString = null }; // setup Store .Setup(x => x.GetAsync(It.Is <string>(k => k.EndsWith("request")), It.IsAny <CancellationToken>())) .Returns(() => Task.FromResult(GetStream("store-request"))); Store .Setup(x => x.GetAsync(It.Is <string>(k => k.EndsWith("request-content")), It.IsAny <CancellationToken>())) .Returns(() => Task.FromResult(GetStream("store-request-content"))); Store .Setup(x => x.GetAsync(It.Is <string>(k => k.EndsWith("response")), It.IsAny <CancellationToken>())) .Returns(() => Task.FromResult(GetStream("store-response"))); Store .Setup(x => x.GetAsync(It.Is <string>(k => k.EndsWith("response-content")), It.IsAny <CancellationToken>())) .Returns(() => Task.FromResult(GetStream("store-response-content"))); Mapper .Setup(x => x.ToHttpAsync(It.IsAny <HttpRequestMessage>(), It.IsAny <CancellationToken>())) .Returns(() => Task.FromResult(Request)); Mapper .Setup(x => x.ToHttpMessage(It.IsAny <HttpRequest>())) .Returns(() => RequestMessage); Mapper .Setup(x => x.ToHttpAsync(It.IsAny <HttpResponseMessage>(), It.IsAny <CancellationToken>())) .Returns(() => Task.FromResult(Response)); Mapper .Setup(x => x.ToHttpMessage(It.IsAny <HttpResponse>())) .Returns(() => ResponseMessage); Serializer .Setup(x => x.Serialize(It.IsAny <Stream>(), It.IsAny <HttpRequest>())) .Callback <Stream, HttpRequest>((s, r) => WriteToStream(s, "serialized")); Serializer .Setup(x => x.Deserialize <HttpRequest>(It.IsAny <Stream>())) .Returns(() => Request); Serializer .Setup(x => x.Serialize(It.IsAny <Stream>(), It.IsAny <HttpResponseOrException>())) .Callback <Stream, HttpResponseOrException>((s, r) => WriteToStream(s, "serialized")); Serializer .Setup(x => x.Deserialize <HttpResponseOrException>(It.IsAny <Stream>())) .Returns(() => ResponseOrException); Target = new HttpMessageStore(Store.Object, Mapper.Object, Serializer.Object); }