private JsonFileStore CreateStore()
        {
            var store = new JsonFileStore(_testFile);

            store.Initialize();
            return(store);
        }
        public void BasicCRUDPersistent()
        {
            var path = Path.GetTempFileName();

            try
            {
                var store = new JsonFileStore(path);
                var tape  = new Tape()
                {
                    Id = "foo"
                };
                store.Insert(tape);
                var tape2 = store.Select(tape.Id);
                Assert.IsNotNull(tape2);

                // make sure tapes are cloned
                tape2.Comment = "bar";
                var tape3 = store.Select(tape2.Id);
                Assert.AreNotEqual(tape2.Comment, tape3.Comment);

                // update
                store.Update(tape2);
                tape3 = store.Select(tape2.Id);
                Assert.AreEqual(tape2.Comment, tape3.Comment);

                // delete
                store.Delete(tape3.Id);
                Assert.AreEqual(0, store.List().Count);
            }
            finally
            {
                File.Delete(path);
            }
        }
        public void BasicCRUDPersistent()
        {
            var path = Path.GetTempFileName();

            try
            {
                var store = new JsonFileStore(path);
                var tape = new Tape()
                               {
                                   Id = "foo"
                               };
                store.Insert(tape);
                var tape2 = store.Select(tape.Id);
                Assert.IsNotNull(tape2);

                // make sure tapes are cloned
                tape2.Comment = "bar";
                var tape3 = store.Select(tape2.Id);
                Assert.AreNotEqual(tape2.Comment, tape3.Comment);

                // update
                store.Update(tape2);
                tape3 = store.Select(tape2.Id);
                Assert.AreEqual(tape2.Comment, tape3.Comment);

                // delete
                store.Delete(tape3.Id);
                Assert.AreEqual(0, store.List().Count);

            }
            finally
            {
                File.Delete(path);
            }
        }
Exemple #4
0
        public void ProxyCanRecordAndPlaybackOpen()
        {
            // fire up a proxy server, record a request, check the store and then replay it

            int    port        = 81;
            string contextName = "Mocument";
            var    path        = Path.GetTempFileName();
            var    store       = new JsonFileStore(path);
            Server server      = null;

            try
            {
                server = new Server(port, 82, "localhost.", false, store);
                server.Start();
                const string postData      = "bar=foo";
                var          recordAddress = "http://localhost.:" + port + "/record/sky/httpbin/httpbin.org/post?foo=bar";
                string       response1     = new WebClient().UploadString(recordAddress, postData);

                // introduce some delay to let the server store the tape. this is not contrived....
                Thread.Sleep(1000);

                var tapes = store.List();
                Assert.AreEqual(1, tapes.Count);
                Assert.AreEqual("sky.httpbin", tapes[0].Id);
                Assert.AreEqual(1, tapes[0].log.entries.Count);

                // #TODO: we need to add something unobtrusive to the replayed response to make it clear it was canned
                var    playAddress = "http://localhost.:" + port + "/play/sky/httpbin/httpbin.org/post?foo=bar";
                string response2   = new WebClient().UploadString(playAddress, postData);
                Thread.Sleep(1000);
                Assert.AreEqual(response1, response2);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
            finally
            {
                File.Delete(path);
                if (server != null)
                {
                    server.Stop();
                }
            }
        }
Exemple #5
0
        private JsonFileStore CreateStore()
        {
            var store = new JsonFileStore(_testFile);

            return(store);
        }
Exemple #6
0
        public void Save(string jsonFilePath)
        {
            var store = new JsonFileStore <Actor>(_converters, jsonFilePath);

            Save(store);
        }