예제 #1
0
        public void GetTestFileAsStream_ReadExistingFile()
        {
            string data = @"
        {
          ""key"": ""value"",
          ""key2"": ""value2""
        }";

            byte[] expected = Encoding.UTF8.GetBytes(data);

            // Write the data to a temporary location.
            string path = Path.GetTempFileName();

            File.WriteAllBytes(path, expected);

            byte[] actual;
            int    actualByteCount;

            using (Stream stream = TestingTools.GetTestFileAsStream(path))
            {
                // Allow a max number of bytes *much* longer than what's expected.
                byte[] buffer = new byte[expected.Length * 10];
                actualByteCount = stream.Read(buffer, 0, buffer.Length);
                // Copy only as many bytes as were actually read.
                actual = new byte[actualByteCount];
                Array.Copy(buffer, actual, actualByteCount);
            }

            Assert.Equal(expected.Length, actualByteCount);
            Assert.Equal(expected, actual);
        }
        public void GetPathToTestFile_Filename(string filename)
        {
            string basePath = Path.GetDirectoryName(this.GetType().Assembly.Location);
            string expected = Path.Join(basePath, "TestData", filename);

            string actual = TestingTools.GetPathToTestFile(filename);

            Assert.Equal(expected, actual);
        }
예제 #3
0
        public void GetDataFileAsJObject_SimpleString(string filename, string expectedValue)
        {
            JObject expected = JObject.Parse(expectedValue);

            string  path   = Path.Join("Tools/TestingTools/GetDataFileAsJObject", filename);
            JObject actual = TestingTools.GetDataFileAsJObject(path);

            Assert.Equal(expected, actual, new JTokenEqualityComparer());
        }
예제 #4
0
        /// <summary>
        /// Gets an ElasticClient backed by an InMemoryConnection.  This is used to mock the
        /// JSON returned by the elastic search so that we test the Nest mappings to our models.
        /// </summary>
        /// <param name="testFile"></param>
        /// <returns></returns>
        public static IElasticClient GetInMemoryElasticClient(string testFile)
        {
            //Get Response JSON
            byte[] responseBody = TestingTools.GetTestFileAsBytes(testFile);

            //While this has a URI, it does not matter, an InMemoryConnection never requests
            //from the server.
            var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));

            // Setup ElasticSearch stuff using the contents of the JSON file as the client response.
            InMemoryConnection conn = new InMemoryConnection(responseBody);

            var connectionSettings = new ConnectionSettings(pool, conn, sourceSerializer: JsonNetSerializer.Default);

            return(new ElasticClient(connectionSettings));
        }
        public void GetStringAsStream_ValidStrings(string data, byte[] expected)
        {
            byte[] actual;
            int    actualByteCount;

            using (Stream stream = TestingTools.GetStringAsStream(data))
            {
                // Allow a max number of bytes *much* longer than what's expected.
                int    bufSize = (expected.Length > 0) ? expected.Length * 10 : 10;
                byte[] buffer  = new byte[bufSize];
                actualByteCount = stream.Read(buffer, 0, buffer.Length);
                // Copy only as many bytes as were actually read.
                actual = new byte[actualByteCount];
                Array.Copy(buffer, actual, actualByteCount);
            }

            Assert.Equal(expected.Length, actualByteCount);
            Assert.Equal(expected, actual);
        }
        public void GetTestFileAsBytes_ReadExistingFile()
        {
            string data = @"
        {
          ""key"": ""value"",
          ""key2"": ""value2""
        }";

            byte[] expected = Encoding.UTF8.GetBytes(data);

            // Write the data to a temporary location.
            string path = Path.GetTempFileName();

            File.WriteAllText(path, data);

            // Get the data back.
            byte[] actual = TestingTools.GetTestFileAsBytes(path);

            Assert.Equal(expected, actual);
        }
 public void GetPathToTestFile_Null()
 {
     Assert.Throws <ArgumentNullException>(
         () => TestingTools.GetPathToTestFile(null)
         );
 }
예제 #8
0
 public void GetTestFileAsStream_NonexistingFile()
 {
     Assert.Throws <FileNotFoundException>(
         () => TestingTools.GetTestFileAsStream("NonExistingFile.json")
         );
 }
예제 #9
0
 public void GetTestFileAsStream_Null()
 {
     Assert.Throws <ArgumentNullException>(
         () => TestingTools.GetTestFileAsStream(null)
         );
 }
예제 #10
0
 public void GetDataFileAsJObject_NonexistingFile()
 {
     Assert.Throws <FileNotFoundException>(
         () => TestingTools.GetDataFileAsJObject("NonExistingFile.json")
         );
 }
예제 #11
0
 public void GetDataFileAsJObject_Null()
 {
     Assert.Throws <ArgumentNullException>(
         () => TestingTools.GetDataFileAsJObject(null)
         );
 }