示例#1
0
        public void ExecuteAsync_RemovesInnerControllerFromReleaseListAndAddsItselfInstead()
        {
            // Arrange
            var request        = new HttpRequestMessage();
            var context        = ContextUtil.CreateControllerContext(request: request);
            var mockController = new Mock <IHttpController>();
            var mockDisposable = mockController.As <IDisposable>();

            mockController.Setup(c => c.ExecuteAsync(context, CancellationToken.None))
            .Callback <HttpControllerContext, CancellationToken>((cc, ct) => cc.Request.RegisterForDispose(mockDisposable.Object))
            .Returns(() => TaskHelpers.FromResult(new HttpResponseMessage()))
            .Verifiable();
            context.ControllerDescriptor = _controllerDescriptor;
            context.Controller           = mockController.Object;
            var traceWriter = new TestTraceWriter();
            var tracer      = new HttpControllerTracer(request, mockController.Object, traceWriter);

            // Act
            ((IHttpController)tracer).ExecuteAsync(context, CancellationToken.None).WaitUntilCompleted();

            // Assert
            IEnumerable <IDisposable> disposables = (IEnumerable <IDisposable>)request.Properties[HttpPropertyKeys.DisposableRequestResourcesKey];

            Assert.Contains(tracer, disposables);
            Assert.DoesNotContain(mockDisposable.Object, disposables);
        }
示例#2
0
        public void LinkShare_GetSitesInOrderDoesNotReturnsGoogleBuzzForAll()
        {
            // Act
            var result = LinkShare.GetSitesInOrder(linkSites: new LinkShareSite[] { LinkShareSite.All });

            // Assert
#pragma warning disable 0618
            Assert.DoesNotContain(LinkShareSite.GoogleBuzz, result.ToArray());
#pragma warning restore 0618
        }
        public void Enumerating_OnlyIncludesHttpRoutes()
        {
            var aspNetRoute = new Mock <RouteBase>().Object;

            _aspNetRoutes.Add("foo", aspNetRoute);
            var httpRoute = new Mock <IHttpRoute>().Object;

            _webApiRoutes.Add("bar", httpRoute);

            List <object> objects = new List <object>(_webApiRoutes);

            Assert.Contains(httpRoute, objects);
            Assert.DoesNotContain(aspNetRoute, objects);
        }
示例#4
0
        public void ModelStateConstructorWithoutDetail_AddsCorrectDictionaryItems()
        {
            ModelStateDictionary modelState = new ModelStateDictionary();

            modelState.AddModelError("[0].Name", "error1");
            modelState.AddModelError("[0].Name", "error2");
            modelState.AddModelError("[0].Address", "error");
            modelState.AddModelError("[2].Name", new Exception("OH NO"));

            HttpError error           = new HttpError(modelState, false);
            HttpError modelStateError = error["ModelState"] as HttpError;

            Assert.Contains(new KeyValuePair <string, object>("Message", "The request is invalid."), error);
            Assert.Contains("error1", modelStateError["[0].Name"] as IEnumerable <string>);
            Assert.Contains("error2", modelStateError["[0].Name"] as IEnumerable <string>);
            Assert.Contains("error", modelStateError["[0].Address"] as IEnumerable <string>);
            Assert.True(modelStateError.ContainsKey("[2].Name"));
            Assert.DoesNotContain("OH NO", modelStateError["[2].Name"] as IEnumerable <string>);
        }