예제 #1
0
        public void WebGetRequestHandler_ProcessRequest_WhenValidUserContextWhenNullDataListID_ExpectExecution()
        {
            //------------Setup for test--------------------------
            var principle    = new Mock <IPrincipal>();
            var mockIdentity = new Mock <IIdentity>();

            mockIdentity.Setup(identity => identity.Name).Returns("FakeUser");
            principle.Setup(p => p.Identity).Returns(mockIdentity.Object);
            ClaimsPrincipal.ClaimsPrincipalSelector = () => new ClaimsPrincipal(principle.Object);
            ClaimsPrincipal.PrimaryIdentitySelector = identities => new ClaimsIdentity(mockIdentity.Object);

            var ctx            = new Mock <ICommunicationContext>();
            var boundVariables = new NameValueCollection {
                { "servicename", "ping" }, { "instanceid", "" }, { "bookmark", "" }
            };
            var queryString = new NameValueCollection {
                { GlobalConstants.DLID, null }, { "wid", Guid.Empty.ToString() }
            };

            ctx.Setup(c => c.Request.BoundVariables).Returns(boundVariables);
            ctx.Setup(c => c.Request.QueryString).Returns(queryString);
            ctx.Setup(c => c.Request.Uri).Returns(new Uri("http://localhost"));
            ctx.Setup(c => c.Request.User).Returns(principle.Object);

            var webGetRequestHandler = new WebGetRequestHandler();

            //------------Execute Test---------------------------
            webGetRequestHandler.ProcessRequest(ctx.Object);
            //------------Assert Results-------------------------
            principle.Verify(p => p.Identity, Times.AtLeast(1));
        }
예제 #2
0
        public void WebGetRequestHandler_ProcessRequest_WhenValidUserContext_ExpectExecution()
        {
            //------------Setup for test--------------------------
            Mock <IPrincipal> principle = new Mock <IPrincipal>();

            principle.Setup(p => p.Identity.Name).Returns("FakeUser");
            principle.Setup(p => p.Identity.Name).Verifiable();

            Mock <ICommunicationContext> ctx            = new Mock <ICommunicationContext>();
            NameValueCollection          boundVariables = new NameValueCollection {
                { "servicename", "ping" }, { "instanceid", "" }, { "bookmark", "" }
            };
            NameValueCollection queryString = new NameValueCollection {
                { GlobalConstants.DLID, Guid.Empty.ToString() }, { "wid", Guid.Empty.ToString() }
            };

            ctx.Setup(c => c.Request.BoundVariables).Returns(boundVariables);
            ctx.Setup(c => c.Request.QueryString).Returns(queryString);
            ctx.Setup(c => c.Request.Uri).Returns(new Uri("http://localhost"));
            ctx.Setup(c => c.Request.User).Returns(principle.Object);

            var webGetRequestHandler = new WebGetRequestHandler();

            //------------Execute Test---------------------------
            webGetRequestHandler.ProcessRequest(ctx.Object);

            //------------Assert Results-------------------------
            principle.Verify(p => p.Identity.Name, Times.AtLeast(1));
        }
예제 #3
0
        public void WebGetRequestHandler_ProcessRequest_WhenValidUserContext_ExpectExecution()
        {
            //------------Setup for test--------------------------

            var principle       = new Mock <IPrincipal>();
            var mockIdentity    = new Mock <IIdentity>();
            var resourceCatalog = new Mock <IResourceCatalog>();
            var mockResource    = new Mock <IResource>();
            var resource        = mockResource.Object;

            resourceCatalog.Setup(o => o.GetResource(Guid.Empty, "ping")).Returns(resource);
            var testCatalog         = new Mock <ITestCatalog>();
            var mockCoverageCatalog = new Mock <ITestCoverageCatalog>();

            mockIdentity.Setup(identity => identity.Name).Returns("FakeUser");
            principle.Setup(p => p.Identity.Name).Returns("FakeUser");
            principle.Setup(p => p.Identity).Returns(mockIdentity.Object);
            principle.Setup(p => p.Identity.Name).Verifiable();
            principle.Setup(p => p.Identity).Returns(mockIdentity.Object).Verifiable();
            var old = Common.Utilities.OrginalExecutingUser;

            if (Common.Utilities.OrginalExecutingUser != null)
            {
                Common.Utilities.OrginalExecutingUser = principle.Object;
            }
            ClaimsPrincipal.ClaimsPrincipalSelector = () => new ClaimsPrincipal(principle.Object);
            ClaimsPrincipal.PrimaryIdentitySelector = identities => new ClaimsIdentity(mockIdentity.Object);

            var ctx            = new Mock <ICommunicationContext>();
            var boundVariables = new NameValueCollection {
                { "servicename", "ping" }, { "instanceid", "" }, { "bookmark", "" }
            };
            var queryString = new NameValueCollection {
                { GlobalConstants.DLID, Guid.Empty.ToString() }, { "wid", Guid.Empty.ToString() }
            };

            ctx.Setup(c => c.Request.BoundVariables).Returns(boundVariables);
            ctx.Setup(c => c.Request.QueryString).Returns(queryString);
            ctx.Setup(c => c.Request.Uri).Returns(new Uri("http://localhost"));
            ctx.Setup(c => c.Request.User).Returns(principle.Object);

            var webGetRequestHandler = new WebGetRequestHandler(resourceCatalog.Object, testCatalog.Object, mockCoverageCatalog.Object);

            //------------Execute Test---------------------------
            webGetRequestHandler.ProcessRequest(ctx.Object);

            //------------Assert Results-------------------------
            mockIdentity.VerifyGet(identity => identity.Name, Times.AtLeast(1));
            Common.Utilities.OrginalExecutingUser = old;
        }