示例#1
0
        public void TestPhunApiRequireReturnInteralProperties()
        {
            // Arrange
            var connector = new ContentConnector();
            var fakeUtility = new Mock<ResourcePathUtility>();
            var mockRequest = new Mock<HttpRequestBase>();
            var context = new Mock<HttpContextBase>();
            var expectedFileSystem = new Mock<IFileSystem>();
            var expectedPath = new Mock<IPath>();

            mockRequest.Setup(rq => rq.Url).Returns(new Uri("http://localhost/testz"));
            mockRequest.Setup(rq => rq.Path).Returns("/testz");
            context.Setup(ctx => ctx.Request).Returns(mockRequest.Object);
            fakeUtility.Setup(u => u.PhunPartialEditable(It.IsAny<Uri>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<object>())).Verifiable();

            var api = new PhunApi(context.Object, connector);
            api.utility = fakeUtility.Object;
            api.phunFileSystem = expectedFileSystem.Object;
            api.phunPath = expectedPath.Object;

            // Act
            // Assert
            Assert.AreEqual(expectedFileSystem.Object, api.require("fs"));
            Assert.AreEqual(expectedPath.Object, api.require("path"));
            Assert.AreEqual(null, api.require("unknown"));
        }
示例#2
0
        public void TestPhunApiRequireReturnAnInstanceOfRegisteredApiObject()
        {
            // Arrange
            var connector = new ContentConnector();
            var fakeUtility = new Mock<ResourcePathUtility>();
            var mockRequest = new Mock<HttpRequestBase>();
            var context = new Mock<HttpContextBase>();

            mockRequest.Setup(rq => rq.Url).Returns(new Uri("http://localhost/testz"));
            mockRequest.Setup(rq => rq.Path).Returns("/testz");
            context.Setup(ctx => ctx.Request).Returns(mockRequest.Object);
            fakeUtility.Setup(u => u.PhunPartialEditable(It.IsAny<Uri>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<object>())).Verifiable();

            var api = new PhunApi(context.Object, connector);
            api.utility = fakeUtility.Object;
            Bootstrapper.Default.RegisterRequireJsModule<ContentConnector>("connector");

            // Act
            var result = api.require("connector");
            Bootstrapper.Default.ApiList.Clear();

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ContentConnector));
        }