Skip to content
This repository has been archived by the owner on Jul 24, 2022. It is now read-only.

Commit

Permalink
Use Moq from aspnetcidev feed
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxwe11 committed Feb 22, 2016
1 parent 9a89d04 commit 83a1b4b
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 75 deletions.
6 changes: 0 additions & 6 deletions NModbus4.UnitTests/Device/ModbusMasterFixture.cs
Expand Up @@ -2,20 +2,14 @@
using System.Linq;
using Modbus.Device;
using Modbus.IO;
#if MOQ
using Moq;
#endif
using Xunit;

namespace Modbus.UnitTests.Device
{
public class ModbusMasterFixture
{
#if MOQ
private static IStreamResource StreamRsource => new Mock<IStreamResource>(MockBehavior.Strict).Object;
#else
private static IStreamResource StreamRsource => new DummyStreamResource();
#endif

private ModbusSerialMaster Master => ModbusSerialMaster.CreateRtu(StreamRsource);

Expand Down
30 changes: 0 additions & 30 deletions NModbus4.UnitTests/DummyStreamResource.cs

This file was deleted.

8 changes: 0 additions & 8 deletions NModbus4.UnitTests/IO/ModbusAsciiTransportFixture.cs
Expand Up @@ -2,20 +2,14 @@
using System.Text;
using Modbus.IO;
using Modbus.Message;
#if MOQ
using Moq;
#endif
using Xunit;

namespace Modbus.UnitTests.IO
{
public class ModbusAsciiTransportFixture
{
#if MOQ
private static IStreamResource StreamResource => new Mock<IStreamResource>(MockBehavior.Strict).Object;
#else
private static IStreamResource StreamResource => new DummyStreamResource();
#endif

[Fact]
public void BuildMessageFrame()
Expand All @@ -28,7 +22,6 @@ public void BuildMessageFrame()
Assert.Equal(expected, actual);
}

#if MOQ
[Fact]
public void ReadRequestResponse()
{
Expand Down Expand Up @@ -68,7 +61,6 @@ public void ReadRequestResponseNotEnoughBytes()
Assert.Throws<IOException>(() => transport.ReadRequestResponse());
mock.VerifyAll();
}
#endif

[Fact]
public void ChecksumsMatchSucceed()
Expand Down
8 changes: 0 additions & 8 deletions NModbus4.UnitTests/IO/ModbusRtuTransportFixture.cs
Expand Up @@ -5,20 +5,14 @@
using Modbus.IO;
using Modbus.Message;
using Modbus.Utility;
#if MOQ
using Moq;
#endif
using Xunit;

namespace Modbus.UnitTests.IO
{
public class ModbusRtuTransportFixture
{
#if MOQ
private static IStreamResource StreamResource => new Mock<IStreamResource>(MockBehavior.Strict).Object;
#else
private static IStreamResource StreamResource => new DummyStreamResource();
#endif

[Fact]
public void BuildMessageFrame()
Expand Down Expand Up @@ -127,7 +121,6 @@ public void ChecksumsMatchFail()
Assert.False(transport.ChecksumsMatch(message, frame));
}

#if MOQ
[Fact]
public void ReadResponse()
{
Expand Down Expand Up @@ -237,6 +230,5 @@ public void Read()

mock.VerifyAll();
}
#endif
}
}
8 changes: 0 additions & 8 deletions NModbus4.UnitTests/IO/ModbusSerialTransportFixture.cs
Expand Up @@ -5,20 +5,14 @@
using Modbus.Message;
using Modbus.UnitTests.Message;
using Modbus.Utility;
#if MOQ
using Moq;
#endif
using Xunit;

namespace Modbus.UnitTests.IO
{
public class ModbusSerialTransportFixture
{
#if MOQ
private static IStreamResource StreamResource => new Mock<IStreamResource>(MockBehavior.Strict).Object;
#else
private static IStreamResource StreamResource => new DummyStreamResource();
#endif

[Fact]
public void CreateResponse()
Expand Down Expand Up @@ -50,7 +44,6 @@ public void CreateResponseErroneousLrcDoNotCheckFrame()
transport.CreateResponse<ReadCoilsInputsResponse>(new byte[] { 19, Modbus.ReadCoils, 0, 0, 0, 2, 115 });
}

#if MOQ
/// <summary>
/// When using the serial RTU protocol the beginning of the message could get mangled leading to an unsupported message type.
/// We want to be sure to try the message again so clear the RX buffer and try again.
Expand Down Expand Up @@ -102,6 +95,5 @@ public void UnicastMessage_PurgeReceiveBuffer()
ModbusMessageFixture.AssertModbusMessagePropertiesAreEqual(response, actualResponse);
mock.VerifyAll();
}
#endif
}
}
14 changes: 2 additions & 12 deletions NModbus4.UnitTests/IO/ModbusTcpTransportFixture.cs
Expand Up @@ -5,33 +5,25 @@
using Modbus.IO;
using Modbus.Message;
using Modbus.UnitTests.Message;
#if MOQ
using Moq;
#endif
using Xunit;

namespace Modbus.UnitTests.IO
{
public class ModbusTcpTransportFixture
{
#if MOQ
private Mock<IStreamResource> StreamResourceMock => new Mock<IStreamResource>(MockBehavior.Strict);
#else
private IStreamResource StreamResourceMock => new DummyStreamResource();
#endif
private IStreamResource StreamResourceMock => new Mock<IStreamResource>(MockBehavior.Strict).Object;

#if MOQ
[Fact]
public void BuildMessageFrame()
{
var mock = new Mock<ModbusIpTransport>(StreamResourceMock.Object) { CallBase = true };
var mock = new Mock<ModbusIpTransport>(StreamResourceMock) { CallBase = true };
var message = new ReadCoilsInputsRequest(Modbus.ReadCoils, 2, 10, 5);

byte[] result = mock.Object.BuildMessageFrame(message);
Assert.Equal(new byte[] { 0, 0, 0, 0, 0, 6, 2, 1, 0, 10, 0, 5 }, result);
mock.VerifyAll();
}
#endif

[Fact]
public void GetMbapHeader()
Expand All @@ -41,7 +33,6 @@ public void GetMbapHeader()
Assert.Equal(new byte[] { 0, 45, 0, 0, 0, 247, 3 }, ModbusIpTransport.GetMbapHeader(message));
}

#if MOQ
[Fact]
public void Write()
{
Expand Down Expand Up @@ -110,7 +101,6 @@ public void ReadRequestResponse_ConnectionAbortedWhileReadingMessageFrame()
Assert.Throws<IOException>(() => ModbusIpTransport.ReadRequestResponse(mock.Object));
mock.VerifyAll();
}
#endif

[Fact]
public void GetNewTransactionId()
Expand Down
4 changes: 1 addition & 3 deletions NModbus4.UnitTests/IO/ModbusTransportFixture.cs
@@ -1,5 +1,4 @@
#if MOQ
using System;
using System;
using System.IO;
using System.Linq;
using Modbus.Data;
Expand Down Expand Up @@ -455,4 +454,3 @@ public void ValidateResponse_CallsOnValidateResponse()
}
}
}
#endif
1 change: 1 addition & 0 deletions NModbus4.UnitTests/project.json
Expand Up @@ -7,6 +7,7 @@
"licenseUrl": "",

"dependencies": {
"moq.netcore": "4.4.0-*",
"NModbus4": { "target": "project" },
"OpenCover": "4.6.166",
"xunit": "2.1.0",
Expand Down
1 change: 1 addition & 0 deletions NModbus4.sln
Expand Up @@ -8,6 +8,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{67F4885B-CF1F-4640-943F-363213B100A9}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
NuGet.config = NuGet.config
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NModbus4.UnitTests", "NModbus4.UnitTests\NModbus4.UnitTests.xproj", "{099155AF-8348-4829-B959-2F83AFCDD4E3}"
Expand Down
7 changes: 7 additions & 0 deletions NuGet.config
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>

0 comments on commit 83a1b4b

Please sign in to comment.