Esempio n. 1
0
        public async Task LookupWithFallback_FailedAll()
        {
            var mockMailReference = new MockMailReference(
                "mock-1",
                "*****@*****.**",
                new[] { "*****@*****.**" }.ToImmutableList(),
                true,
                "Some text",
                _queue);

            _queue.References.Add(mockMailReference);
            _dns.AddMx("example.com", "first.example.com", 10);
            _dns.AddIp("first.example.com", IPAddress.Parse("10.0.0.1"));

            Task executeTask = Task.Run(
                () => _transfer.SendMailsToDomain("example.com", new[] { mockMailReference }, CancellationToken.None));

            MockTcpConnectionProvider.MockTcpClient client = await GetClientFor(IPAddress.Parse("10.0.0.1"));
            await WriteToAsync(
                client.HalfStream,
                @"554 Failed
554 Failed
");

            await executeTask;

            Assert.Equal(1, _queue.References.Count);
            Assert.Equal(0, _queue.DeletedReferences.Count);

            SmtpFailureData failure = _failures.GetFailure("mock-1", false);

            Assert.NotNull(failure);
            Assert.Equal(1, failure.Retries);
            Assert.InRange(failure.FirstFailure, DateTimeOffset.UtcNow - TimeSpan.FromSeconds(1), DateTime.UtcNow);
        }
Esempio n. 2
0
        public async Task LookupWithFallback()
        {
            var mockMailReference = new MockMailReference(
                "mock-1",
                "*****@*****.**",
                new[] { "*****@*****.**" }.ToImmutableList(),
                true,
                "Some text",
                _queue);

            _queue.References.Add(mockMailReference);
            _dns.AddMx("example.com", "second.example.com", 20);
            _dns.AddMx("example.com", "first.example.com", 10);
            _dns.AddMx("example.com", "third.example.com", 30);

            _dns.AddIp("first.example.com", IPAddress.Parse("10.0.0.1"));
            _dns.AddIp("second.example.com", IPAddress.Parse("10.0.0.2"));
            _dns.AddIp("third.example.com", IPAddress.Parse("10.0.0.3"));

            Task executeTask = Task.Run(
                () => _transfer.SendMailsToDomain("example.com", new[] { mockMailReference }, CancellationToken.None));

            MockTcpConnectionProvider.MockTcpClient client = await GetClientFor(IPAddress.Parse("10.0.0.1"));
            await WriteToAsync(
                client.HalfStream,
                @"554 Failed
554 Failed
");

            client = await GetClientFor(IPAddress.Parse("10.0.0.2"));
            await WriteToAsync(
                client.HalfStream,
                @"554 Failed
554 Failed
");

            client = await GetClientFor(IPAddress.Parse("10.0.0.3"));
            await WriteToAsync(
                client.HalfStream,
                @"220 example.com greets test.example.com (HELO)
250 Ok (MAIL)
250 Ok (RCPT)
354 End data with <CR><LF>.<CR><LF> (DATA)
250 Ok (DATA with .)
250 Bye (QUIT)
");

            await executeTask;

            Assert.Equal(0, _queue.References.Count);
            Assert.Equal(1, _queue.DeletedReferences.Count);
        }
Esempio n. 3
0
        private async Task <MockTcpConnectionProvider.MockTcpClient> GetClientFor(IPAddress ipAddress)
        {
            MockTcpConnectionProvider.MockTcpClient client = null;
            while (client?.HalfStream == null)
            {
                client = _tcp.Created.FirstOrDefault(t => Equals(t.IpAddress, ipAddress));
                if (client?.HalfStream == null)
                {
                    await Task.Delay(100);
                }
            }

            return(client);
        }