コード例 #1
0
        public static void ClassInit(TestContext context)
        {
            ILoggerFactory  factory     = new LoggerFactory().AddDebug();
            DataServiceMock dataService = new DataServiceMock();

            _recordRepo       = dataService.GetRepository <Record>();
            _recordOperations = new RecordOperations(
                dataService,
                new RecordFetchProvider(),
                new Logger <RecordOperations>(factory));
        }
コード例 #2
0
 public void StartsWithIgnoringWhiteSpaces()
 {
     Check.That(RecordOperations.StartsWithIgnoringWhiteSpaces("", "", StringComparison.Ordinal)).IsTrue();
     Check.That(RecordOperations.StartsWithIgnoringWhiteSpaces("", "test", StringComparison.Ordinal)).IsFalse();
     Check.That(RecordOperations.StartsWithIgnoringWhiteSpaces(" ", "test", StringComparison.Ordinal)).IsFalse();
     Check.That(RecordOperations.StartsWithIgnoringWhiteSpaces("  test  ", "test", StringComparison.Ordinal)).IsTrue();
     Check.That(RecordOperations.StartsWithIgnoringWhiteSpaces("  test", "test", StringComparison.Ordinal)).IsTrue();
     Check.That(RecordOperations.StartsWithIgnoringWhiteSpaces("test string text", "test", StringComparison.Ordinal)).IsTrue();
     Check.That(RecordOperations.StartsWithIgnoringWhiteSpaces(" test string text", "test", StringComparison.Ordinal)).IsTrue();
     Check.That(RecordOperations.StartsWithIgnoringWhiteSpaces(" test string text", "hello", StringComparison.Ordinal)).IsFalse();
 }
コード例 #3
0
        public async Task GetRecordsAsync_ExpectedResult()
        {
            _client.GetAllAsync(Arg.Any <UKFastClient.GetPaginatedAsyncFunc <Record> >(), null).Returns(
                Task.Run <IList <Record> >(() => new List <Record>()
            {
                new Record(),
                new Record()
            }));

            var ops     = new RecordOperations <Record>(_client);
            var domains = await ops.GetRecordsAsync();

            Assert.AreEqual(2, domains.Count);
        }
コード例 #4
0
        public async Task GetRecordsPaginatedAsync_ExpectedResult()
        {
            _client.GetPaginatedAsync <Record>("/ddosx/v1/records").Returns(
                Task.Run(() => new Paginated <Record>(_client, "/ddosx/v1/records", null,
                                                      new ClientResponse <IList <Record> >()
            {
                Body = new ClientResponseBody <IList <Record> >()
                {
                    Data = new List <Record>()
                    {
                        new Record(),
                        new Record()
                    }
                }
            })));

            var ops       = new RecordOperations <Record>(_client);
            var paginated = await ops.GetRecordsPaginatedAsync();

            Assert.AreEqual(2, paginated.Items.Count);
        }
コード例 #5
0
        public void GetRecords(string moduleAPIName)
        {
            try
            {
                Console.WriteLine("Fetching Cr's for user - " + SDKInitializer.GetInitializer().User.Email);

                RecordOperations recordOperation = new RecordOperations();

                APIResponse <ResponseHandler> response = recordOperation.GetRecords(moduleAPIName, null, null);

                if (response != null)
                {
                    //Get the status code from response
                    Console.WriteLine("Status Code: " + response.StatusCode);

                    if (new List <int>()
                    {
                        204, 304
                    }.Contains(response.StatusCode))
                    {
                        Console.WriteLine(response.StatusCode == 204 ? "No Content" : "Not Modified");

                        return;
                    }

                    //Check if expected response is received
                    if (response.IsExpected)
                    {
                        //Get object from response
                        ResponseHandler responseHandler = response.Object;

                        if (responseHandler is ResponseWrapper)
                        {
                            //Get the received ResponseWrapper instance
                            ResponseWrapper responseWrapper = (ResponseWrapper)responseHandler;

                            //Get the list of obtained Record instances
                            List <API.Record.Record> records = responseWrapper.Data;

                            foreach (API.Record.Record record in records)
                            {
                                Console.WriteLine(JsonConvert.SerializeObject(record));
                            }
                        }
                        //Check if the request returned an exception
                        else if (responseHandler is APIException)
                        {
                            //Get the received APIException instance
                            APIException exception = (APIException)responseHandler;

                            //Get the Status
                            Console.WriteLine("Status: " + exception.Status.Value);

                            //Get the Code
                            Console.WriteLine("Code: " + exception.Code.Value);

                            Console.WriteLine("Details: ");

                            //Get the details map
                            foreach (KeyValuePair <string, object> entry in exception.Details)
                            {
                                //Get each value in the map
                                Console.WriteLine(entry.Key + ": " + JsonConvert.SerializeObject(entry.Value));
                            }

                            //Get the Message
                            Console.WriteLine("Message: " + exception.Message.Value);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(JsonConvert.SerializeObject(ex));
            }
        }