Ejemplo n.º 1
0
        public void ConversionTable_GetConversionValueWithNullUnit()
        {
            var row1 = new List <string> {
                "Energy", "Erg", "Joule", "Kilocalorie", "Kilowatt hour"
            };
            var row2 = new List <string> {
                "Erg", "1", "1.00E-07", "2.39E-11", "2.78E-14"
            };
            var row3 = new List <string> {
                "Joule", "", "1", ".000239006", "2.78E-07"
            };
            var row4 = new List <string> {
                "Kilocalorie", "", "", "1", ".00116222"
            };
            var row5 = new List <string> {
                "Kilowatt hour", "", "", "", "1"
            };

            var table = new List <List <string> >();

            table.Add(row1);
            table.Add(row2);
            table.Add(row3);
            table.Add(row4);
            table.Add(row5);

            var conversionTable = new ConversionTable(table, table[0][0]);
            var conversionValue = conversionTable.GetConversionValue(null, "Kilocalorie");
            var expectedValue   = new ConversionValue();

            Assert.AreEqual(expectedValue, conversionValue);
        }
Ejemplo n.º 2
0
        public void ConversionValue_ComputationOrderReversed()
        {
            var valueInJoules = new ConversionValue(151320d, new[] { "Joules" }, null, "Energy");
            var joulesToKCal  = new ConversionValue(0.000239006, new[] { "Calorie" }, new[] { "Joules" }, "Energy");
            var valueInKCal   = joulesToKCal * valueInJoules;

            Assert.AreEqual("36.16638792 Calorie", valueInKCal.ToString());
        }
Ejemplo n.º 3
0
        public void ConversionValue_AllValuesUnitless()
        {
            var valueInCM         = new ConversionValue(200d, null, null, "length");
            var centimetersToFeet = new ConversionValue(0.0328084, null, null, "length");
            var valueInFeet       = valueInCM * centimetersToFeet;

            Assert.AreEqual(valueInFeet.Value.ToString(), valueInFeet.ToString());
        }
Ejemplo n.º 4
0
        public void ConversionValue_EmptyStringUnits_UnitCanceling()
        {
            var valueInCM         = new ConversionValue(200d, new[] { string.Empty }, new[] { string.Empty }, "length");
            var centimetersToFeet = new ConversionValue(0.0328084, new[] { "feet" }, new[] { "centimeter" }, "length");
            var valueInFeet       = valueInCM * centimetersToFeet;

            Assert.AreEqual("6.56168 feet per centimeter", valueInFeet.ToString());
        }
Ejemplo n.º 5
0
        public void ConversionValue_RegularUnitConversion_ProperOperation()
        {
            var valueInJoules = new ConversionValue(151320d, new[] { "Joules" }, null, "Energy");
            var joulesToKCal  = new ConversionValue(0.000239006, new[] { "Calorie" }, new[] { "Joules" }, "Energy");
            var valueInKCal   = valueInJoules * joulesToKCal;

            Assert.AreEqual("36.16638792 Calorie", valueInKCal.ToString());
        }
Ejemplo n.º 6
0
        public void ConversionValue_CompoundUnitConversion_ProperOperation()
        {
            var valueInFeetPerSecond = new ConversionValue(46d, new[] { "feet" }, new[] { "second" }, "velocity");
            var feetToMiles          = new ConversionValue(0.000189394, new[] { "miles" }, new[] { "feet" }, "length");
            var secondToHour         = new ConversionValue(3600d, new[] { "second" }, new[] { "hour" }, "time");
            var valueInMPH           = valueInFeetPerSecond * feetToMiles * secondToHour;

            valueInMPH.Value = System.Math.Round(valueInMPH.Value, 4);

            Assert.AreEqual("31.3636 miles per hour", valueInMPH.ToString());
        }
Ejemplo n.º 7
0
        public void ConversionValue_EqualsOther()
        {
            var valueInInches      = new ConversionValue(15d, new[] { "Inches" }, null, "Length");
            var otherValueInInches = new ConversionValue(15d, new[] { "Inches" }, null, "Length");

            var valueInFeet       = new ConversionValue(1.25, new[] { "Feet" }, null, "Length");
            var feetToInches      = new ConversionValue(12d, new[] { "Inches" }, new[] { "Feet" }, "Length");
            var convertedToInches = valueInFeet * feetToInches;

            Assert.IsTrue(valueInInches.Equals(otherValueInInches));
            Assert.IsTrue(otherValueInInches.Equals(valueInInches));

            if (valueInInches.Equals(otherValueInInches) && otherValueInInches.Equals(convertedToInches))
            {
                Assert.IsTrue(valueInInches.Equals(convertedToInches));
            }

            Assert.IsFalse(valueInInches.Equals(null));
        }
Ejemplo n.º 8
0
        public void Stoichiometry_CreateConversionTable()
        {
            ChemicalEquation.PTable = new PeriodicTable("..\\..\\..\\Chemistry-Solver\\data\\ElementData.csv");

            var stoichiometry = new Stoichiometry();

            var equation = new ChemicalEquation("1H_(2) + 1O_(2) --> 1H_(2)O_(1)");

            equation.Balance();

            var canceledUnit  = $"{equation.Reactants[0].Item2}{equation.Reactants[0].Item1.ToString()} moles";
            var remainingUnit = $"{equation.Reactants[1].Item2}{equation.Reactants[1].Item1.ToString()} moles";

            stoichiometry.CreateConversionTable(equation);

            stoichiometry.UnitConverter.InputValue      = new ConversionValue(14d, new[] { canceledUnit }, null, equation.ToString());
            stoichiometry.UnitConverter.ConversionRatio = stoichiometry.UnitConverter.ConversionTable.GetConversionValue(canceledUnit, remainingUnit);

            var actual   = stoichiometry.UnitConverter.PerformConversion();
            var expected = new ConversionValue(7d, new[] { remainingUnit }, null, equation.ToString());

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 9
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            // Do nothing
        }
        else
        {
            if (SettingsKeyInfoProvider.GetBoolValue(SiteContext.CurrentSiteName + ".CMSEnableWindowsLiveID"))
            {
                string siteName = SiteContext.CurrentSiteName;
                if (!string.IsNullOrEmpty(siteName))
                {
                    // Get LiveID settings
                    string appId  = SettingsKeyInfoProvider.GetStringValue(siteName + ".CMSApplicationID");
                    string secret = SettingsKeyInfoProvider.GetStringValue(siteName + ".CMSApplicationSecret");

                    if (!WindowsLiveLogin.UseServerSideAuthorization)
                    {
                        // Add windows live ID script
                        ScriptHelper.RegisterClientScriptInclude(Page, typeof(string), "WLScript", LIVE_CONNECT_API_URL);

                        // Add login functions
                        String loginLiveIDClientScript = @"

                            function signUserIn() {
                                var scopesArr = ['wl.signin'];
                                WL.login({ scope: scopesArr });
                            }
                    
                            function refreshLiveID(param)
                            {
                                " + ControlsHelper.GetPostBackEventReference(btnHidden, "#").Replace("'#'", "param") + @" 
                            }                                       
                        ";

                        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ClientInitLiveIDScript", ScriptHelper.GetScript(loginLiveIDClientScript));
                    }

                    // Check valid Windows LiveID parameters
                    if ((appId == string.Empty) || (secret == string.Empty))
                    {
                        lblError.Visible = true;
                        lblError.Text    = GetString("liveid.incorrectsettings");
                        return;
                    }

                    WindowsLiveLogin wll = new WindowsLiveLogin(appId, secret);

                    // If user is already authenticated
                    if (AuthenticationHelper.IsAuthenticated())
                    {
                        // If signout should be visible and user has LiveID registered

                        if (ShowSignOut && !String.IsNullOrEmpty(MembershipContext.AuthenticatedUser.UserSettings.WindowsLiveID))
                        {
                            // Get data from auth cookie
                            string[] userData = AuthenticationHelper.GetUserDataFromAuthCookie();

                            // Check if user has truly logged in by LiveID
                            if ((userData != null) && (Array.IndexOf(userData, "liveidlogin") >= 0))
                            {
                                // Redirect to Windows Live and back to "home" page
                                string defaultAliasPath = SettingsKeyInfoProvider.GetStringValue(siteName + ".CMSDefaultAliasPath");
                                string url    = DocumentURLProvider.GetUrl(defaultAliasPath);
                                string navUrl = wll.GetLogoutUrl(URLHelper.GetAbsoluteUrl(url));

                                // If text is set use text/button link
                                if (!string.IsNullOrEmpty(SignOutText))
                                {
                                    // Button link
                                    if (ShowAsButton)
                                    {
                                        btnSignOut.CommandArgument = navUrl;
                                        btnSignOut.Text            = SignOutText;
                                        btnSignOut.Visible         = true;
                                    }
                                    // Text link
                                    else
                                    {
                                        btnSignOutLink.CommandArgument = navUrl;
                                        btnSignOutLink.Text            = SignOutText;
                                        btnSignOutLink.Visible         = true;
                                    }
                                }
                                // Image link
                                else
                                {
                                    btnSignOutImage.CommandArgument = navUrl;
                                    btnSignOutImage.ImageUrl        = ResolveUrl(SignOutImageURL);
                                    btnSignOutImage.Visible         = true;
                                    btnSignOut.Text = GetString("webparts_membership_signoutbutton.signout");
                                }
                            }
                        }
                        else
                        {
                            Visible = false;
                        }
                    }
                    // Sign In
                    else
                    {
                        // Create return URL
                        string returnUrl = QueryHelper.GetText("returnurl", "");
                        returnUrl = (returnUrl == String.Empty) ? RequestContext.CurrentURL : returnUrl;

                        // Create parameters for LiveID request URL
                        String[] parameters = new String[3];
                        parameters[0] = returnUrl;
                        parameters[1] = TrackConversionName;
                        parameters[2] = ConversionValue.ToString();
                        SessionHelper.SetValue("LiveIDInformtion", parameters);

                        returnUrl = wll.GetLoginUrl();

                        // Get App ID
                        appId = SettingsKeyInfoProvider.GetStringValue(siteName + ".CMSApplicationID");

                        // Create full LiveID request URL
                        string navUrl = AUTHORIZATION_URL + "?client_id=" + appId + "&redirect=true&scope=wl.signin&response_type=code&redirect_uri=" + HttpUtility.UrlEncode(returnUrl);

                        // If text is set use text/button link
                        if (!string.IsNullOrEmpty(SignInText))
                        {
                            // Button link
                            if (ShowAsButton)
                            {
                                AssignButtonControl(navUrl, returnUrl, appId);
                                btnSignIn.Text = SignInText;
                            }
                            // Text link
                            else
                            {
                                AssignHyperlinkControl(navUrl, returnUrl, appId);
                                lnkSignIn.Text = SignInText;
                            }
                        }
                        // Image link
                        else
                        {
                            AssignHyperlinkControl(navUrl, returnUrl, appId);
                            lnkSignIn.ImageUrl = ResolveUrl(SignInImageURL);
                            lnkSignIn.Text     = GetString("webparts_membership_signoutbutton.signin");
                        }
                    }
                }
            }
            else
            {
                // Error label is displayed in Design mode when Windows Live ID is disabled
                if (PortalContext.IsDesignMode(PortalContext.ViewMode))
                {
                    StringBuilder parameter = new StringBuilder();
                    parameter.Append(UIElementInfoProvider.GetApplicationNavigationString("cms", "Settings") + " -> ");
                    parameter.Append(GetString("settingscategory.cmsmembership") + " -> ");
                    parameter.Append(GetString("settingscategory.cmsmembershipauthentication") + " -> ");
                    parameter.Append(GetString("settingscategory.cmswindowsliveid"));
                    if (MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin))
                    {
                        // Make it link for Admin
                        parameter.Insert(0, "<a href=\"" + URLHelper.GetAbsoluteUrl(UIContextHelper.GetApplicationUrl("cms", "settings")) + "\" target=\"_top\">");
                        parameter.Append("</a>");
                    }

                    lblError.Text    = String.Format(GetString("mem.liveid.disabled"), parameter);
                    lblError.Visible = true;
                }
                else
                {
                    Visible = false;
                }
            }
        }
    }