public void PassedCoursesReturnContentResultIfCourseCountZero() { var identity = new GenericIdentity("student1"); var controllerContext = new Mock <ControllerContext>(); var principal = new Mock <IPrincipal>(); principal.SetupGet(x => x.Identity.Name).Returns("student1"); controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object); var mockStudent = new Mock <IStudentRepository>(); var mock = new Mock <IRegisterRepository>(); var mockCourse = new Mock <ICourseRepository>(); StudentController controller = new StudentController(mockCourse.Object, mockStudent.Object, mock.Object); controller.ControllerContext = controllerContext.Object; var student = new Student(); mockStudent.Setup(c => c.GetWithCourses(identity.Name)).Returns(student); student.Courses = new List <Course> { new Course { StartDate = DateTime.Now, Duration = 4 } }; ContentResult result = controller.PassedCourses() as ContentResult; Assert.AreEqual(result.GetType(), typeof(ContentResult)); }
public void Post_AllGood() { Environment.SetEnvironmentVariable("hcb:IsTokenValid", "true"); ContentResult result = reCaptcha.DoWork(token); //Validate the token Assert.AreEqual(typeof(ContentResult), result.GetType()); Assert.AreEqual("true", result.Content); //Now make the validation call. bool isValidToken = contactUs.Validate(token); Assert.AreEqual(true, isValidToken); }
public void Post_DifferentToken() { Environment.SetEnvironmentVariable("hcb:IsTokenValid", "true"); //Force it to look like a valid token ContentResult result = reCaptcha.DoWork(token); //Validate the token Assert.AreEqual(typeof(ContentResult), result.GetType()); Assert.AreEqual("true", result.Content); //Now make the validation call. bool isValidToken = contactUs.Validate(token + "xyz"); Assert.AreEqual(false, isValidToken); }
public void Post_TimedOutToken() { Environment.SetEnvironmentVariable("hcb:IsTokenValid", "true"); //Force token to look like a good one. ContentResult result = reCaptcha.DoWork(token); //Validate the token Assert.AreEqual(typeof(ContentResult), result.GetType()); Assert.AreEqual("true", result.Content); //Now make the validation call. Thread.Sleep(4000); bool isValidToken = contactUs.Validate(token); Assert.AreEqual(false, isValidToken); }
/// <summary> /// 测试不同类型的请求 /// </summary> /// <param name="xml">微信发过来的xml原文</param> private void PostTest(string xml) { Init(xml);//初始化 var timestamp = "itsafaketimestamp"; var nonce = "whateveryouwant"; var signature = Senparc.Weixin.MP.CheckSignature.GetSignature(timestamp, nonce, target.Token); DateTime st = DateTime.Now; //这里使用MiniPost,绕过日志记录 ContentResult actual = target.MiniPost(signature, timestamp, nonce, "echostr") as ContentResult; DateTime et = DateTime.Now; Assert.IsNotNull(actual); Assert.AreEqual(typeof(WeixinResult), actual.GetType()); Console.WriteLine(actual.Content); Console.WriteLine("页面用时(ms):" + (et - st).TotalMilliseconds); }
public void StartedCourseReturnsContextResultIfStudentNull() { var identity = new GenericIdentity("student1"); var controllerContext = new Mock <ControllerContext>(); var principal = new Mock <IPrincipal>(); principal.SetupGet(x => x.Identity.Name).Returns("student1"); controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object); var mockStudent = new Mock <IStudentRepository>(); var mock = new Mock <IRegisterRepository>(); var mockCourse = new Mock <ICourseRepository>(); StudentController controller = new StudentController(mockCourse.Object, mockStudent.Object, mock.Object); controller.ControllerContext = controllerContext.Object; mockStudent.Setup(c => c.GetWithCourses(identity.Name)).Returns((Student)null).Verifiable(); ContentResult result = controller.StartedCourses() as ContentResult; Assert.AreEqual(result.GetType(), typeof(ContentResult)); }
public void WithContentResult_ShouldFail() { ActionResult result = new ContentResult { Content = "{ \"name\" : \"WithJson_GivenExpected_ShouldPass\" }" }; // this is a bit of a hack to build the expected message. There must be a better way? var messageFormat = ActionResultAssertions.Constants.CommonFailMessage .Replace("{reason}", "") .Replace("{", "\"{") .Replace("}", "}\""); var failureMessage = String.Format(messageFormat, typeof(JsonResult).Name, result.GetType().Name); System.Action act = () => result.Should().BeJsonResult(); act.Should().Throw <System.Exception>().WithMessage(failureMessage); }