Moved NameValuePair and tests to base Common library for use in other projects.
7e2e0c54
Pedro Silva
committed
succeeded
5 changed files
D20Tek.Common.xml
/D20Tek.Common/D20Tek.Common.xml+38
/D20Tek.Common/D20Tek.Common.xml
Add comment 288 <member name="M:D20Tek.Common.DataTypes.NamedElement`1.GetHashCode">
Add comment 289 <inheritdoc/>
Add comment 290 </member>
Add comment 291 Plus   <member name="T:D20Tek.Common.DataTypes.NameValuePair`1">
Add comment 292 Plus   <summary>
Add comment 293 Plus   Class to encapsulate name value pair.
Add comment 294 Plus   </summary>
Add comment 295 Plus   <typeparam name="TValue">Type of the value.</typeparam>
Add comment 296 Plus   </member>
Add comment 297 Plus   <member name="M:D20Tek.Common.DataTypes.NameValuePair`1.#ctor(System.String,`0)">
Add comment 298 Plus   <summary>
Add comment 299 Plus   Initializes a new instance of the <see cref="T:D20Tek.Common.DataTypes.NameValuePair`1"/> class.
Add comment 300 Plus   </summary>
Add comment 301 Plus   <param name="name">Name to intialize.</param>
Add comment 302 Plus   <param name="value">Value to initialize.</param>
Add comment 303 Plus   </member>
Add comment 304 Plus   <member name="M:D20Tek.Common.DataTypes.NameValuePair`1.#ctor">
Add comment 305 Plus   <summary>
Add comment 306 Plus   Initializes a new instance of the <see cref="T:D20Tek.Common.DataTypes.NameValuePair`1"/> class.
Add comment 307 Plus   Default constructor for serialization.
Add comment 308 Plus   </summary>
Add comment 309 Plus   </member>
Add comment 310 Plus   <member name="P:D20Tek.Common.DataTypes.NameValuePair`1.Name">
Add comment 311 Plus   <summary>
Add comment 312 Plus   Gets or sets the name of this element.
Add comment 313 Plus   </summary>
Add comment 314 Plus   </member>
Add comment 315 Plus   <member name="P:D20Tek.Common.DataTypes.NameValuePair`1.Value">
Add comment 316 Plus   <summary>
Add comment 317 Plus   Gets or sets the value of this element.
Add comment 318 Plus   </summary>
Add comment 319 Plus   </member>
Add comment 320 Plus   <member name="M:D20Tek.Common.DataTypes.NameValuePair`1.ToString">
Add comment 321 Plus   <inheritdoc/>
Add comment 322 Plus   </member>
Add comment 323 Plus   <member name="M:D20Tek.Common.DataTypes.NameValuePair`1.Equals(System.Object)">
Add comment 324 Plus   <inheritdoc/>
Add comment 325 Plus   </member>
Add comment 326 Plus   <member name="M:D20Tek.Common.DataTypes.NameValuePair`1.GetHashCode">
Add comment 327 Plus   <inheritdoc/>
Add comment 328 Plus   </member>
Add comment 291 329 <member name="T:D20Tek.Common.ObservableObject">
Add comment 292 330 <summary>
Add comment 293 331 Observable object with INotifyPropertyChanged implemented.
NameValuePair.cs
/D20Tek.Common.Shared/DataTypes/NameValuePair.cs+80
/D20Tek.Common.Shared/DataTypes/NameValuePair.cs
Add comment 1 Plus  //-----------------------------------------------------------------------
Add comment 2 Plus  // <copyright file="NameValuePair.cs" company="DarthPedro">
Add comment 3 Plus  // Copyright (c) 2020 DarthPedro. All rights reserved.
Add comment 4 Plus  // </copyright>
Add comment 5 Plus  //-----------------------------------------------------------------------
Add comment 6 Plus  // <summary>
Add comment 7 Plus  // This project is licensed under the MIT license.
Add comment 8 Plus  // </summary>
Add comment 9 Plus  //-----------------------------------------------------------------------
Add comment 10 Plus  using System;
Add comment 11 Plus  
Add comment 12 Plus  namespace D20Tek.Common.DataTypes
Add comment 13 Plus  {
Add comment 14 Plus   /// <summary>
Add comment 15 Plus   /// Class to encapsulate name value pair.
Add comment 16 Plus   /// </summary>
Add comment 17 Plus   /// <typeparam name="TValue">Type of the value.</typeparam>
Add comment 18 Plus   public class NameValuePair<TValue>
Add comment 19 Plus   {
Add comment 20 Plus   private string name;
Add comment 21 Plus  
Add comment 22 Plus   /// <summary>
Add comment 23 Plus   /// Initializes a new instance of the <see cref="NameValuePair{TValue}"/> class.
Add comment 24 Plus   /// </summary>
Add comment 25 Plus   /// <param name="name">Name to intialize.</param>
Add comment 26 Plus   /// <param name="value">Value to initialize.</param>
Add comment 27 Plus   public NameValuePair(string name, TValue value)
Add comment 28 Plus   {
Add comment 29 Plus   this.Name = name;
Add comment 30 Plus   this.Value = value;
Add comment 31 Plus   }
Add comment 32 Plus  
Add comment 33 Plus   /// <summary>
Add comment 34 Plus   /// Initializes a new instance of the <see cref="NameValuePair{TValue}"/> class.
Add comment 35 Plus   /// Default constructor for serialization.
Add comment 36 Plus   /// </summary>
Add comment 37 Plus   public NameValuePair()
Add comment 38 Plus   {
Add comment 39 Plus   }
Add comment 40 Plus  
Add comment 41 Plus   /// <summary>
Add comment 42 Plus   /// Gets or sets the name of this element.
Add comment 43 Plus   /// </summary>
Add comment 44 Plus   public string Name
Add comment 45 Plus   {
Add comment 46 Plus   get => this.name;
Add comment 47 Plus   set => this.name = value ?? throw new ArgumentNullException(nameof(this.Name));
Add comment 48 Plus   }
Add comment 49 Plus  
Add comment 50 Plus   /// <summary>
Add comment 51 Plus   /// Gets or sets the value of this element.
Add comment 52 Plus   /// </summary>
Add comment 53 Plus   public TValue Value { get; set; }
Add comment 54 Plus  
Add comment 55 Plus   /// <inheritdoc/>
Add comment 56 Plus   public override string ToString()
Add comment 57 Plus   {
Add comment 58 Plus   return $"[{this.Name}] = {this.Value}";
Add comment 59 Plus   }
Add comment 60 Plus  
Add comment 61 Plus   /// <inheritdoc/>
Add comment 62 Plus   public override bool Equals(object obj)
Add comment 63 Plus   {
Add comment 64 Plus   if (obj == null)
Add comment 65 Plus   {
Add comment 66 Plus   return false;
Add comment 67 Plus   }
Add comment 68 Plus  
Add comment 69 Plus   var other = (NameValuePair<TValue>)obj;
Add comment 70 Plus   return this.Name.Equals(other.Name, StringComparison.InvariantCulture);
Add comment 71 Plus   }
Add comment 72 Plus  
Add comment 73 Plus   /// <inheritdoc/>
Add comment 74 Plus   public override int GetHashCode()
Add comment 75 Plus   {
Add comment 76 Plus   return HashCode.Combine(this.Name);
Add comment 77 Plus   }
Add comment 78 Plus   }
Add comment 79 Plus  }
Add comment 80 Plus  
D20Tek.Common.Shared.projitems
/D20Tek.Common.Shared/D20Tek.Common.Shared.projitems+1
/D20Tek.Common.Shared/D20Tek.Common.Shared.projitems
Add comment 20 <Compile Include="$(MSBuildThisFileDirectory)DataTypes\DiceNotation\TermResult.cs" />
Add comment 21 <Compile Include="$(MSBuildThisFileDirectory)DataTypes\DiceNotation\TermResultListConverter.cs" />
Add comment 22 <Compile Include="$(MSBuildThisFileDirectory)DataTypes\NamedElement.cs" />
Add comment 23 Plus   <Compile Include="$(MSBuildThisFileDirectory)DataTypes\NameValuePair.cs" />
Add comment 23 24 <Compile Include="$(MSBuildThisFileDirectory)DataTypes\ObservableObject.cs" />
Add comment 24 25 <Compile Include="$(MSBuildThisFileDirectory)DataTypes\Collections\IPagedList.cs" />
Add comment 25 26 <Compile Include="$(MSBuildThisFileDirectory)DataTypes\ValueRange.cs" />
D20Tek.Common.Standard.xml
/D20Tek.Common.Standard/D20Tek.Common.Standard.xml+38
/D20Tek.Common.Standard/D20Tek.Common.Standard.xml
Add comment 273 <member name="M:D20Tek.Common.DataTypes.NamedElement`1.GetHashCode">
Add comment 274 <inheritdoc/>
Add comment 275 </member>
Add comment 276 Plus   <member name="T:D20Tek.Common.DataTypes.NameValuePair`1">
Add comment 277 Plus   <summary>
Add comment 278 Plus   Class to encapsulate name value pair.
Add comment 279 Plus   </summary>
Add comment 280 Plus   <typeparam name="TValue">Type of the value.</typeparam>
Add comment 281 Plus   </member>
Add comment 282 Plus   <member name="M:D20Tek.Common.DataTypes.NameValuePair`1.#ctor(System.String,`0)">
Add comment 283 Plus   <summary>
Add comment 284 Plus   Initializes a new instance of the <see cref="T:D20Tek.Common.DataTypes.NameValuePair`1"/> class.
Add comment 285 Plus   </summary>
Add comment 286 Plus   <param name="name">Name to intialize.</param>
Add comment 287 Plus   <param name="value">Value to initialize.</param>
Add comment 288 Plus   </member>
Add comment 289 Plus   <member name="M:D20Tek.Common.DataTypes.NameValuePair`1.#ctor">
Add comment 290 Plus   <summary>
Add comment 291 Plus   Initializes a new instance of the <see cref="T:D20Tek.Common.DataTypes.NameValuePair`1"/> class.
Add comment 292 Plus   Default constructor for serialization.
Add comment 293 Plus   </summary>
Add comment 294 Plus   </member>
Add comment 295 Plus   <member name="P:D20Tek.Common.DataTypes.NameValuePair`1.Name">
Add comment 296 Plus   <summary>
Add comment 297 Plus   Gets or sets the name of this element.
Add comment 298 Plus   </summary>
Add comment 299 Plus   </member>
Add comment 300 Plus   <member name="P:D20Tek.Common.DataTypes.NameValuePair`1.Value">
Add comment 301 Plus   <summary>
Add comment 302 Plus   Gets or sets the value of this element.
Add comment 303 Plus   </summary>
Add comment 304 Plus   </member>
Add comment 305 Plus   <member name="M:D20Tek.Common.DataTypes.NameValuePair`1.ToString">
Add comment 306 Plus   <inheritdoc/>
Add comment 307 Plus   </member>
Add comment 308 Plus   <member name="M:D20Tek.Common.DataTypes.NameValuePair`1.Equals(System.Object)">
Add comment 309 Plus   <inheritdoc/>
Add comment 310 Plus   </member>
Add comment 311 Plus   <member name="M:D20Tek.Common.DataTypes.NameValuePair`1.GetHashCode">
Add comment 312 Plus   <inheritdoc/>
Add comment 313 Plus   </member>
Add comment 276 314 <member name="T:D20Tek.Common.ObservableObject">
Add comment 277 315 <summary>
Add comment 278 316 Observable object with INotifyPropertyChanged implemented.
NameValuePairTests.cs
/D20Tek.Common.UnitTests/Models/NameValuePairTests.cs+114
/D20Tek.Common.UnitTests/Models/NameValuePairTests.cs
Add comment 1 Plus  using D20Tek.Common.DataTypes;
Add comment 2 Plus  using Microsoft.VisualStudio.TestTools.UnitTesting;
Add comment 3 Plus  using System;
Add comment 4 Plus  using System.Diagnostics.CodeAnalysis;
Add comment 5 Plus  
Add comment 6 Plus  namespace D20Tek.Common.UnitTests.Models
Add comment 7 Plus  {
Add comment 8 Plus   [TestClass]
Add comment 9 Plus   public class NameValuePairTests
Add comment 10 Plus   {
Add comment 11 Plus   [TestMethod]
Add comment 12 Plus   public void Constructor()
Add comment 13 Plus   {
Add comment 14 Plus   // setup
Add comment 15 Plus  
Add comment 16 Plus   // test
Add comment 17 Plus   var pair = new NameValuePair<int>("TestName", 42);
Add comment 18 Plus  
Add comment 19 Plus   // validate
Add comment 20 Plus   Assert.IsNotNull(pair);
Add comment 21 Plus   Assert.AreEqual("TestName", pair.Name);
Add comment 22 Plus   Assert.AreEqual(42, pair.Value);
Add comment 23 Plus   }
Add comment 24 Plus  
Add comment 25 Plus   [TestMethod]
Add comment 26 Plus   public void ToStringTest()
Add comment 27 Plus   {
Add comment 28 Plus   // setup
Add comment 29 Plus   var pair = new NameValuePair<string>("TestName", "lorem ipsum");
Add comment 30 Plus  
Add comment 31 Plus   // test
Add comment 32 Plus   var s = pair.ToString();
Add comment 33 Plus  
Add comment 34 Plus   // validate
Add comment 35 Plus   Assert.IsNotNull(pair);
Add comment 36 Plus   Assert.AreEqual("TestName", pair.Name);
Add comment 37 Plus   Assert.AreEqual("lorem ipsum", pair.Value);
Add comment 38 Plus   Assert.AreEqual("[TestName] = lorem ipsum", s);
Add comment 39 Plus   }
Add comment 40 Plus  
Add comment 41 Plus   [TestMethod]
Add comment 42 Plus   public void Equals_ShouldBeTrue()
Add comment 43 Plus   {
Add comment 44 Plus   // setup
Add comment 45 Plus   var pair1 = new NameValuePair<Guid>("SameName", Guid.NewGuid());
Add comment 46 Plus   var pair2 = new NameValuePair<Guid>("SameName", Guid.NewGuid());
Add comment 47 Plus  
Add comment 48 Plus   // test
Add comment 49 Plus   var e = pair1.Equals(pair2);
Add comment 50 Plus  
Add comment 51 Plus   // validate
Add comment 52 Plus   Assert.IsTrue(e);
Add comment 53 Plus   }
Add comment 54 Plus  
Add comment 55 Plus   [TestMethod]
Add comment 56 Plus   public void Equals_ShouldBeFalse()
Add comment 57 Plus   {
Add comment 58 Plus   // setup
Add comment 59 Plus   var pair1 = new NameValuePair<bool>("Name1", true);
Add comment 60 Plus   var pair2 = new NameValuePair<bool>("Name2", true);
Add comment 61 Plus  
Add comment 62 Plus   // test
Add comment 63 Plus   var e = pair1.Equals(pair2);
Add comment 64 Plus  
Add comment 65 Plus   // validate
Add comment 66 Plus   Assert.IsFalse(e);
Add comment 67 Plus   }
Add comment 68 Plus  
Add comment 69 Plus   [TestMethod]
Add comment 70 Plus   public void Equals_NullOther()
Add comment 71 Plus   {
Add comment 72 Plus   // setup
Add comment 73 Plus   var pair1 = new NameValuePair<string>
Add comment 74 Plus   {
Add comment 75 Plus   Name = "Name1",
Add comment 76 Plus   Value = "test",
Add comment 77 Plus   };
Add comment 78 Plus  
Add comment 79 Plus   // test
Add comment 80 Plus   var e = pair1.Equals(null);
Add comment 81 Plus  
Add comment 82 Plus   // validate
Add comment 83 Plus   Assert.IsFalse(e);
Add comment 84 Plus   }
Add comment 85 Plus  
Add comment 86 Plus   [TestMethod]
Add comment 87 Plus   public void GetHashCodeTest()
Add comment 88 Plus   {
Add comment 89 Plus   // setup
Add comment 90 Plus   var pair = new NameValuePair<string>("TestName", "lorem ipsum");
Add comment 91 Plus   var expected = HashCode.Combine("TestName");
Add comment 92 Plus  
Add comment 93 Plus   // test
Add comment 94 Plus   var h = pair.GetHashCode();
Add comment 95 Plus  
Add comment 96 Plus   // validate
Add comment 97 Plus   Assert.AreEqual(expected, h);
Add comment 98 Plus   }
Add comment 99 Plus  
Add comment 100 Plus   [TestMethod]
Add comment 101 Plus   [ExpectedException(typeof(ArgumentNullException))]
Add comment 102 Plus   [ExcludeFromCodeCoverage]
Add comment 103 Plus   public void Constructor_WithNullName()
Add comment 104 Plus   {
Add comment 105 Plus   // setup
Add comment 106 Plus  
Add comment 107 Plus   // test
Add comment 108 Plus   _ = new NameValuePair<int>(null, 42);
Add comment 109 Plus  
Add comment 110 Plus   // validate
Add comment 111 Plus   }
Add comment 112 Plus   }
Add comment 113 Plus  }
Add comment 114 Plus