示例#1
0
        public void CheckCacheCount()
        {
            int CacheCount = 0;

            #region GetcacheCount
            //Arrange
            var controller = new CacheController(new ToDoBL(new ToDoRepository(), new DataCache()));

            controller.Request = new HttpRequestMessage
            {
                Method = HttpMethod.Get
            };

            //Actual
            var response = controller.Get();
            int.TryParse(response.Content.ReadAsStringAsync().Result.ToString(), out CacheCount);
            #endregion


            #region Add item
            //Arrange
            var controllerAdd = new ToDoController(new ToDoBL(new ToDoRepository(), new DataCache()));

            controllerAdd.Request = new HttpRequestMessage
            {
                Method = HttpMethod.Post
            };
            int      id      = 100;
            ToDoItem request = new ToDoItem()
            {
                Id = id, Name = "Test Data"
            };

            //Actual
            var responseAdd = controllerAdd.Post(request);
            #endregion


            #region Validate Count
            //Arrange
            var controllerValidate = new CacheController(new ToDoBL(new ToDoRepository(), new DataCache()));

            controllerValidate.Request = new HttpRequestMessage
            {
                Method = HttpMethod.Get
            };

            //Actual
            var responseValidate      = controllerValidate.Get();
            int CacheCountAfterInsert = 0;
            int.TryParse(responseValidate.Content.ReadAsStringAsync().Result.ToString(), out CacheCountAfterInsert);

            Assert.AreEqual((CacheCount + 1), CacheCountAfterInsert);
            #endregion
        }
示例#2
0
        public void GetCacheException()
        {
            //Arrange
            var controller = new CacheController(new ToDoMockService());

            controller.Request = new HttpRequestMessage
            {
                Method = HttpMethod.Get
            };

            //Actual
            var response = controller.Get();

            //Assert
            Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
        }
示例#3
0
        public void GetCache()
        {
            //Arrange
            var controller = new CacheController(new ToDoBL(new ToDoRepository(), new DataCache()));

            controller.Request = new HttpRequestMessage
            {
                Method = HttpMethod.Get
            };

            //Actual
            var response = controller.Get();

            //Assert
            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Content);
            Assert.IsTrue(response.IsSuccessStatusCode);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }