//****************************************************************************************************** // AdapterTest.cs - Gbtc // // Copyright © 2012, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may // not use this file except in compliance with the License. You may obtain a copy of the License at: // // http://www.opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 02/01/2011 - Denis Kholine // 12/13/2012 - Starlynn Danyelle Gilliam // Modified Header. // //****************************************************************************************************** #region [ University of Illinois/NCSA Open Source License ] /* Copyright © <2012> All rights reserved. Developed by: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal with the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers. • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation and/or other materials provided with the distribution. • Neither the names of , nor the names of its contributors may be used to endorse or promote products derived from this Software without specific prior written permission. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. */ #endregion using System; using GSF.Adapters; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace GSF.Core.Tests { /// ///This is a test class for AdapterTest and is intended ///to contain all AdapterTest Unit Tests /// [TestClass] public class AdapterTest : IDisposable { #region DISPOSE private bool isDisposed; ~AdapterTest() { Dispose(false); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool isDisposing) { if (!isDisposed) { if (isDisposing) { target.Dispose(); } isDisposed = false; } } #endregion private TestContext testContextInstance; /// ///Gets or sets the test context which provides ///information about and functionality for the current test run. /// public TestContext TestContext { get { return testContextInstance; } set { testContextInstance = value; } } #region Additional test attributes Adapter target; // //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test [TestInitialize] public void MyTestInitialize() { target = new Adapter(); } //Use TestCleanup to run code after each test has run [TestCleanup] public void MyTestCleanup() { target.Dispose(); } #endregion /// /// A test for Adapter Constructor /// Initializes a new instance of the . /// [TestMethod] public void AdapterConstructorTest() { Assert.IsInstanceOfType(target, typeof(Adapter)); Assert.IsNotNull(target); } /// ///A test for Dispose /// [TestMethod] [DeploymentItem("GSF.Core.dll")] public void DisposeTest() { try { target.Dispose(); } catch { Assert.Inconclusive("Disposing error."); } } /// /// A test for Initialize /// Initializes the . /// [TestMethod] public void InitializeTest() { try { target.Initialize(); } catch { Assert.Inconclusive("Can't initialize Adapter instance."); } } /// ///A test for LoadSettings /// [TestMethod] public void LoadSettingsTest() { try { target.LoadSettings(); } catch { Assert.Inconclusive("Can't load settings."); } } /// /// A test for OnDisposed /// Raises the event. /// [TestMethod] [DeploymentItem("GSF.Core.dll")] public void OnDisposedTest() { try { target.Dispose(); } catch { Assert.Fail(); } } ///// /////A test for OnExecutionException ///// //[TestMethod] //[DeploymentItem("GSF.Core.dll")] //public void OnExecutionExceptionTest() //{ // // Creation of the private accessor for 'Microsoft.VisualStudio.TestTools.TypesAndSymbols.Assembly' failed // Assert.Inconclusive("Exception verification implementation needed"); //} ///// ///// A test for OnStatusUpdate ///// Raises the event. ///// ///// to send to event. ///// Update message to send to event. ///// Arguments to be used when formatting the . //[TestMethod] //[DeploymentItem("GSF.Core.dll")] //public void OnStatusUpdateTest() //{ // // Creation of the private accessor for 'Microsoft.VisualStudio.TestTools.TypesAndSymbols.Assembly' failed // Assert.Inconclusive("Creation of the private accessor for \'Microsoft.VisualStudio.TestTools.TypesAndSy" + // "mbols.Assembly\' failed"); //} /// /// A test for SaveSettings /// Saves settings to the config file if the property is set to true. /// /// has a value of null or empty string. [TestMethod] public void SaveSettingsTest() { target.PersistSettings = true; try { target.SaveSettings(); } catch { Assert.Inconclusive("Configuration error exception"); } } /// /// A test for Domain /// Gets the in which the is executing. /// [TestMethod] public void DomainTest() { AppDomain actual; actual = target.Domain; Assert.IsNotNull(actual); } /// /// A test for Enabled /// Gets or sets a boolean value that indicates whether the is currently enabled. /// [TestMethod] public void EnabledTest() { bool expected = false; bool actual; target.Enabled = expected; actual = target.Enabled; Assert.AreEqual(expected, actual); } /// /// A test for HostFile /// Gets or sets the path to the file where the is housed. /// /// /// This can be used to update the when changes are made to the file where it is housed. /// [TestMethod] public void HostFileTest() { string expected = "Host File"; string actual; target.HostFile = expected; actual = target.HostFile; Assert.AreEqual(expected, actual); } /// /// A test for MemoryUsage /// Gets the memory utilzation of the in bytes if executing in a separate , otherwise . /// /// /// /// gets updated only after a full blocking collection by (e.g. ). /// /// /// This method always returns under Mono deployments. /// /// [TestMethod] public void MemoryUsageTest() { double actual; if (AppDomain.MonitoringIsEnabled == false) { AppDomain.MonitoringIsEnabled = true; } actual = target.MemoryUsage; Assert.AreNotEqual(Double.NaN, actual); } /// /// A test for Name /// Gets the unique identifier of the . /// [TestMethod] public void NameTest() { string actual; actual = target.Name; Assert.IsNotNull(actual); } /// /// A test for PersistSettings /// Gets or sets a boolean value that indicates whether settings are to be saved to the config file. /// [TestMethod] public void PersistSettingsTest() { bool expected = false; bool actual; target.PersistSettings = expected; actual = target.PersistSettings; Assert.AreEqual(expected, actual); } /// /// A test for ProcessorUsage /// Gets the % processor utilization of the if executing in a separate otherwise . /// /// /// This method always returns under Mono deployments. /// [TestMethod] public void ProcessorUsageTest() { double actual; if (AppDomain.MonitoringIsEnabled == false) { AppDomain.MonitoringIsEnabled = true; } actual = target.ProcessorUsage; Assert.AreNotEqual(Double.NaN, actual); } /// /// A test for SettingsCategory /// Saves settings to the config file if the property is set to true. /// /// has a value of null or empty string. [TestMethod] public void SettingsCategoryTest() { string expected = "Config File"; string actual; target.SettingsCategory = expected; actual = target.SettingsCategory; Assert.AreEqual(expected, actual); } /// /// A test for Status /// Gets the descriptive status of the . /// [TestMethod] public void StatusTest() { string actual; actual = target.Status; Assert.IsNotNull(actual); } /// /// A test for TypeName /// Gets or sets the text representation of the 's . /// /// /// This can be used for looking up the of the when deserializing it using . /// [TestMethod] public void TypeNameTest() { string expected = "GSF.Adapters.Adapter, GSF.Core"; string actual; target.TypeName = expected; actual = target.TypeName; Assert.AreEqual(expected, actual); } } }