Beispiel #1
0
        public void DeleteResponse()
        {
            List <Todo> oldTodos = new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL))
                                   .GetModelAsync <List <Todo> >().Result;

            Assert.IsTrue(oldTodos != null && oldTodos.Count > 0);

            int oldCount = oldTodos.Count;

            Todo first = oldTodos.FirstOrDefault();

            HttpResponseMessage result = new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL))
                                         .DeleteResponseAsync(first.Id).Result;

            Assert.IsTrue(result.IsSuccessStatusCode);

            List <Todo> newTodos = new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL))
                                   .GetModelAsync <List <Todo> >().Result;

            Assert.IsTrue(newTodos != null && newTodos.Count > 0);

            int newCount = newTodos.Count;

            Assert.IsTrue(newCount < oldCount);
        }
Beispiel #2
0
 public void GetResponse()
 {
     using (HttpResponseMessage responseMessage =
                new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL))
                .GetResponseAsync().Result)
     {
         Assert.IsTrue(responseMessage.IsSuccessStatusCode);
     }
 }
Beispiel #3
0
        public void GetModel()
        {
            List <Todo> todos = new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL)).GetModelAsync <List <Todo> >().Result;

            Assert.IsTrue(todos != null && todos.Count > 0);

            Todo model = new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL + "/" + todos.FirstOrDefault().Id)).GetModelAsync <Todo>().Result;

            Assert.IsNotNull(model);
            Assert.IsTrue(model.Id > 0);
        }
Beispiel #4
0
        public void PostModel()
        {
            Todo result = new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL)).PostModelAsync <Todo, Todo>(new Todo
            {
                Completed = true,
                Title     = "My todo",
                UserId    = 2
            }).Result;

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id > 0);
        }
Beispiel #5
0
        public void PostString()
        {
            string result = new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL))
                            .PostStringAsync(new Todo
            {
                Completed = true,
                Title     = "My todo",
                UserId    = 2
            }).Result;

            Assert.IsTrue(result.Length > 0);
        }
Beispiel #6
0
 public void PostResponse()
 {
     using (HttpResponseMessage result =
                new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL))
                .PostRespnseAsync(new Todo
     {
         Completed = true,
         Title = "My todo",
         UserId = 2
     }).Result)
     {
         Assert.IsTrue(result.IsSuccessStatusCode);
     }
 }
Beispiel #7
0
        public void PutModel()
        {
            string urlGet   = Constants.URL + "/23";
            Todo   oldModel = new Unicorn(UnicornConfigFactory.NewInstance(urlGet))
                              .GetModelAsync <Todo>().Result;

            Assert.IsNotNull(oldModel);
            Assert.IsTrue(oldModel.Id > 0);

            oldModel.Title = "My edited todo";

            Todo newModel = new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL))
                            .PutModelAsync <Todo, Todo>(oldModel, oldModel.Id).Result;

            Assert.IsNotNull(newModel);
            Assert.IsTrue(newModel.Id > 0);
            Assert.AreNotEqual(oldModel, newModel);
        }
Beispiel #8
0
        public void PutString()
        {
            string urlGet   = Constants.URL + "/22";
            Todo   oldModel = new Unicorn(UnicornConfigFactory.NewInstance(urlGet))
                              .GetModelAsync <Todo>().Result;

            Assert.IsNotNull(oldModel);
            Assert.IsTrue(oldModel.Id > 0);

            oldModel.Title = "My edited todo";

            string stringResult = new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL))
                                  .PutStringAsync(oldModel, oldModel.Id).Result;

            Todo newModel = Serializer.Deserialize <Todo>(stringResult);

            Assert.IsNotNull(newModel);
            Assert.IsTrue(newModel.Id > 0);
            Assert.AreNotEqual(oldModel, newModel);
        }
Beispiel #9
0
        public void PutResponse()
        {
            string url      = Constants.URL + "/21";
            Todo   oldModel = new Unicorn(UnicornConfigFactory.NewInstance(url)).GetModelAsync <Todo>().Result;

            Assert.IsNotNull(oldModel);
            Assert.IsTrue(oldModel.Id > 0);

            oldModel.Title = "My edited todo";

            using (HttpResponseMessage responseMessage =
                       new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL))
                       .PutResponseAsync(oldModel, oldModel.Id).Result)
            {
                Assert.IsTrue(responseMessage.IsSuccessStatusCode);
                Todo newModel = Serializer.Deserialize <Todo>(responseMessage.ReadContentAsStringAsync().Result);
                Assert.IsNotNull(newModel);
                Assert.IsTrue(newModel.Id > 0);
                Assert.AreNotEqual(oldModel, newModel);
            }
        }
Beispiel #10
0
        public void DeleteJson()
        {
            List <Todo> oldTodos = new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL))
                                   .GetModelAsync <List <Todo> >().Result;

            Assert.IsTrue(oldTodos != null && oldTodos.Count > 0);

            int oldCount = oldTodos.Count;

            Todo first = oldTodos.FirstOrDefault();

            string result = new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL))
                            .DeleteStringAsync(first.Id).Result;

            List <Todo> newTodos = new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL))
                                   .GetModelAsync <List <Todo> >().Result;

            Assert.IsTrue(newTodos != null && newTodos.Count > 0);

            int newCount = newTodos.Count;

            Assert.IsTrue(newCount < oldCount);
        }
Beispiel #11
0
        public void GetString()
        {
            string jsonString = new Unicorn(UnicornConfigFactory.NewInstance(Constants.URL)).GetStringAync().Result;

            Assert.IsTrue(jsonString.Length > 0);
        }