mercredi 25 mai 2016

write Rhino Mock Test cases for Web api

HI have created a WEBAPI below. i am trying to write rhino Mocks for below API i have tried a lot but everytime i failed

WEBAPI Code

[Route("api/{Home}/{Username}/{Password}")]
        public HttpResponseMessage Get(string Username, string Password)

        {
            HttpResponseMessage response;
            var display = Userloginvalues().Where(m => m.UserName == Username && m.Password == Password).FirstOrDefault();
            if (display != null)
            {
                response = Request.CreateResponse(HttpStatusCode.OK);
                response.Content = new StringContent("xxxx.", Encoding.Unicode);
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound);
                response.Content = new StringContent("xxxx", Encoding.Unicode);
            }
            return response;

        }
        public static List<LoginModel> Userloginvalues()
        {
            List<LoginModel> objModel = new List<LoginModel>();
            objModel.Add(new LoginModel { UserName = "test", Password = "test" });
            return objModel;
        }

RHIN MOCKS i tried below but dont know how to proceed

MockRepository mocks = new MockRepository();
            WebApplication1.Models.ILoginRepository login = mocks.Stub<WebApplication1.Models.ILoginRepository>();
            HttpResponseMessage _respone;
            _respone = login.Get("test", "test");

Aucun commentaire:

Enregistrer un commentaire