Skip to content
This repository was archived by the owner on Jul 27, 2021. It is now read-only.

Minor formatting cleanup, base class implementation, some minor refactoring and upgrade to .NET 4.62. #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Minor cleanup to (mostly) unit tests.
  • Loading branch information
ats-ccochran committed Jul 17, 2017
commit 4b0666d5171114e11b93adb297440a21a715234c
2 changes: 1 addition & 1 deletion IotaCSharpApi/Api/Utils/Checksum.cs
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ public static class Checksum
/// <param name="address">An address without checksum</param>
/// <returns>The address with the appended checksum </returns>
/// <exception cref="InvalidAddressException">is thrown when an invalid address is provided</exception>
public static string AddChecksum(string address)
public static string AddChecksum(this string address)
{
InputValidator.CheckAddress(address);
string addressWithChecksum = address;
8 changes: 4 additions & 4 deletions IotaCSharpApi/Api/Utils/IotaUnitConverter.cs
Original file line number Diff line number Diff line change
@@ -16,14 +16,14 @@ public class IotaUnitConverter
/// <returns>the specified amount in the target unit</returns>
public static double ConvertUnits(long amount, IotaUnits fromUnit, IotaUnits toUnit)
{
long amountInSource = (long) (amount*Math.Pow(10, (int) fromUnit));
long amountInSource = (long)(amount * Math.Pow(10, (int)fromUnit));
return ConvertUnits(amountInSource, toUnit);
}

private static double ConvertUnits(long amount, IotaUnits toUnit)
{
int base10NormalizationExponent = (int) toUnit;
return (amount/Math.Pow(10, base10NormalizationExponent));
int base10NormalizationExponent = (int)toUnit;
return amount / Math.Pow(10, base10NormalizationExponent);
}

/// <summary>
@@ -33,7 +33,7 @@ private static double ConvertUnits(long amount, IotaUnits toUnit)
/// <returns>the optimal IotaUnit</returns>
public static IotaUnits FindOptimalIotaUnitToDisplay(long amount)
{
int length = (amount).ToString().Length;
int length = amount.ToString().Length;

if (amount < 0)
{
1 change: 0 additions & 1 deletion IotaCSharpApiUnitTests/Api/IotaApiTests.cs
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@
using Iota.Lib.CSharp.Api.Core;
using Iota.Lib.CSharp.Api.Exception;
using Iota.Lib.CSharp.Api.Model;
using Iota.Lib.CSharp.Api.Utils;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Iota.Lib.CSharpTests.Api
1 change: 0 additions & 1 deletion IotaCSharpApiUnitTests/Api/IotaCoreApiTest.cs
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@
using Iota.Lib.CSharp.Api;
using Iota.Lib.CSharp.Api.Core;
using Iota.Lib.CSharp.Api.Exception;
using Iota.Lib.CSharp.Api.Utils;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Iota.Lib.CSharpTests.Api
6 changes: 3 additions & 3 deletions IotaCSharpApiUnitTests/Api/Utils/ChecksumTest.cs
Original file line number Diff line number Diff line change
@@ -15,19 +15,19 @@ public class ChecksumTest
[TestMethod]
public void shouldAddChecksum()
{
Assert.AreEqual(Checksum.AddChecksum(TEST_ADDRESS_WITHOUT_CHECKSUM), TEST_ADDRESS_WITH_CHECKSUM);
Assert.AreEqual(TEST_ADDRESS_WITHOUT_CHECKSUM.AddChecksum(), TEST_ADDRESS_WITH_CHECKSUM);
}

[TestMethod]
public void shouldRemoveChecksum()
{
Assert.AreEqual(Checksum.RemoveChecksum(TEST_ADDRESS_WITH_CHECKSUM), TEST_ADDRESS_WITHOUT_CHECKSUM);
Assert.AreEqual(TEST_ADDRESS_WITH_CHECKSUM.RemoveChecksum(), TEST_ADDRESS_WITHOUT_CHECKSUM);
}

[TestMethod]
public void shouldIsValidChecksum()
{
Assert.AreEqual(Checksum.IsValidChecksum(TEST_ADDRESS_WITH_CHECKSUM), true);
Assert.AreEqual(TEST_ADDRESS_WITH_CHECKSUM.IsValidChecksum(), true);
}
}
}
9 changes: 6 additions & 3 deletions IotaCSharpApiUnitTests/Api/Utils/InputValidatorTests.cs
Original file line number Diff line number Diff line change
@@ -68,9 +68,12 @@ public void shouldIsArrayOfHashes()
[TestMethod]
public void shouldIsTransfersCollectionCorrect()
{
List<Transfer> transfers = new List<Transfer>();
transfers.Add(new Transfer(TEST_ADDRESS_WITH_CHECKSUM, 0, TEST_MESSAGE, TEST_TAG));
transfers.Add(new Transfer(TEST_ADDRESS_WITH_CHECKSUM, 0, TEST_MESSAGE, TEST_TAG));
List<Transfer> transfers = new List<Transfer>
{
new Transfer(TEST_ADDRESS_WITH_CHECKSUM, 0, TEST_MESSAGE, TEST_TAG),
new Transfer(TEST_ADDRESS_WITH_CHECKSUM, 0, TEST_MESSAGE, TEST_TAG)
};

Assert.AreEqual(InputValidator.IsTransfersCollectionValid(transfers), true);
}
}
3 changes: 2 additions & 1 deletion IotaCSharpApiUnitTests/Api/Utils/TrytesConverterTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Security.Cryptography;
using Iota.Lib.CSharp.Api.Utils;
using Microsoft.VisualStudio.TestTools.UnitTesting;

@@ -29,7 +30,7 @@ public void shouldConvertBackAndForth()
Assert.AreEqual(str, back);
}

private static Random random = new Random();
private static Random random = new Random(DateTime.Now.Millisecond);

public static string RandomString(int length)
{