public async void SingleConfiguration_Options_PushFailed() { var config = new PushChannelConfiguration() { ChannelType = TestChannelType, Id = "TestId" }; var ex = new PushException("test"); var providerMock = new Mock <IPushProvider>(MockBehavior.Strict); providerMock.Setup(v => v.PushAsync(It.IsAny <string>(), It.IsAny <PushOptions>())) .Throws(ex); var pushService = new PushService(MockByConfigs(new[] { config }), new[] { MockByProvider(new Dictionary <string, IPushProvider> { { config.Id, providerMock.Object } }) }); var res = await Assert.ThrowsAsync <PushFailedException>(async() => await pushService.Push("userid", new Dictionary <string, string>(), "payload", null)); Assert.Single(res.Failures); Assert.Same(config, res.Failures[0].Configuration); Assert.Same(ex, res.Failures[0].Exception); Assert.Same(ex, res.InnerException); }
public async void MultiConfiguration_PartiallyFailed() { var config1 = new PushChannelConfiguration() { ChannelType = TestChannelType, Id = "1" }; var config2 = new PushChannelConfiguration() { ChannelType = TestChannelType, Id = "2" }; var config3 = new PushChannelConfiguration() { ChannelType = TestChannelType, Id = "3" }; var ex1 = new PushException("test"); var ex2 = new PushException("test"); var providerMock1 = new Mock <IPushProvider>(MockBehavior.Strict); providerMock1.Setup(v => v.PushAsync(It.IsAny <string>(), It.IsAny <PushOptions>())) .Throws(ex1); var providerMock2 = new Mock <IPushProvider>(MockBehavior.Strict); providerMock2.Setup(v => v.PushAsync(It.IsAny <string>(), It.IsAny <PushOptions>())) .Throws(ex2); var providerMock3 = new Mock <IPushProvider>(MockBehavior.Strict); providerMock3.Setup(v => v.PushAsync(It.IsAny <string>(), It.IsAny <PushOptions>())) .Returns(Task.CompletedTask); var pushService = new PushService(MockByConfigs(new[] { config1, config2, config3 }), new[] { MockByProvider(new Dictionary <string, IPushProvider> { { config1.Id, providerMock1.Object }, { config2.Id, providerMock2.Object }, { config3.Id, providerMock3.Object } }) }); var res = await Assert.ThrowsAsync <PushPartiallyFailedException>(async() => await pushService.Push("userid", new Dictionary <string, string>(), "payload", null)); Assert.Equal(2, res.Failures.Length); Assert.Collection(res.Failures, v => { Assert.Same(config1, v.Configuration); Assert.Same(ex1, v.Exception); }, v => { Assert.Same(config2, v.Configuration); Assert.Same(ex2, v.Exception); }); Assert.Collection(res.InnerExceptions, v => Assert.Same(ex1, v), v => Assert.Same(ex2, v)); Assert.Single(res.Succeeded); Assert.Collection(res.Succeeded, v => { Assert.Same(config3, v.Configuration); Assert.Null(v.Exception); }); }
private void Process(PushException p) { s_logger.Error(p.LogContent); s_logger.Error(p.StackTrace); }