public void SetUp()
        {
            _fakeFacts = new List <Fact>()
            {
                new Fact()
                {
                    Id = Guid.NewGuid().ToString()
                },
                new Fact()
                {
                    Id = Guid.NewGuid().ToString()
                }
            };

            var mockMessageHandler = new Mock <HttpMessageHandler>();

            mockMessageHandler.Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()
                )
            .ReturnsAsync(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(JsonConvert.SerializeObject(_fakeFacts))
            });

            _facts = new AnimalFacts(new HttpClient(mockMessageHandler.Object));
        }
        public async Task AnimalFactsTests_HandlesExceptionReturnsNull(FactSubject factSubject)
        {
            var mockMessageHandler = new Mock <HttpMessageHandler>();

            mockMessageHandler.Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()
                )
            .ThrowsAsync(new Exception("No cat facts for you."));

            _facts = new AnimalFacts(new HttpClient(mockMessageHandler.Object));

            var oneFact = await _facts.GetFact(new AnimalFactQuery(factSubject, 10));

            Assert.IsTrue(oneFact is null);
        }
Exemple #3
0
        public static void AddFact(this IFacts factSource, string key, string value)
        {
            if (key == null)
            {
                return;
            }

            if (value == null)
            {
                if (factSource.Facts.ContainsKey(key))
                {
                    factSource.Facts.Remove(key);
                    return;
                }
            }


            factSource.Facts[key] = value;
        }
Exemple #4
0
 public Task WorkAsync(IFacts facts, CancellationToken cancellation)
 {
     throw new System.NotImplementedException();
 }
        public bool IsTriggered(IFacts facts)
        {
            var fact = new FactKey();

            return(facts.ContainsKey(fact));
        }