public void Login()
        {
            DateTime start, end;
            TimeSpan duration1, duration2;

            // This is a copy of the actual code in WebServiceBase.Login.
            // Can not use an instance of WebServiceBase if we would like
            // to test caching since WebServiceBase.Login uses class
            // WebServiceContext which needs ASP.NET to cache information.
            using (WebServiceContext context = new WebServiceContextCached(Settings.Default.TestUserName,
                                                                           ApplicationIdentifier.UserAdmin.ToString()))
            {
                try
                {
                    start = DateTime.Now;
                    WebServiceData.UserManager.Login(context,
                                                     Settings.Default.TestUserName,
                                                     Settings.Default.TestPassword,
                                                     ApplicationIdentifier.UserAdmin.ToString(),
                                                     false);
                    end       = DateTime.Now;
                    duration1 = end - start;
                    Debug.WriteLine("Duration during first loggin = " + duration1.TotalMilliseconds);

                    // Now everything should be cached.
                    start = DateTime.Now;
                    WebServiceData.UserManager.Login(context,
                                                     Settings.Default.TestUserName,
                                                     Settings.Default.TestPassword,
                                                     ApplicationIdentifier.UserAdmin.ToString(),
                                                     false);
                    end       = DateTime.Now;
                    duration2 = end - start;
                    Debug.WriteLine("Duration during second loggin = " + duration2.TotalMilliseconds);
                    Assert.IsTrue(duration2.TotalMilliseconds <= duration1.TotalMilliseconds);
                }
                catch (Exception exception)
                {
                    WebServiceData.LogManager.LogError(context, exception);
                    throw;
                }
            }
        }
        public void CurrentRoles()
        {
            WebClientInformation clientInformation;
            WebClientToken       clientToken;
            WebServiceContext    context;

            // Test without selected role
            clientToken = new WebClientToken(Settings.Default.TestUserName,
                                             ApplicationIdentifier.UserAdmin.ToString(),
                                             WebServiceData.WebServiceManager.Key);
            clientInformation                   = new WebClientInformation();
            clientInformation.Locale            = new WebLocale();
            clientInformation.Locale.Id         = 581;
            clientInformation.Locale.ISOCode    = "se-SV";
            clientInformation.Locale.Name       = "Swedish (Sweden)";
            clientInformation.Locale.NativeName = "svenska (Sverige)";
            clientInformation.Token             = clientToken.Token;
            context = new WebServiceContextCached(clientInformation);
            Assert.IsTrue(context.CurrentRoles.IsNotEmpty());
            Assert.IsTrue(1 < context.CurrentRoles.Count);

            // Test with selected role.
            clientToken = new WebClientToken(Settings.Default.TestUserName,
                                             ApplicationIdentifier.UserAdmin.ToString(),
                                             WebServiceData.WebServiceManager.Key);
            clientInformation                   = new WebClientInformation();
            clientInformation.Role              = new WebRole();
            clientInformation.Role.Id           = Settings.Default.TestRoleId;
            clientInformation.Role.Name         = "No role name";
            clientInformation.Locale            = new WebLocale();
            clientInformation.Locale.Id         = 581;
            clientInformation.Locale.ISOCode    = "se-SV";
            clientInformation.Locale.Name       = "Swedish (Sweden)";
            clientInformation.Locale.NativeName = "svenska (Sverige)";
            clientInformation.Token             = clientToken.Token;
            context = new WebServiceContextCached(clientInformation);
            Assert.IsTrue(context.CurrentRoles.IsNotEmpty());
            Assert.AreEqual(1, context.CurrentRoles.Count);
            Assert.AreEqual(Settings.Default.TestRoleId, context.CurrentRoles[0].Id);
        }
        public void ConstructorCurrentRoleError()
        {
            WebClientInformation clientInformation;
            WebClientToken       clientToken;
            WebServiceContext    context;

            clientToken = new WebClientToken(Settings.Default.TestUserName,
                                             ApplicationIdentifier.EVA.ToString(),
                                             WebServiceData.WebServiceManager.Key);
            clientInformation                   = new WebClientInformation();
            clientInformation.Role              = new WebRole();
            clientInformation.Role.Id           = -42;
            clientInformation.Role.Name         = "No role name";
            clientInformation.Locale            = new WebLocale();
            clientInformation.Locale.Id         = 581;
            clientInformation.Locale.ISOCode    = "se-SV";
            clientInformation.Locale.Name       = "Swedish (Sweden)";
            clientInformation.Locale.NativeName = "svenska (Sverige)";
            clientInformation.Token             = clientToken.Token;
            context = new WebServiceContextCached(clientInformation);
            Assert.IsNotNull(context);
        }