Exemplo n.º 1
0
 public void ByteArray_Ok_KeepResponse(object responseValue)
 {
     using (var request = new MemorySetup <byte[]>(
                responseValue,
                settings => settings.ExposeRawResponse(true),
                (settings, stream) => FakeResponse.Ok(settings, response: stream)
                ))
         this.ShouldStreamOfCopy(request);
 }
Exemplo n.º 2
0
 public void String_Bad_KeepResponse(object responseValue)
 {
     using (var request = new MemorySetup <string>(
                responseValue,
                settings => settings.ExposeRawResponse(true),
                (settings, stream) => FakeResponse.Bad(settings, response: stream)
                ))
         this.ShouldStreamOfCopy(request, false);
 }
 public async Task String_Bad_DiscardResponse(object responseValue)
 {
     using (var request = await new AsyncMemorySetup <string>(
                responseValue,
                settings => settings.ExposeRawResponse(false),
                (settings, stream) => FakeResponse.Bad(settings, response: stream)
                ).Init())
         this.ShouldStreamOfCopy(request, success: false, keepRaw: false);
 }
 public async Task Stream_Ok_DiscardResponse(object responseValue)
 {
     using (var request = await new AsyncMemorySetup <Stream>(
                responseValue,
                settings => settings.ExposeRawResponse(false),
                (settings, stream) => FakeResponse.Ok(settings, response: stream)
                ).Init())
         this.ShouldDirectlyStream(request);
 }
 public async Task ByteArray_Bad_KeepResponse(object responseValue)
 {
     using (var request = await new AsyncMemorySetup <byte[]>(
                responseValue,
                settings => settings.ExposeRawResponse(true),
                (settings, stream) => FakeResponse.Bad(settings, response: stream)
                ).Init())
         this.ShouldStreamOfCopy(request, success: false);
 }
 public async Task String_Ok_KeepResponse(object responseValue)
 {
     using (var request = await new AsyncMemorySetup <string>(
                responseValue,
                settings => settings.ExposeRawResponse(true),
                (settings, stream) => FakeResponse.Ok(settings, response: stream)
                ).Init())
         this.ShouldStreamOfCopy(request);
 }
 public async Task ByteArray_Ok_DiscardResponse(object responseValue)
 {
     using (var request = await new AsyncMemorySetup <byte[]>(
                responseValue,
                settings => settings.ExposeRawResponse(false),
                (settings, stream) => FakeResponse.Ok(settings, response: stream)
                ).Init())
         this.ShouldStreamOfCopy(request, keepRaw: false);
 }
Exemplo n.º 8
0
 public void Stream_Ok_KeepResponse(object responseValue)
 {
     using (var request = new MemorySetup <Stream>(
                responseValue,
                settings => settings.ExposeRawResponse(true),
                (settings, stream) => FakeResponse.Ok(settings, response: stream)
                ))
         this.ShouldDirectlyStream(request, success: true);
 }
Exemplo n.º 9
0
 public void Stream_Bad_DiscardResponse(object responseValue)
 {
     using (var request = new MemorySetup <Stream>(
                responseValue,
                settings => settings.ExposeRawResponse(false),
                (settings, stream) => FakeResponse.Bad(settings, response: stream)
                ))
         this.ShouldDirectlyStream(request, success: false);
 }
 public async Task Typed_Bad_KeepResponse(object responseValue)
 {
     using (var request = await new AsyncMemorySetup <StandardResponse>(
                responseValue,
                settings => settings.ExposeRawResponse(true),
                (settings, stream) => FakeResponse.Bad(settings, response: stream)
                ).Init())
         this.ShouldStreamOfCopy(request, false);
 }
 public async Task Stream_Bad_KeepResponse(object responseValue)
 {
     using (var request = await new AsyncMemorySetup <Stream>(
                responseValue,
                settings => settings.ExposeRawResponse(true),
                (settings, stream) => FakeResponse.Bad(settings, response: stream)
                ).Init())
         this.ShouldDirectlyStream(request, success: false);
 }
Exemplo n.º 12
0
 public void ByteArray_Bad_DiscardResponse(object responseValue)
 {
     using (var request = new MemorySetup <byte[]>(
                responseValue,
                settings => settings.ExposeRawResponse(false),
                (settings, stream) => FakeResponse.Bad(settings, response: stream)
                ))
         this.ShouldStreamOfCopy(request, success: false, keepRaw: false);
 }
Exemplo n.º 13
0
 public void String_Ok_DiscardResponse(object responseValue)
 {
     using (var request = new MemorySetup <string>(
                responseValue,
                settings => settings.ExposeRawResponse(false),
                (settings, stream) => FakeResponse.Ok(settings, response: stream)
                ))
         this.ShouldStreamOfCopy(request, keepRaw: false);
 }
Exemplo n.º 14
0
 public void Typed_Ok_DiscardResponse(object responseValue)
 {
     using (var request = new MemorySetup <StandardResponse>(
                responseValue,
                settings => settings.ExposeRawResponse(false),
                (settings, stream) => FakeResponse.Ok(settings, response: stream)
                ))
         this.ShouldDirectlyStream(request);
 }
Exemplo n.º 15
0
        public async Task EnsureRefreshAuthenticationTokenAsyncThrowsForFailedCalls()
        {
            var client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.InternalServerError()));
            var token  = AuthTokenTests.GetTestAuthToken();

            token.ExpiresUtc = DateTime.UtcNow.AddDays(-1);
            client.SetAuthenticationToken(token);
            var result = await client.RefreshAuthenticationTokenAsync("secret");
        }
 public async Task DynamicDictionary_Bad_DiscardResponse(object responseValue)
 {
     using (var request = await new AsyncMemorySetup <DynamicDictionary>(
                responseValue,
                settings => settings.ExposeRawResponse(false),
                (settings, stream) => FakeResponse.Bad(settings, response: stream)
                ).Init())
         this.ShouldDirectlyStream(request, false);
 }
Exemplo n.º 17
0
        public async Task EnsureRefreshAuthenticationTokenAsyncReturnsExistingTokenIfValid()
        {
            var client = new MusicClient("test", "gb", new MockApiRequestHandler(FakeResponse.NotFound()));
            var token  = AuthTokenTests.GetTestAuthToken();

            client.SetAuthenticationToken(token);
            var result = await client.RefreshAuthenticationTokenAsync("secret");

            Assert.AreEqual(token.AccessToken, result.AccessToken, "Expected the same token");
        }
Exemplo n.º 18
0
        public async System.Threading.Tasks.Task UnauthorizedResponseDoesNothingInDefaultImplementation()
        {
            var command = new MockMusicClientCommand
            {
                OAuth2         = new OAuth2(new FakeAuthHeaderProvider()),
                RequestHandler = new MockApiRequestHandler(FakeResponse.RawUnauthorized()),
            };

            await command.ExecuteAsync(null);
        }
 public async Task DynamicDictionary_Ok_KeepResponse(object responseValue)
 {
     using (var request = await new AsyncMemorySetup <DynamicDictionary>(
                responseValue,
                settings => settings.ExposeRawResponse(true),
                (settings, stream) => FakeResponse.Ok(settings, response: stream),
                c => c.InfoAsync()
                ).Init())
         this.ShouldStreamOfCopy(request);
 }
Exemplo n.º 20
0
 public void DynamicDictionary_Bad_DiscardResponse(object responseValue)
 {
     using (var request = new MemorySetup <DynamicDictionary>(
                responseValue,
                settings => settings.ExposeRawResponse(false),
                (settings, stream) => FakeResponse.Bad(settings, response: stream),
                client => client.Info()
                ))
         this.ShouldDirectlyStream(request, false);
 }
Exemplo n.º 21
0
        CreateMockRule(FakeRequest fakeRequest, FakeResponse fakeResponse, RuleStatusType statusType, bool continueProcessing)
        {
            var mockRule = new Mock <IBaseRule <FakeRequest, FakeResponse> >();

            mockRule.Setup(x => x.ProcessAsync(fakeRequest, fakeResponse, ItIsAnyRules())).Returns(Task.CompletedTask);
            mockRule.Setup(x => x.Status).Returns(statusType);
            mockRule.Setup(x => x.IsNotProcessed()).Returns(statusType == RuleStatusType.NotProcessed);
            mockRule.Setup(x => x.ContinueProcessing).Returns(continueProcessing);
            return(mockRule);
        }
Exemplo n.º 22
0
 public void VoidResponse_Bad_DiscardResponse(object responseValue)
 {
     using (var request = new MemorySetup <VoidResponse>(
                responseValue,
                settings => settings.ExposeRawResponse(false),
                (settings, stream) => FakeResponse.Bad(settings, response: stream)
                ))
         //voidResponse NEVER reads the body so Raw is always false
         this.ShouldDirectlyStream(request, success: false);
 }
Exemplo n.º 23
0
 public void DynamicDictionary_Ok_KeepResponse(object responseValue)
 {
     using (var request = new MemorySetup <DynamicDictionary>(
                responseValue,
                settings => settings.ExposeRawResponse(true),
                (settings, stream) => FakeResponse.Ok(settings, response: stream),
                client => client.Info()
                ))
         this.ShouldStreamOfCopy(request);
 }
Exemplo n.º 24
0
        public async void DeadNodesAreNotVisited_AndPingedAppropiately_Async()
        {
            using (var fake = new AutoFake())
            {
                var dateTimeProvider = ProvideDateTimeProvider(fake);
                var config           = ProvideConfiguration(dateTimeProvider);
                var connection       = ProvideConnection(fake, config);

                var getCall = FakeCalls.GetCall(fake);
                var ok      = Task.FromResult(FakeResponse.Ok(config));
                var bad     = Task.FromResult(FakeResponse.Bad(config));
                getCall.ReturnsNextFromSequence(
                    ok,                      //info 1 - 9204
                    bad,                     //info 2 - 9203 DEAD
                    ok,                      //info 2 retry - 9202
                    ok,                      //info 3 - 9201
                    ok,                      //info 4 - 9204
                    ok,                      //info 5 - 9202
                    ok,                      //info 6 - 9201
                    ok,                      //info 7 - 9204
                    ok,                      //info 8 - 9203 (Now > Timeout)
                    ok                       //info 9 - 9202
                    );

                var seenNodes = new List <Uri>();
                getCall.Invokes((Uri u, IRequestConnectionConfiguration o) => seenNodes.Add(u));

                var pingCall = FakeCalls.PingAtConnectionLevelAsync(fake);
                pingCall.Returns(ok);

                var client1 = fake.Resolve <ElasticsearchClient>();
                await client1.InfoAsync();                 //info call 1

                await client1.InfoAsync();                 //info call 2

                await client1.InfoAsync();                 //info call 3

                await client1.InfoAsync();                 //info call 4

                await client1.InfoAsync();                 //info call 5

                await client1.InfoAsync();                 //info call 6

                await client1.InfoAsync();                 //info call 7

                await client1.InfoAsync();                 //info call 8

                await client1.InfoAsync();                 //info call 9

                AssertSeenNodesAreInExpectedOrder(seenNodes);

                //4 nodes first time usage + 1 time after the first time 9203 came back to live
                pingCall.MustHaveHappened(Repeated.Exactly.Times(5));
            }
        }
Exemplo n.º 25
0
 public void VoidResponse_Bad_KeepResponse(object responseValue)
 {
     using (var request = new MemorySetup <VoidResponse>(
                responseValue,
                settings => settings.ExposeRawResponse(true),
                (settings, stream) => FakeResponse.Bad(settings, response: stream)
                ))
         //voidResponse NEVER reads the body so Raw is always false
         //and no intermediate stream should be created
         this.ShouldDirectlyStream(request, success: false);
 }
Exemplo n.º 26
0
        public void BaseSetup()
        {
            MockHttpContext = new Mock <HttpContextBase>();
            MockRequest     = new Mock <HttpRequestBase>();
            FakeResponse    = new FakeResponse();
            Routes          = new RouteCollection();
            Routes.RegisterRoutes();

            MockHttpContext.Setup(m => m.Request).Returns(MockRequest.Object);
            MockHttpContext.Setup(m => m.Response).Returns(FakeResponse);
        }
 public async Task VoidResponse_Ok_KeepResponse(object responseValue)
 {
     using (var request = await new AsyncMemorySetup <VoidResponse>(
                responseValue,
                settings => settings.ExposeRawResponse(true),
                (settings, stream) => FakeResponse.Ok(settings, response: stream)
                ).Init())
         //voidResponse NEVER reads the body so Raw is always false
         //and no intermediate stream should be created
         this.ShouldDirectlyStream(request);
 }
Exemplo n.º 28
0
        public void EnsureCountryResolverPassesDefaultSettings()
        {
            MockApiRequestHandler mockHandler = new MockApiRequestHandler(FakeResponse.NotFound());
            ICountryResolver      client      = new CountryResolver("test1", mockHandler);

            client.CheckAvailability(result => Assert.IsNotNull(result, "Expected a result"), "xx");

            Assert.AreEqual("test1", mockHandler.LastUsedSettings.AppId);
            Assert.AreEqual(null, mockHandler.LastUsedSettings.CountryCode);
            Assert.AreEqual(false, mockHandler.LastUsedSettings.CountryCodeBasedOnRegionInfo);
        }
Exemplo n.º 29
0
        public async Task ProcessAsyncCanChangeStatusAndContinueProcessing(string scenario, bool expectedContinueProcessing,
                                                                           RuleStatusType expectedRuleStatusType, FakeRule rule, List <IBaseRule <FakeRequest, FakeResponse> > rules)
        {
            var request = new FakeRequest {
                ContinueProcessing = expectedContinueProcessing
            };
            var response = new FakeResponse();

            await rule.ProcessAsync(request, response, rules);

            Assert.AreEqual(expectedContinueProcessing, rule.ContinueProcessing, scenario);
            Assert.AreEqual(expectedRuleStatusType, rule.Status, scenario);
        }
Exemplo n.º 30
0
        public void EnsureUriIsBuiltCorrectlyForTrack()
        {
            StringBuilder uri = new StringBuilder("http://api.ent.nokia.com/1.x/gb/");
            var           cmd = new NewReleasesCommand
            {
                RequestHandler = new MockApiRequestHandler(FakeResponse.NotFound()),
                Category       = Category.Track,
                ClientSettings = new MockMusicClientSettings(string.Empty, string.Empty, string.Empty)
            };

            cmd.AppendUriPath(uri);
            Assert.AreEqual("http://api.ent.nokia.com/1.x/gb/products/new/track/", uri.ToString());
        }
        private string GetOutboundUrl(object routeValues)
        {
            RouteCollection routes = new RouteCollection();
            RouteConfig.RegisterRoutes(routes);
            var mockHttpContext = new Moq.Mock<HttpContextBase>();
            var mockRequest = new Moq.Mock<HttpRequestBase>();
            var fakeResponse = new FakeResponse();
            mockHttpContext.Setup(x => x.Request).Returns(mockRequest.Object);
            mockHttpContext.Setup(x => x.Response).Returns(fakeResponse);
            mockRequest.Setup(x => x.ApplicationPath).Returns("/");

            var ctx = new RequestContext(mockHttpContext.Object, new RouteData());
            return routes.GetVirtualPath(ctx, new RouteValueDictionary(routeValues)).VirtualPath;
        }
    public void MyTestInitialize()
    {
      string appPath = FileHelper.CombineTrackbacksInPath(
          Path.Combine(TestContext.TestDir, @"..\..\WebCore\"));
      container = new Container(new FileRegistry(appPath));

      var mockHttpContext = new Moq.Mock<HttpContextBase>();
      var mockRequest = new Moq.Mock<HttpRequestBase>();
      var fakeResponse = new FakeResponse();
      var fakeAppState = new FakeApplicationState();
      fakeAppState.Add("Container", container);
      mockHttpContext.Setup(x => x.Request).Returns(mockRequest.Object);
      mockHttpContext.Setup(x => x.Response).Returns(fakeResponse);
      mockHttpContext.Setup(x => x.Application).Returns(fakeAppState);
      mockRequest.Setup(x => x.ApplicationPath).Returns("/");
      var requestContext = new RequestContext(mockHttpContext.Object, new RouteData());
      container.Configure(a => a.For<UrlHelper>().Use(f => new UrlHelper(requestContext)));
      PluginEngine.LoadPlugins(container, RouteTable.Routes, ViewEngines.Engines, ModelBinders.Binders, appPath, TestContext.TestDeploymentDir);
    }