Example #1
0
        public void PushLogsErrorIfServerResponseIsInvalid()
        {
            // arrange
            var          logTuple      = LoggerFixtureHelper.SetupLogCatcher();
            const string apiToken      = "fakeToken";
            const string sendkey       = "Send";
            var          configuration = new PushoverConfigDummy(true)
            {
                ApiToken       = apiToken,
                DefaultSendKey = sendkey
            };

            var wrapperDummy = new Mock <IPushoverWrapper>();

            wrapperDummy.Setup(t => t.Configuration).Returns(configuration);
            wrapperDummy.Setup(t => t.Push("Test", "Test", "", "")).Throws <Exception>();

            var sut = new PushoverNotifier(wrapperDummy.Object);

            // act
            sut.SendNotification("Test", "Test");

            // assert
            logTuple.Item2.Verify(t => t.Error(It.IsAny <Exception>(), "An error occured while trying to send a Push"), Times.Once);

            LoggerFixtureHelper.SwitchLogger(logTuple.Item1);
        }
Example #2
0
        public void CannotSendPushIfPushoverIsDisabled()
        {
            // arrange
            const string apiToken      = "fakeToken";
            const string sendkey       = "Send";
            var          configuration = new PushoverConfigDummy(false)
            {
                ApiToken       = apiToken,
                DefaultSendKey = sendkey
            };
            var wrapperDummy = new Mock <IPushoverWrapper>();
            var logTuple     = LoggerFixtureHelper.SetupLogCatcher();

            wrapperDummy.Setup(t => t.Configuration).Returns(configuration);

            var sut = new PushoverNotifier(wrapperDummy.Object);

            // act
            sut.SendNotification("Test", "Test");

            // assert
            logTuple.Item2.Verify(t => t.Verbose("Cannot send Push, Pushover is disabled"), Times.Once);

            LoggerFixtureHelper.SwitchLogger(logTuple.Item1);
        }
Example #3
0
        public void PushNotification()
        {
            // arrange
            var          logTuple      = LoggerFixtureHelper.SetupLogCatcher();
            const string apiToken      = "fakeToken";
            const string sendkey       = "Send";
            var          configuration = new PushoverConfigDummy(true)
            {
                ApiToken       = apiToken,
                DefaultSendKey = sendkey
            };

            var wrapperDummy = new Mock <IPushoverWrapper>();

            wrapperDummy.Setup(t => t.Configuration).Returns(configuration);
            wrapperDummy.Setup(t => t.Push("Test", "Test", sendkey, "")).Returns(new PushResponse());

            var sut = new PushoverNotifier(wrapperDummy.Object);

            // act
            sut.SendNotification("Test", "Test");

            // assert
            wrapperDummy.Verify(t => t.Push("Test", "Test", "", ""), Times.Once);
            logTuple.Item2.Verify(t => t.Debug("Push sent"), Times.Once);

            LoggerFixtureHelper.SwitchLogger(logTuple.Item1);
        }
        public void ConfigurationWithBothApiTokenAndDefaultSendKeySetsUpBaseClassCorrectly()
        {
            // arrange
            const string apiToken = "RandomKey";
            var          config   = new PushoverConfigDummy(true)
            {
                ApiToken = apiToken
            };

            // act
            var sut = new PushoverWrapper(config);

            // assert
            sut.Configuration.Should().Be(config);
            sut.AppKey.Should().Be(apiToken);
            sut.DefaultUserGroupSendKey.Should().BeNullOrEmpty();
        }
        public void TryingToSendWithInvalidDetailsThrowsAnException()
        {
            // arrange
            const string apiToken = "RandomKey";
            var          config   = new PushoverConfigDummy(true)
            {
                ApiToken = apiToken
            };
            var sut = new PushoverWrapper(config);
            var act = new Action(() =>
            {
                sut.Push("Test", "Test");
            });

            // act
            // assert
            act.ShouldThrow <Exception>();
        }
        public void ConfigurationWithOnlyApiTokenCorrectlySetsUpBaseClass()
        {
            // arrange
            const string apiToken = "RandomKey";
            const string sendKey  = "SendKey";
            var          config   = new PushoverConfigDummy(true)
            {
                ApiToken       = apiToken,
                DefaultSendKey = sendKey
            };

            // act
            var sut = new PushoverWrapper(config);

            // assert
            sut.AppKey.Should().Be(apiToken);
            sut.DefaultUserGroupSendKey.Should().Be(sendKey);
        }
Example #7
0
        public void PushoverDoesNotActivateIfDisabledInSettings()
        {
            // arrange
            var logTuple = LoggerFixtureHelper.SetupLogCatcher();
            var config   = new PushoverConfigDummy(false);

            var wrapperDummy = new Mock <IPushoverWrapper>();

            wrapperDummy.Setup(t => t.Configuration).Returns(config);

            // act
            var sut = new PushoverNotifier(wrapperDummy.Object);

            // assert
            sut.IsEnabled.Should().BeFalse();
            logTuple.Item2.Verify(t => t.Information("Setting up Pushover client"), Times.Never);

            LoggerFixtureHelper.SwitchLogger(logTuple.Item1);
        }
Example #8
0
        public void PushoverIsSetupCorrectly()
        {
            // arrange
            var          logTuple = LoggerFixtureHelper.SetupLogCatcher();
            const string apiToken = "fakeToken";
            var          config   = new PushoverConfigDummy(true)
            {
                ApiToken = apiToken
            };

            var wrapperDummy = new Mock <IPushoverWrapper>();

            wrapperDummy.Setup(t => t.Configuration).Returns(config);

            // act
            var sut = new PushoverNotifier(wrapperDummy.Object);

            // assert
            sut.IsEnabled.Should().BeTrue();
            LoggerFixtureHelper.SwitchLogger(logTuple.Item1);
        }
Example #9
0
        public void PushIsNotSendIfNoDefaultKeyIsSetAndSendIsAttemptedWithoutASendKey()
        {
            // arrange
            var          logTuple      = LoggerFixtureHelper.SetupLogCatcher();
            const string apiToken      = "fakeToken";
            var          configuration = new PushoverConfigDummy(false)
            {
                ApiToken = apiToken
            };

            var wrapperDummy = new Mock <IPushoverWrapper>();

            wrapperDummy.Setup(t => t.Configuration).Returns(configuration);

            var sut = new PushoverNotifier(wrapperDummy.Object);

            // act
            sut.SendNotification("Test", "Test");

            // assert
            logTuple.Item2.Verify(t => t.Warning("DefaultSendKey is not provided and no send key was provided. Cannot send Push"), Times.Once);

            LoggerFixtureHelper.SwitchLogger(logTuple.Item1);
        }