コード例 #1
0
        public void DefaultAuthentication()
        {
            WebContextMock context = new WebContextMock();

            Assert.IsNotNull(context.Authentication,
                             "Authentication should not be null.");

            ExceptionHelper.ExpectException <NotSupportedException>(
                () => context.Authentication.Login(null));
            ExceptionHelper.ExpectException <NotSupportedException>(
                () => context.Authentication.Logout(false));
            ExceptionHelper.ExpectException <NotSupportedException>(
                () => context.Authentication.LoadUser());
            ExceptionHelper.ExpectException <NotSupportedException>(
                () => context.Authentication.SaveUser(false));

            Assert.AreEqual(context.Authentication.User, context.UserMock,
                            "Users should be equal.");
            Assert.IsNotNull(context.UserMock,
                             "User should not be null.");
            Assert.IsNotNull(context.UserMock.Identity,
                             "Identity should not be null.");
            Assert.IsNotNull(context.UserMock.Identity.AuthenticationType,
                             "Authentication type should not be null.");
            Assert.IsFalse(context.UserMock.Identity.IsAuthenticated,
                           "Authentication state should be false.");
            Assert.IsNotNull(context.UserMock.Identity.Name,
                             "Name should not be null.");

            Assert.IsFalse(context.UserMock.IsInRole("Role"),
                           "This method should not throw.");
        }
コード例 #2
0
        public void User()
        {
            WebContextMock     context        = new WebContextMock();
            AuthenticationMock authentication = new AuthenticationMock();

            PropertyChangedEventArgs    args    = null;
            PropertyChangedEventHandler handler = (sender, e) =>
            {
                if (e.PropertyName == "User")
                {
                    Assert.IsNull(args,
                                  "There should only be a single \"User\" event. The args should be null.");
                    args = e;

                    Assert.AreEqual(authentication.User, context.UserMock,
                                    "Users should be equal.");
                    Assert.AreEqual(context.Authentication.User, context.UserMock,
                                    "User and Authentication.User should be identical.");
                }
            };

            ((INotifyPropertyChanged)context).PropertyChanged += handler;

            Assert.IsNotNull(context.UserMock,
                             "User should not be null.");
            Assert.AreEqual(context.Authentication.User, context.UserMock,
                            "User and Authentication.User should be identical.");

            context.Authentication = authentication;

            Assert.IsNotNull(args,
                             "A User property change should have occurred.");

            ((INotifyPropertyChanged)context).PropertyChanged -= handler;
        }
コード例 #3
0
        public void CurrentThrowsWithZeroInstances()
        {
#if SILVERLIGHT
            Application app = Application.Current;
            Assert.IsNotNull(app,
                             "Application should not be null.");
#endif
            ExceptionHelper.ExpectException <InvalidOperationException>(
                () => Assert.IsNull(WebContextBase.Current, "This should fail."));

            WebContextMock context = new WebContextMock(true);

            Assert.AreEqual(context, WebContextBase.Current,
                            "Contexts should be equal.");

            ExceptionHelper.ExpectException <InvalidOperationException>(
                () => new WebContextMock(true));
        }
コード例 #4
0
        public void RaisePropertyChanged()
        {
            WebContextMock context      = new WebContextMock();
            string         propertyName = string.Empty;

            PropertyChangedEventArgs    args    = null;
            PropertyChangedEventHandler handler = (sender, e) =>
            {
                Assert.IsNull(args,
                              "There should only be a single event. The args should be null.");
                args = e;

                Assert.AreEqual(propertyName, e.PropertyName,
                                "Property names should be equal.");
            };

            ((INotifyPropertyChanged)context).PropertyChanged += handler;

            ExceptionHelper.ExpectArgumentNullException(
                () => context.RaisePropertyChangedMock(null), "propertyName");
            ExceptionHelper.ExpectArgumentNullException(
                () => context.RaisePropertyChangedMock(string.Empty), "propertyName");

            propertyName = "Property 1";

            context.RaisePropertyChangedMock(propertyName);
            Assert.IsNotNull(args,
                             "A change event should have occurred.");

            args = null;

            propertyName = "Property 2";
            context.RaisePropertyChangedMock(propertyName);
            Assert.IsNotNull(args,
                             "A change event should have occurred.");

            ((INotifyPropertyChanged)context).PropertyChanged -= handler;
        }
コード例 #5
0
        public void Authentication()
        {
            WebContextMock        context        = new WebContextMock();
            AuthenticationService authentication = new AuthenticationMock();

            PropertyChangedEventArgs    authenticationArgs = null;
            PropertyChangedEventArgs    userArgs           = null;
            PropertyChangedEventHandler handler            = (sender, e) =>
            {
                if (e.PropertyName == "Authentication")
                {
                    Assert.IsNull(authenticationArgs,
                                  "There should only be a single \"Authentication\" event. The args should be null.");
                    authenticationArgs = e;

                    Assert.AreEqual(authentication, context.Authentication,
                                    "Authentication contexts should be equal.");
                    Assert.AreEqual(authentication.User, context.UserMock,
                                    "Users should be equal.");
                }
                else if (e.PropertyName == "User")
                {
                    Assert.IsNull(userArgs,
                                  "There should only be a single \"User\" event. The args should be null.");
                    userArgs = e;

                    Assert.AreEqual(authentication, context.Authentication,
                                    "Authentication contexts should be equal.");
                    Assert.AreEqual(authentication.User, context.UserMock,
                                    "Users should be equal.");
                }
                else
                {
                    Assert.Fail("There should not be any other property change events.");
                }
            };

            ((INotifyPropertyChanged)context).PropertyChanged += handler;

            Assert.IsNotNull(context.Authentication,
                             "Authentication should not be null.");

            AuthenticationService original = context.Authentication;

            context.Authentication = authentication;

            Assert.IsNotNull(authenticationArgs,
                             "An Authentication property change should have occurred.");
            Assert.IsNotNull(userArgs,
                             "A User property change should have occurred.");

            // Reset values for the event handler
            authentication     = original;
            authenticationArgs = null;
            userArgs           = null;

            context.Authentication = original;

            Assert.IsNotNull(authenticationArgs,
                             "An Authentication property change should have occurred.");
            Assert.IsNotNull(userArgs,
                             "A User property change should have occurred.");

            ((INotifyPropertyChanged)context).PropertyChanged -= handler;
        }
コード例 #6
0
        public void DefaultAuthentication()
        {
            WebContextMock context = new WebContextMock();

            Assert.IsNotNull(context.Authentication,
                "Authentication should not be null.");

            ExceptionHelper.ExpectException<NotSupportedException>(
                () => context.Authentication.Login(null));
            ExceptionHelper.ExpectException<NotSupportedException>(
                () => context.Authentication.Logout(false));
            ExceptionHelper.ExpectException<NotSupportedException>(
                () => context.Authentication.LoadUser());
            ExceptionHelper.ExpectException<NotSupportedException>(
                () => context.Authentication.SaveUser(false));

            Assert.AreEqual(context.Authentication.User, context.UserMock,
                "Users should be equal.");
            Assert.IsNotNull(context.UserMock,
                "User should not be null.");
            Assert.IsNotNull(context.UserMock.Identity,
                "Identity should not be null.");
            Assert.IsNotNull(context.UserMock.Identity.AuthenticationType,
                "Authentication type should not be null.");
            Assert.IsFalse(context.UserMock.Identity.IsAuthenticated,
                "Authentication state should be false.");
            Assert.IsNotNull(context.UserMock.Identity.Name,
                "Name should not be null.");

            Assert.IsFalse(context.UserMock.IsInRole("Role"),
                "This method should not throw.");
        }
コード例 #7
0
        public void RaisePropertyChanged()
        {
            WebContextMock context = new WebContextMock();
            string propertyName = string.Empty;

            PropertyChangedEventArgs args = null;
            PropertyChangedEventHandler handler = (sender, e) =>
            {
                Assert.IsNull(args,
                    "There should only be a single event. The args should be null.");
                args = e;

                Assert.AreEqual(propertyName, e.PropertyName,
                    "Property names should be equal.");
            };
            ((INotifyPropertyChanged)context).PropertyChanged += handler;

            ExceptionHelper.ExpectArgumentNullException(
                () => context.RaisePropertyChangedMock(null), "propertyName");
            ExceptionHelper.ExpectArgumentNullException(
                () => context.RaisePropertyChangedMock(string.Empty), "propertyName");

            propertyName = "Property 1";

            context.RaisePropertyChangedMock(propertyName);
            Assert.IsNotNull(args,
                "A change event should have occurred.");

            args = null;

            propertyName = "Property 2";
            context.RaisePropertyChangedMock(propertyName);
            Assert.IsNotNull(args,
                "A change event should have occurred.");

            ((INotifyPropertyChanged)context).PropertyChanged -= handler;
        }
コード例 #8
0
        public void User()
        {
            WebContextMock context = new WebContextMock();
            AuthenticationMock authentication = new AuthenticationMock();

            PropertyChangedEventArgs args = null;
            PropertyChangedEventHandler handler = (sender, e) =>
            {
                if (e.PropertyName == "User")
                {
                    Assert.IsNull(args,
                        "There should only be a single \"User\" event. The args should be null.");
                    args = e;

                    Assert.AreEqual(authentication.User, context.UserMock,
                        "Users should be equal.");
                    Assert.AreEqual(context.Authentication.User, context.UserMock,
                        "User and Authentication.User should be identical.");
                }
            };
            ((INotifyPropertyChanged)context).PropertyChanged += handler;

            Assert.IsNotNull(context.UserMock,
                "User should not be null.");
            Assert.AreEqual(context.Authentication.User, context.UserMock,
                "User and Authentication.User should be identical.");

            context.Authentication = authentication;

            Assert.IsNotNull(args,
                "A User property change should have occurred.");

            ((INotifyPropertyChanged)context).PropertyChanged -= handler;
        }
コード例 #9
0
        public void Authentication()
        {
            WebContextMock context = new WebContextMock();
            AuthenticationService authentication = new AuthenticationMock();

            PropertyChangedEventArgs authenticationArgs = null;
            PropertyChangedEventArgs userArgs = null;
            PropertyChangedEventHandler handler = (sender, e) =>
            {
                if (e.PropertyName == "Authentication")
                {
                    Assert.IsNull(authenticationArgs,
                        "There should only be a single \"Authentication\" event. The args should be null.");
                    authenticationArgs = e;

                    Assert.AreEqual(authentication, context.Authentication,
                        "Authentication contexts should be equal.");
                    Assert.AreEqual(authentication.User, context.UserMock,
                        "Users should be equal.");
                }
                else if (e.PropertyName == "User")
                {
                    Assert.IsNull(userArgs,
                        "There should only be a single \"User\" event. The args should be null.");
                    userArgs = e;

                    Assert.AreEqual(authentication, context.Authentication,
                        "Authentication contexts should be equal.");
                    Assert.AreEqual(authentication.User, context.UserMock,
                        "Users should be equal.");
                }
                else
                {
                    Assert.Fail("There should not be any other property change events.");
                }
            };
            ((INotifyPropertyChanged)context).PropertyChanged += handler;

            Assert.IsNotNull(context.Authentication,
                "Authentication should not be null.");

            AuthenticationService original = context.Authentication;

            context.Authentication = authentication;

            Assert.IsNotNull(authenticationArgs,
                "An Authentication property change should have occurred.");
            Assert.IsNotNull(userArgs,
                "A User property change should have occurred.");

            // Reset values for the event handler
            authentication = original;
            authenticationArgs = null;
            userArgs = null;

            context.Authentication = original;

            Assert.IsNotNull(authenticationArgs,
                "An Authentication property change should have occurred.");
            Assert.IsNotNull(userArgs,
                "A User property change should have occurred.");

            ((INotifyPropertyChanged)context).PropertyChanged -= handler;
        }
コード例 #10
0
        public void CurrentThrowsWithZeroInstances()
        {
            Application app = Application.Current;
            Assert.IsNotNull(app,
                "Application should not be null.");

            ExceptionHelper.ExpectException<InvalidOperationException>(
                () => Assert.IsNull(WebContextBase.Current, "This should fail."));

            WebContextMock context = new WebContextMock(true);

            Assert.AreEqual(context, WebContextBase.Current,
                "Contexts should be equal.");

            ExceptionHelper.ExpectException<InvalidOperationException>(
                () => new WebContextMock(true));
        }