How to perform NUnit testing in a project on class level?

こ雲淡風輕ζ 提交于 2019-12-11 08:57:15

问题


I want to perform an NUnit Testing on a method of my project. Here SerializeBinary() method is converting object into binary streams and DeserializeFromBinaryStream() method once again convert it into previous same object format.now I want to check wheather these both objects are same or not after DesirializingFromBinary() method task. I go through from Here:, but did not clear my concepts.

I am attaching my part of code below.

First part:

public abstract class Streaming
{
    private static int _streamingIDExponent = 41;

    public const string MonthLookup = "ABCDEFGHIJK";
    public const string ExpiryStringFormat = "ddMMMyyyy";
    public const double DefaultTicksPerPoint = 3;
    private long _StreamingID;
    private int _minQty = DefaultMinimumQty;
    public virtual void SerializeBinary(BinaryStreamWriter binaryStreamWriter)
    {
        binaryStreamWriter.Write(_StreamingID);
        binaryStreamWriter.Write(_ex_StreamingID);
        binaryStreamWriter.Write(_minQty);
        binaryStreamWriter.Write(_extendedProperties.Count);
        foreach (KeyValuePair<StreamingPropertyName, StreamingProperty> dictionaryEntry in _extendedProperties)
        {
            dictionaryEntry.Value.SerializeBinary(binaryStreamWriter);
        }
    }

    public virtual bool DeserializeFromBinary(BinaryStreamReader binaryStreamReader, out string errorString)
    {
        errorString = string.Empty;
        try
        {
            _StreamingID = binaryStreamReader.ReadInt64();
            _exStreamingID = binaryStreamReader.ReadInt64();
            _minQty = binaryStreamReader.ReadInt32();    
        }
        catch (Exception oEx)
        {
            errorString = oEx.Message;
        }

        return string.IsNullOrEmpty(errorString);
    }

second Part:

public class Asset : Streaming
{
    public override void SerializeBinary(BinaryStreamWriter binaryStreamWriter)
    {
        base.SerializeBinary(binaryStreamWriter);
    }

    public override bool DeserializeFromBinary(BinaryStreamReader binaryStreamReader, out string errorString)
    {
        if (!base.DeserializeFromBinary(binaryStreamReader, out errorString))
            return false;

        try
        {
            return true;
        }
        catch (Exception oEx)
        {
            errorString = oEx.Message;
            return false;
        }
    }

Third Part:

 public class BinaryStreamWriter : IDisposable
 {
    private BinaryWriter _binaryWriter;
    public BinaryStreamWriter(BinaryWriter binaryWriter)
    {
        _binaryWriter = binaryWriter;
    }

    public void Write(object value)
    {
        if (value is Boolean) Write((Boolean)value);
        else if (value is Byte) Write((Byte)value);
        else if (value is Byte?) Write((Byte?)value);
        else if (value is Byte[]) Write((Byte[])value);
        else throw new InvalidOperationException(value.GetType().ToString());
    }

    void IDisposable.Dispose()
    {
         (_binaryWriter as IDisposable).Dispose();
    }
 }

Kindly suggest me accordingly.

来源:https://stackoverflow.com/questions/42456607/how-to-perform-nunit-testing-in-a-project-on-class-level

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!