本文整理汇总了C#中Mock.ExpectSet方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.ExpectSet方法的具体用法?C# Mock.ExpectSet怎么用?C# Mock.ExpectSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mock
的用法示例。
在下文中一共展示了Mock.ExpectSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteResult
public void ExecuteResult() {
// Arrange
object data = _jsonData;
string contentType = "Some content type.";
Encoding contentEncoding = Encoding.UTF8;
// Arrange expectations
Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict);
mockControllerContext.ExpectGet(c => c.HttpContext.Request.HttpMethod).Returns("POST").Verifiable();
mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentType, contentType).Verifiable();
mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentEncoding, contentEncoding).Verifiable();
mockControllerContext.Expect(c => c.HttpContext.Response.Write(_jsonSerializedData)).Verifiable();
JsonResult result = new JsonResult {
Data = data,
ContentType = contentType,
ContentEncoding = contentEncoding
};
// Act
result.ExecuteResult(mockControllerContext.Object);
// Assert
mockControllerContext.Verify();
}
示例2: OnException
public void OnException() {
// Arrange
HandleErrorAttribute attr = new HandleErrorAttribute() {
View = "SomeView",
Master = "SomeMaster",
ExceptionType = typeof(ArgumentException)
};
Exception exception = new ArgumentNullException();
Mock<HttpContextBase> mockHttpContext = new Mock<HttpContextBase>(MockBehavior.Strict);
mockHttpContext.Expect(c => c.IsCustomErrorEnabled).Returns(true);
mockHttpContext.Expect(c => c.Session).Returns((HttpSessionStateBase)null);
mockHttpContext.Expect(c => c.Response.Clear()).Verifiable();
mockHttpContext.ExpectSet(c => c.Response.StatusCode, 500).Verifiable();
mockHttpContext.ExpectSet(c => c.Response.TrySkipIisCustomErrors, true).Verifiable();
TempDataDictionary tempData = new TempDataDictionary();
IViewEngine viewEngine = new Mock<IViewEngine>().Object;
Controller controller = new Mock<Controller>().Object;
controller.TempData = tempData;
ExceptionContext context = GetExceptionContext(mockHttpContext.Object, controller, exception);
// Exception
attr.OnException(context);
// Assert
mockHttpContext.Verify();
ViewResult viewResult = context.Result as ViewResult;
Assert.IsNotNull(viewResult, "The Result property should have been set to an instance of ViewResult.");
Assert.AreEqual(tempData, viewResult.TempData);
Assert.AreEqual("SomeView", viewResult.ViewName);
Assert.AreEqual("SomeMaster", viewResult.MasterName);
HandleErrorInfo viewData = viewResult.ViewData.Model as HandleErrorInfo;
Assert.IsNotNull(viewData, "The ViewData model should have been set to an instance of ExceptionViewData.");
Assert.AreSame(exception, viewData.Exception);
Assert.AreEqual("SomeController", viewData.ControllerName);
Assert.AreEqual("SomeAction", viewData.ActionName);
}
示例3: ExecuteResult
public void ExecuteResult() {
// Arrange
Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict);
mockControllerContext.ExpectSet(c => c.HttpContext.Response.StatusCode, 401).Verifiable();
HttpUnauthorizedResult result = new HttpUnauthorizedResult();
// Act
result.ExecuteResult(mockControllerContext.Object);
// Assert
mockControllerContext.Verify();
}
示例4: EmptyContentTypeRendersDefault
public void EmptyContentTypeRendersDefault() {
// Arrange
object data = _jsonData;
Encoding contentEncoding = Encoding.UTF8;
// Arrange expectations
Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict);
mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentType, "application/json").Verifiable();
mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentEncoding, contentEncoding).Verifiable();
mockControllerContext.Expect(c => c.HttpContext.Response.Write(_jsonSerializedData)).Verifiable();
JsonResult result = new JsonResult {
Data = data,
ContentType = String.Empty,
ContentEncoding = contentEncoding
};
// Act
result.ExecuteResult(mockControllerContext.Object);
// Assert
mockControllerContext.Verify();
}
示例5: CreateClassMockTest
public void CreateClassMockTest()
{
var mock = new Mock<Mocked>();
mock.ExpectCall(m => m.Method(2)).Returns("2").Once();
mock.ExpectGet(m => m.Property).Gets(2).Never();
mock.ExpectSet(m => m.Property).Sets(2).Never();
var value = mock.Object.Method(2);
mock.Verify();
Assert.That(value, Is.EqualTo("2"));
}
示例6: ExecuteResultDoesNotSetContentDispositionIfNotSpecified
public void ExecuteResultDoesNotSetContentDispositionIfNotSpecified() {
// Arrange
Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict);
mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentType, "application/my-type").Verifiable();
EmptyFileResult result = new EmptyFileResult("application/my-type");
// Act
result.ExecuteResult(mockControllerContext.Object);
// Assert
Assert.IsTrue(result.WasWriteFileCalled);
mockControllerContext.Verify();
}
示例7: ConfigureSessionState_Default_DoesNothing
public void ConfigureSessionState_Default_DoesNothing() {
// Arrange
Mock<HttpContextBase> mockHttpContext = new Mock<HttpContextBase>();
mockHttpContext.ExpectSet(o => o.Handler).Never();
HttpContextBase httpContext = mockHttpContext.Object;
DynamicSessionStateConfigurator35 configurator = new DynamicSessionStateConfigurator35(httpContext);
// Act
configurator.ConfigureSessionState(ControllerSessionState.Default);
IHttpHandler newHandler = httpContext.Handler;
// Assert
mockHttpContext.Verify();
}
示例8: ExecuteResult
public void ExecuteResult() {
// Arrange
string content = "Some content.";
string contentType = "Some content type.";
Encoding contentEncoding = Encoding.UTF8;
// Arrange expectations
Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict);
mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentType, contentType).Verifiable();
mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentEncoding, contentEncoding).Verifiable();
mockControllerContext.Expect(c => c.HttpContext.Response.Write(content)).Verifiable();
ContentResult result = new ContentResult {
Content = content,
ContentType = contentType,
ContentEncoding = contentEncoding
};
// Act
result.ExecuteResult(mockControllerContext.Object);
// Assert
mockControllerContext.Verify();
}
示例9: NullScriptIsNotOutput
public void NullScriptIsNotOutput() {
// Arrange
string contentType = "application/x-javascript";
// Arrange expectations
Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict);
mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentType, contentType).Verifiable();
JavaScriptResult result = new JavaScriptResult();
// Act
result.ExecuteResult(mockControllerContext.Object);
// Assert
mockControllerContext.Verify();
}
示例10: ContentDispositionHeaderIsEncodedCorrectlyForUnicodeCharacters
public void ContentDispositionHeaderIsEncodedCorrectlyForUnicodeCharacters() {
// Arrange
Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict);
mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentType, "application/my-type").Verifiable();
mockControllerContext.Expect(c => c.HttpContext.Response.AddHeader("Content-Disposition", @"attachment; filename*=UTF-8''ABCXYZabcxyz012789!%40%23$%25%5E&%2A%28%29-%3D_+.:~%CE%94")).Verifiable();
EmptyFileResult result = new EmptyFileResult("application/my-type") {
FileDownloadName = "[email protected]#$%^&*()-=_+.:~Δ"
};
// Act
result.ExecuteResult(mockControllerContext.Object);
// Assert
Assert.IsTrue(result.WasWriteFileCalled);
mockControllerContext.Verify();
}
示例11: ExecuteResultSetsContentDispositionIfSpecified
public void ExecuteResultSetsContentDispositionIfSpecified() {
// Arrange
Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict);
mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentType, "application/my-type").Verifiable();
mockControllerContext.Expect(c => c.HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=filename.ext")).Verifiable();
EmptyFileResult result = new EmptyFileResult("application/my-type") {
FileDownloadName = "filename.ext"
};
// Act
result.ExecuteResult(mockControllerContext.Object);
// Assert
Assert.IsTrue(result.WasWriteFileCalled);
mockControllerContext.Verify();
}
示例12: ContentDispositionHeaderIsEncodedCorrectly
public void ContentDispositionHeaderIsEncodedCorrectly() {
// See comment in FileResult.cs detailing how the FileDownloadName should be encoded.
// Arrange
Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict);
mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentType, "application/my-type").Verifiable();
mockControllerContext.Expect(c => c.HttpContext.Response.AddHeader("Content-Disposition", @"attachment; filename=""some\\file""")).Verifiable();
EmptyFileResult result = new EmptyFileResult("application/my-type") {
FileDownloadName = @"some\file"
};
// Act
result.ExecuteResult(mockControllerContext.Object);
// Assert
Assert.IsTrue(result.WasWriteFileCalled);
mockControllerContext.Verify();
}
示例13: ExecuteResult
public void ExecuteResult() {
// Arrange
string script = "alert('foo');";
string contentType = "application/x-javascript";
// Arrange expectations
Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict);
mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentType, contentType).Verifiable();
mockControllerContext.Expect(c => c.HttpContext.Response.Write(script)).Verifiable();
JavaScriptResult result = new JavaScriptResult {
Script = script
};
// Act
result.ExecuteResult(mockControllerContext.Object);
// Assert
mockControllerContext.Verify();
}
示例14: NullContentIsNotOutput
public void NullContentIsNotOutput() {
// Arrange
string contentType = "Some content type.";
Encoding contentEncoding = Encoding.UTF8;
// Arrange expectations
Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict);
mockControllerContext.ExpectGet(c => c.HttpContext.Request.HttpMethod).Returns("POST").Verifiable();
mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentType, contentType).Verifiable();
mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentEncoding, contentEncoding).Verifiable();
JsonResult result = new JsonResult {
ContentType = contentType,
ContentEncoding = contentEncoding
};
// Act
result.ExecuteResult(mockControllerContext.Object);
// Assert
mockControllerContext.Verify();
}
示例15: OnResultExecuting_ItemsFlagSet_ReplacesOutputWriter
public void OnResultExecuting_ItemsFlagSet_ReplacesOutputWriter() {
// Arrange
TextWriter originalWriter = TextWriter.Null;
TextWriter newWriter = null;
Mock<ResultExecutingContext> mockFilterContext = new Mock<ResultExecutingContext>();
mockFilterContext.Expect(o => o.HttpContext.Items[It.IsAny<object>()]).Returns("theCacheKey");
mockFilterContext.Expect(o => o.HttpContext.Response.Output).Returns(originalWriter);
mockFilterContext
.ExpectSet(o => o.HttpContext.Response.Output)
.Callback(w => { newWriter = w; });
// Act
ChildActionCacheAttribute attr = new ChildActionCacheAttribute() {
Duration = 10
};
// Act
attr.OnResultExecuting(mockFilterContext.Object);
// Assert
ChildActionCacheAttribute.WrappedStringWriter stringWriter = newWriter as ChildActionCacheAttribute.WrappedStringWriter;
Assert.IsNotNull(stringWriter);
Assert.AreEqual(originalWriter, stringWriter.OriginalWriter);
}