public void GetByCode_Return_InternalServerError() { //Setup Mock <IServiceProvider> serviceProvider = GetServiceProvider(); GarmentDetailCurrencyService service = new GarmentDetailCurrencyService(serviceProvider.Object); serviceProvider.Setup(s => s.GetService(typeof(GarmentDetailCurrencyService))).Returns(service); //Act IActionResult response = GetController(service).GetByCode(null); //Assert int statusCode = this.GetStatusCode(response); Assert.Equal((int)HttpStatusCode.InternalServerError, statusCode); }
public void GetByCode_Return_Ok() { //Setup CoreDbContext dbContext = _dbContext(GetCurrentAsyncMethod()); Mock <IServiceProvider> serviceProvider = GetServiceProvider(); GarmentDetailCurrencyService service = new GarmentDetailCurrencyService(serviceProvider.Object); serviceProvider.Setup(s => s.GetService(typeof(GarmentDetailCurrencyService))).Returns(service); serviceProvider.Setup(s => s.GetService(typeof(CoreDbContext))).Returns(dbContext); Lib.Models.GarmentDetailCurrency testData = GetTestData(dbContext); //Act IActionResult response = GetController(service).GetByCode(""); //Assert int statusCode = this.GetStatusCode(response); Assert.Equal((int)HttpStatusCode.OK, statusCode); }
protected GarmentDetailCurrenciesController GetController(GarmentDetailCurrencyService service) { var user = new Mock <ClaimsPrincipal>(); var claims = new Claim[] { new Claim("username", "unittestusername") }; user.Setup(u => u.Claims).Returns(claims); GarmentDetailCurrenciesController controller = new GarmentDetailCurrenciesController(service); controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user.Object } }; controller.ControllerContext.HttpContext.Request.Headers["Authorization"] = "Bearer unittesttoken"; controller.ControllerContext.HttpContext.Request.Path = new PathString("/v1/unit-test"); return(controller); }