public async Task DeleteTemplateRecordAsync_ValidParameters_ExpectedClientCall()
        {
            IANSSafeDNSClient client = Substitute.For <IANSSafeDNSClient>();

            var ops = new TemplateRecordOperations <Record>(client);
            await ops.DeleteRecordAsync(123, 456);

            await client.Received().DeleteAsync("/safedns/v1/templates/123/records/456");
        }
        public async Task UpdateTemplateRecordAsync_ValidParameters_ExpectedClientCall()
        {
            UpdateRecordRequest req = new UpdateRecordRequest()
            {
                Name = "new.example.com"
            };

            IANSSafeDNSClient client = Substitute.For <IANSSafeDNSClient>();

            var ops = new TemplateRecordOperations <Record>(client);
            await ops.UpdateRecordAsync(123, 456, req);

            await client.Received().PatchAsync("/safedns/v1/templates/123/records/456", req);
        }
        public async Task GetTemplateRecordAsync_ValidParameters_ExpectedResult()
        {
            IANSSafeDNSClient client = Substitute.For <IANSSafeDNSClient>();

            client.GetAsync <Record>("/safedns/v1/templates/123/records/456").Returns(new Record()
            {
                ID = 123
            });

            var ops            = new TemplateRecordOperations <Record>(client);
            var TemplateRecord = await ops.GetRecordAsync(123, 456);

            Assert.AreEqual(123, TemplateRecord.ID);
        }
        public async Task GetTemplateRecordsAsync_ExpectedResult()
        {
            IANSSafeDNSClient client = Substitute.For <IANSSafeDNSClient>();
            var ops = new TemplateRecordOperations <Record>(client);

            client.GetAllAsync(Arg.Any <ANSClient.GetPaginatedAsyncFunc <Record> >(), null).Returns(Task.Run <IList <Record> >(() =>
            {
                return(new List <Record>()
                {
                    new Record(),
                    new Record()
                });
            }));

            var records = await ops.GetRecordsAsync(123);

            Assert.AreEqual(2, records.Count);
        }
        public async Task CreateTemplateRecordAsync_ExpectedResult()
        {
            CreateRecordRequest req = new CreateRecordRequest()
            {
                Name = "test.example.com"
            };

            IANSSafeDNSClient client = Substitute.For <IANSSafeDNSClient>();

            client.PostAsync <Record>("/safedns/v1/templates/123/records", req).Returns(new Record()
            {
                ID = 123
            });

            var ops = new TemplateRecordOperations <Record>(client);
            int id  = await ops.CreateRecordAsync(123, req);

            Assert.AreEqual(123, id);
        }
        public async Task GetTemplateRecordsPaginatedAsync_ExpectedClientCall()
        {
            IANSSafeDNSClient client = Substitute.For <IANSSafeDNSClient>();

            client.GetPaginatedAsync <Record>("/safedns/v1/templates/123/records").Returns(Task.Run(() =>
            {
                return(new Paginated <Record>(client, "/safedns/v1/templates/123/records", null, new Response.ClientResponse <System.Collections.Generic.IList <Record> >()
                {
                    Body = new Response.ClientResponseBody <System.Collections.Generic.IList <Record> >()
                    {
                        Data = new List <Record>()
                        {
                            new Record(),
                            new Record()
                        }
                    }
                }));
            }));

            var ops       = new TemplateRecordOperations <Record>(client);
            var paginated = await ops.GetRecordsPaginatedAsync(123);

            Assert.AreEqual(2, paginated.Items.Count);
        }
 public async Task GetTemplateRecordsPaginatedAsync_InvalidTemplateID_ThrowsANSClientValidationException()
 {
     var ops = new TemplateRecordOperations <Record>(null);
     await Assert.ThrowsExceptionAsync <ANSClientValidationException>(() => ops.GetRecordsPaginatedAsync(0));
 }
 public async Task CreateTemplateRecordAsync_InvalidTemplateID_ThrowsANSClientValidationException()
 {
     var ops = new TemplateRecordOperations <Record>(null);
     await Assert.ThrowsExceptionAsync <ANSClientValidationException>(() => ops.CreateRecordAsync(0, null));
 }
 public async Task DeleteTemplateRecordAsync_InvalidRecordID_ThrowsANSClientValidationException()
 {
     var ops = new TemplateRecordOperations <Record>(null);
     await Assert.ThrowsExceptionAsync <ANSClientValidationException>(() => ops.DeleteRecordAsync(123, 0));
 }