Exemple #1
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;
        }
        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;
        }
Exemple #3
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;
        }
        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;
        }