Пример #1
0
        public void WebPostRequestHandler_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 webPostRequestHandler = new WebPostRequestHandler();

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

            //------------Assert Results-------------------------
            principle.Verify(p => p.Identity.Name, Times.AtLeast(1));
        }
Пример #2
0
        public void WebPostRequestHandler_ProcessRequest_WhenValidUserContext_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.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 webPostRequestHandler = new WebPostRequestHandler();

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

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