2013-03-28 22:07:09 +00:00
|
|
|
|
|
2011-07-09 18:19:33 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
2013-03-05 05:33:34 +00:00
|
|
|
|
using NzbDrone.Common;
|
2011-07-09 18:19:33 +00:00
|
|
|
|
using NzbDrone.Core.Model.Xbmc;
|
2013-05-19 23:17:32 +00:00
|
|
|
|
using NzbDrone.Core.Notifications.Xbmc;
|
2011-07-09 18:19:33 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
2011-07-09 18:19:33 +00:00
|
|
|
|
|
2011-10-20 23:42:17 +00:00
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
2011-07-09 18:19:33 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2013-02-17 05:44:06 +00:00
|
|
|
|
public class EventClientProviderTest : CoreTest
|
2011-07-09 18:19:33 +00:00
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void SendNotification_true()
|
|
|
|
|
{
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
|
2011-07-09 18:19:33 +00:00
|
|
|
|
|
|
|
|
|
var header = "NzbDrone Test";
|
|
|
|
|
var message = "Test Message!";
|
|
|
|
|
var address = "localhost";
|
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var fakeUdp = Mocker.GetMock<UdpProvider>();
|
2011-07-09 18:19:33 +00:00
|
|
|
|
fakeUdp.Setup(s => s.Send(address, UdpProvider.PacketType.Notification, It.IsAny<byte[]>())).Returns(true);
|
|
|
|
|
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var result = Mocker.Resolve<EventClientProvider>().SendNotification(header, message, IconType.Jpeg, "NzbDrone.jpg", address);
|
2011-07-09 18:19:33 +00:00
|
|
|
|
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2011-07-09 18:19:33 +00:00
|
|
|
|
Assert.AreEqual(true, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SendNotification_false()
|
|
|
|
|
{
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
|
2011-07-09 18:19:33 +00:00
|
|
|
|
|
|
|
|
|
var header = "NzbDrone Test";
|
|
|
|
|
var message = "Test Message!";
|
|
|
|
|
var address = "localhost";
|
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var fakeUdp = Mocker.GetMock<UdpProvider>();
|
2011-07-09 18:19:33 +00:00
|
|
|
|
fakeUdp.Setup(s => s.Send(address, UdpProvider.PacketType.Notification, It.IsAny<byte[]>())).Returns(false);
|
|
|
|
|
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var result = Mocker.Resolve<EventClientProvider>().SendNotification(header, message, IconType.Jpeg, "NzbDrone.jpg", address);
|
2011-07-09 18:19:33 +00:00
|
|
|
|
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2011-07-09 18:19:33 +00:00
|
|
|
|
Assert.AreEqual(false, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SendAction_Update_true()
|
|
|
|
|
{
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
|
2011-07-09 18:19:33 +00:00
|
|
|
|
|
|
|
|
|
var path = @"C:\Test\TV\30 Rock";
|
|
|
|
|
var command = String.Format("ExecBuiltIn(UpdateLibrary(video,{0}))", path);
|
|
|
|
|
var address = "localhost";
|
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var fakeUdp = Mocker.GetMock<UdpProvider>();
|
2011-07-09 18:19:33 +00:00
|
|
|
|
fakeUdp.Setup(s => s.Send(address, UdpProvider.PacketType.Action, It.IsAny<byte[]>())).Returns(true);
|
|
|
|
|
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var result = Mocker.Resolve<EventClientProvider>().SendAction(address, ActionType.ExecBuiltin, command);
|
2011-07-09 18:19:33 +00:00
|
|
|
|
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2011-07-09 18:19:33 +00:00
|
|
|
|
Assert.AreEqual(true, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SendAction_Update_false()
|
|
|
|
|
{
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
|
2011-07-09 18:19:33 +00:00
|
|
|
|
|
|
|
|
|
var path = @"C:\Test\TV\30 Rock";
|
|
|
|
|
var command = String.Format("ExecBuiltIn(UpdateLibrary(video,{0}))", path);
|
|
|
|
|
var address = "localhost";
|
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var fakeUdp = Mocker.GetMock<UdpProvider>();
|
2011-07-09 18:19:33 +00:00
|
|
|
|
fakeUdp.Setup(s => s.Send(address, UdpProvider.PacketType.Action, It.IsAny<byte[]>())).Returns(false);
|
|
|
|
|
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2011-12-15 04:15:53 +00:00
|
|
|
|
var result = Mocker.Resolve<EventClientProvider>().SendAction(address, ActionType.ExecBuiltin, command);
|
2011-07-09 18:19:33 +00:00
|
|
|
|
|
2013-03-28 22:07:09 +00:00
|
|
|
|
|
2011-07-09 18:19:33 +00:00
|
|
|
|
Assert.AreEqual(false, result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|