Have one last unit test
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Tello_Drone;
|
||||
|
||||
namespace Tests
|
||||
namespace TelloDroneUnitTests
|
||||
{
|
||||
public class ConsoleLoggerTests
|
||||
{
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
|
||||
using System;
|
||||
using System.Net.Sockets;
|
||||
using ImTools;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Tello_Drone;
|
||||
|
||||
namespace Tests
|
||||
namespace TelloDroneUnitTests
|
||||
{
|
||||
public class DroneCommandsTests
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@ using Moq;
|
||||
using NUnit.Framework;
|
||||
using Tello_Drone;
|
||||
|
||||
namespace Tests
|
||||
namespace TelloDroneUnitTests
|
||||
{
|
||||
public class DroneFactoryTests
|
||||
{
|
||||
|
||||
152
TelloDroneUnitTests/DroneTests.cs
Normal file
152
TelloDroneUnitTests/DroneTests.cs
Normal file
@@ -0,0 +1,152 @@
|
||||
using System;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Microsoft.VisualStudio.TestPlatform.Common.Utilities;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Tello_Drone;
|
||||
|
||||
namespace TelloDroneUnitTests
|
||||
{
|
||||
public class DroneTests
|
||||
{
|
||||
private Mock<IDroneCommands> _mockDroneCommands;
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_mockDroneCommands = new Mock<IDroneCommands>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidForwardTest()
|
||||
{
|
||||
var drone = new Drone(_mockDroneCommands.Object);
|
||||
drone.Forward(It.IsAny<int>());
|
||||
_mockDroneCommands.Verify(x => x.Forward(It.IsAny<int>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidReverseTest()
|
||||
{
|
||||
var drone = new Drone(_mockDroneCommands.Object);
|
||||
drone.Reverse(It.IsAny<int>());
|
||||
_mockDroneCommands.Verify(x => x.Reverse(It.IsAny<int>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidUpTest()
|
||||
{
|
||||
var drone = new Drone(_mockDroneCommands.Object);
|
||||
drone.Up(It.IsAny<int>());
|
||||
_mockDroneCommands.Verify(x => x.Up(It.IsAny<int>()), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void ValidDownTest()
|
||||
{
|
||||
var drone = new Drone(_mockDroneCommands.Object);
|
||||
drone.Down(It.IsAny<int>());
|
||||
_mockDroneCommands.Verify(x => x.Down(It.IsAny<int>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidLeftTest()
|
||||
{
|
||||
var drone = new Drone(_mockDroneCommands.Object);
|
||||
drone.Left(It.IsAny<int>());
|
||||
_mockDroneCommands.Verify(x => x.Left(It.IsAny<int>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidRightTest()
|
||||
{
|
||||
var drone = new Drone(_mockDroneCommands.Object);
|
||||
drone.Right(It.IsAny<int>());
|
||||
_mockDroneCommands.Verify(x => x.Right(It.IsAny<int>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidFrontFlipTest()
|
||||
{
|
||||
var drone = new Drone(_mockDroneCommands.Object);
|
||||
drone.FrontFlip();
|
||||
_mockDroneCommands.Verify(x => x.FrontFlip(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidBackFlipTest()
|
||||
{
|
||||
var drone = new Drone(_mockDroneCommands.Object);
|
||||
drone.BackFlip();
|
||||
_mockDroneCommands.Verify(x => x.BackFlip(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidLeftFlipTest()
|
||||
{
|
||||
var drone = new Drone(_mockDroneCommands.Object);
|
||||
drone.LeftFlip();
|
||||
_mockDroneCommands.Verify(x => x.LeftFlip(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidRightFlipTest()
|
||||
{
|
||||
var drone = new Drone(_mockDroneCommands.Object);
|
||||
drone.RightFlip();
|
||||
_mockDroneCommands.Verify(x => x.RightFlip(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CommandTest()
|
||||
{
|
||||
_mockDroneCommands.Setup(x => x.Command()).Returns(true);
|
||||
var drone = new Drone(_mockDroneCommands.Object);
|
||||
Assert.AreEqual(true, drone.Command());
|
||||
_mockDroneCommands.Verify(x => x.Command(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CommandReturnsFalse()
|
||||
{
|
||||
_mockDroneCommands.Setup(x => x.Command()).Returns(false);
|
||||
var drone = new Drone(_mockDroneCommands.Object);
|
||||
Assert.AreEqual(false, drone.Command());
|
||||
_mockDroneCommands.Verify(x => x.Command(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LandTest()
|
||||
{
|
||||
var drone = new Drone(_mockDroneCommands.Object);
|
||||
drone.Land();
|
||||
_mockDroneCommands.Verify(x => x.Land(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TakeOffTest()
|
||||
{
|
||||
var drone = new Drone(_mockDroneCommands.Object);
|
||||
drone.TakeOff();
|
||||
_mockDroneCommands.Verify(x => x.TakeOff(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InitialTakeOffTest()
|
||||
{
|
||||
_mockDroneCommands.Setup(x => x.InitialTakeOff()).Returns(true);
|
||||
var drone = new Drone(_mockDroneCommands.Object);
|
||||
Assert.AreEqual(true, drone.InitialTakeOff());
|
||||
_mockDroneCommands.Verify(x => x.InitialTakeOff(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RotateClockWise()
|
||||
{
|
||||
var drone = new Drone(_mockDroneCommands.Object);
|
||||
drone.RotateClockWise(It.IsAny<int>());
|
||||
_mockDroneCommands.Verify(x => x.RotateClockWise(It.IsAny<int>()), Times.Once);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
44
TelloDroneUnitTests/MissionCommanderTests.cs
Normal file
44
TelloDroneUnitTests/MissionCommanderTests.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Tello_Drone;
|
||||
|
||||
namespace TelloDroneUnitTests
|
||||
{
|
||||
public class MissionCommanderTests
|
||||
{
|
||||
private Mock<IDroneFactory> _mockDroneFactory;
|
||||
private Mock<IMissions> _mockMission;
|
||||
private Mock<Drone> _mockDrone;
|
||||
private Mock<IDroneCommands> _mockDroneCommands;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_mockDroneFactory = new Mock<IDroneFactory>();
|
||||
_mockMission = new Mock<IMissions>();
|
||||
_mockDroneCommands = new Mock<IDroneCommands>();
|
||||
_mockDrone = new Mock<Drone>(_mockDroneCommands.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RunMissionTest()
|
||||
{
|
||||
_mockDroneCommands.Setup(x => x.Command()).Returns(true);
|
||||
_mockDroneFactory.SetupGet(x => x.CreateDrone).Returns(_mockDrone.Object);
|
||||
var missionCommander = new MissionCommander(_mockDroneFactory.Object);
|
||||
missionCommander.RunMission(_mockMission.Object);
|
||||
_mockMission.Verify(x => x.Run(It.IsAny<Drone>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RunMissionSetupFailed()
|
||||
{
|
||||
_mockDroneCommands.Setup(x => x.Command()).Returns(false);
|
||||
_mockDroneFactory.SetupGet(x => x.CreateDrone).Returns(_mockDrone.Object);
|
||||
var missionCommander = new MissionCommander(_mockDroneFactory.Object);
|
||||
missionCommander.RunMission(_mockMission.Object);
|
||||
_mockMission.Verify(x => x.Run(It.IsAny<Drone>()), Times.Never);
|
||||
}
|
||||
}
|
||||
}
|
||||
30
TelloDroneUnitTests/MissionListTests.cs
Normal file
30
TelloDroneUnitTests/MissionListTests.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.VisualStudio.TestPlatform.Common.Utilities;
|
||||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Tello_Drone;
|
||||
|
||||
namespace TelloDroneUnitTests
|
||||
{
|
||||
public class MissionListTests
|
||||
{
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MissionListTest()
|
||||
{
|
||||
var missionList = new MissionList();
|
||||
for (int i = 0; i < missionList.GetMissionList().Count; i++)
|
||||
{
|
||||
Assert.AreEqual(typeof(string), missionList.GetMissionList()[i].Item1.GetType());
|
||||
Assert.IsInstanceOf(typeof(IMissions), missionList.GetMissionList()[i].Item2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
24
TelloDroneUnitTests/UdpClientWrapperFactoryTests.cs
Normal file
24
TelloDroneUnitTests/UdpClientWrapperFactoryTests.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Threading;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Tello_Drone;
|
||||
|
||||
namespace TelloDroneUnitTests
|
||||
{
|
||||
public class UdpClientWrapperFactoryTests
|
||||
{
|
||||
private Mock<IConsoleLogger> _mockConsoleLogger;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_mockConsoleLogger = new Mock<IConsoleLogger>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateTest()
|
||||
{
|
||||
Assert.IsInstanceOf(typeof(UdpClientWrapper), new UdpClientWrapperFactory(_mockConsoleLogger.Object).Create());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user