Ejemplo n.º 1
0
        public void FailedCreateTest()
        {
            var options = new ServerCreateOptions("");

            var ex = Assert.Throws <MailosaurException>(delegate {
                m_Client.Servers.Create(options);
            });

            Assert.Equal("Operation returned an invalid status code 'BadRequest'", ex.Message);
            Assert.Equal("ValidationError", ex.MailosaurError.Type);
            Assert.Equal(1, ex.MailosaurError.Messages.Count);
            Assert.NotEmpty(ex.MailosaurError.Messages["name"]);
        }
Ejemplo n.º 2
0
        public void CrudTest()
        {
            var serverName = "My test";

            // Create a new server
            var    options       = new ServerCreateOptions(serverName);
            Server createdServer = m_Client.Servers.Create(options);

            Assert.False(string.IsNullOrWhiteSpace(createdServer.Id));
            Assert.Equal(serverName, createdServer.Name);
            Assert.NotNull(createdServer.Password);
            Assert.NotNull(createdServer.Users);
            Assert.Equal(0, createdServer.Messages);
            Assert.NotNull(createdServer.ForwardingRules);

            // Retrieve a server and confirm it has expected content
            Server retrievedServer = m_Client.Servers.Get(createdServer.Id);

            Assert.Equal(createdServer.Id, retrievedServer.Id);
            Assert.Equal(createdServer.Name, retrievedServer.Name);
            Assert.NotNull(retrievedServer.Password);
            Assert.NotNull(retrievedServer.Users);
            Assert.Equal(0, retrievedServer.Messages);
            Assert.NotNull(retrievedServer.ForwardingRules);

            // Update a server and confirm it has changed
            retrievedServer.Name += " EDITED";
            Server updatedServer = m_Client.Servers.Update(retrievedServer.Id, retrievedServer);

            Assert.Equal(retrievedServer.Id, updatedServer.Id);
            Assert.Equal(retrievedServer.Name, updatedServer.Name);
            Assert.Equal(retrievedServer.Password, updatedServer.Password);
            Assert.Equal(retrievedServer.Users, updatedServer.Users);
            Assert.Equal(retrievedServer.Messages, updatedServer.Messages);
            Assert.Equal(retrievedServer.ForwardingRules, updatedServer.ForwardingRules);

            m_Client.Servers.Delete(retrievedServer.Id);

            // Attempting to delete again should fail
            Assert.Throws <MailosaurException>(delegate {
                m_Client.Servers.Delete(retrievedServer.Id);
            });
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a server
 /// </summary>
 /// <remarks>
 /// Creates a new virtual SMTP server and returns it.
 /// </remarks>
 /// <param name='serverCreateOptions'>
 /// </param>
 /// <exception cref="MailosaurException">
 /// Thrown when the operation returned an invalid status code
 /// </exception>
 /// <return>
 /// A response object containing the response body and response headers.
 /// </return>
 public Task <Server> CreateAsync(ServerCreateOptions serverCreateOptions)
 => ExecuteRequest <Server>(HttpMethod.Post, "api/servers", serverCreateOptions);
Ejemplo n.º 4
0
 /// <summary>
 /// Create a server
 /// </summary>
 /// <remarks>
 /// Creates a new virtual SMTP server and returns it.
 /// </remarks>
 /// <param name='serverCreateOptions'>
 /// </param>
 /// <exception cref="MailosaurException">
 /// Thrown when the operation returned an invalid status code
 /// </exception>
 /// <return>
 /// A response object containing the response body and response headers.
 /// </return>
 public Server Create(ServerCreateOptions serverCreateOptions)
 => Task.Run(async() => await CreateAsync(serverCreateOptions)).UnwrapException <Server>();