public void Test_WebFileSystem_OpenRead_Returns_Mapped_Path() { var mockFileSystem = new Mock<IFileSystem>(); var mockHttpContextFactory = new Mock<IHttpContextFactory>(); var mockHttpContext = new Mock<IHttpContext>(); var mockHttpServerUtility = new Mock<IHttpServerUtility>(); mockFileSystem .Setup(x => x.OpenRead(It.IsAny<string>())) .Returns(new MemoryStream()); mockHttpServerUtility .Setup(x => x.MapPath(It.IsAny<string>())) .Returns<string>(x=>x); mockHttpContext .SetupGet(x => x.Server) .Returns(mockHttpServerUtility.Object); mockHttpContextFactory .Setup(x => x.CreateContext()) .Returns(mockHttpContext.Object); IFileSystem fileSystem = new WebFileSystem(mockFileSystem.Object, mockHttpContextFactory.Object); using (var result = fileSystem.OpenRead("abc123")) { } mockHttpServerUtility.Verify(x=>x.MapPath(It.IsAny<string>()), Times.Once); }
public void Test_WebFileSystem_OpenRead_Returns_Mapped_Path() { var mockFileSystem = new Mock <IFileSystem>(); var mockHttpContextFactory = new Mock <IHttpContextFactory>(); var mockHttpContext = new Mock <IHttpContext>(); var mockHttpServerUtility = new Mock <IHttpServerUtility>(); mockFileSystem .Setup(x => x.OpenRead(It.IsAny <string>())) .Returns(new MemoryStream()); mockHttpServerUtility .Setup(x => x.MapPath(It.IsAny <string>())) .Returns <string>(x => x); mockHttpContext .SetupGet(x => x.Server) .Returns(mockHttpServerUtility.Object); mockHttpContextFactory .Setup(x => x.CreateContext()) .Returns(mockHttpContext.Object); IFileSystem fileSystem = new WebFileSystem(mockFileSystem.Object, mockHttpContextFactory.Object); using (var result = fileSystem.OpenRead("abc123")) { } mockHttpServerUtility.Verify(x => x.MapPath(It.IsAny <string>()), Times.Once); }