示例#1
0
        public void CanGetViewResult()
        {
            lock (TestOrderingLock.Lock)
            {
                var se       = new MinimalTypeSystemHack();
                var osResult = new ViewActionResult();

                osResult.ViewData             = InitViewData();
                osResult.ViewData["MyData"]   = ValueFactory.Create("string data");
                osResult.ViewData["MyObject"] = new StructureImpl();

                osResult.ViewData.Model = new ArrayImpl();

                var realAction = osResult.CreateExecutableResult();
                Assert.IsType(typeof(string), realAction.ViewData["MyData"]);
                Assert.IsType(typeof(DynamicContextWrapper), realAction.ViewData["MyObject"]);
                Assert.IsType(typeof(DynamicContextWrapper), realAction.ViewData.Model);

                var structWrap = realAction.ViewData["MyObject"] as DynamicContextWrapper;
                var arrayWrap  = realAction.ViewData.Model as DynamicContextWrapper;

                Assert.Equal(osResult.ViewData["MyObject"], structWrap.UnderlyingObject);
                Assert.Equal(osResult.ViewData.Model, structWrap.UnderlyingObject);
            }
        }
示例#2
0
        public void ViewResultDataAccessibleThroughScript()
        {
            lock (TestOrderingLock.Lock)
            {
                var se       = new MinimalTypeSystemHack();
                var osResult = new ViewActionResult();
                osResult.ViewData           = InitViewData();
                osResult.ViewData["MyData"] = ValueFactory.Create("string data");

                Assert.Equal("string data", osResult.ViewData.GetIndexedValue(ValueFactory.Create("MyData")).AsString());
            }
        }
        public void WrapStructureIndices()
        {
            lock (TestOrderingLock.Lock)
            {
                var se = new MinimalTypeSystemHack();

                var structure = new StructureImpl("Свойство1,Свойство2",
                                                  ValueFactory.Create(1),
                                                  ValueFactory.Create("Hello"));

                dynamic dynStructure = new DynamicContextWrapper(structure);
                Assert.Equal <int>(1, (int)dynStructure["Свойство1"]);
                Assert.Equal <string>("Hello", dynStructure["Свойство2"]);
            }
        }
示例#4
0
        public void ContentTypeIsReflectedInHeadersAfterAssignment()
        {
            lock (TestOrderingLock.Lock)
            {
                var se       = new MinimalTypeSystemHack();
                var context  = new DefaultHttpContext();
                var response = new DefaultHttpResponse(context);

                var scriptRequest = new HttpResponseImpl(response);
                scriptRequest.ContentType = "text/plain";
                Assert.True(scriptRequest.Headers.GetIndexedValue(ValueFactory.Create("Content-Type")).AsString().Equals("text/plain"));
                Assert.Equal("text/plain", scriptRequest.RealObject.Headers["Content-Type"]);
                Assert.Equal("text/plain", scriptRequest.RealObject.ContentType);
            }
        }
        public void WrapStructureMethodsCall()
        {
            lock (TestOrderingLock.Lock)
            {
                var se = new MinimalTypeSystemHack();

                var     structure    = new StructureImpl();
                dynamic dynStructure = new DynamicContextWrapper(structure);

                dynStructure.Вставить("Свойство1", 1);
                dynStructure.Вставить("Свойство2", "Hello");

                Assert.Equal <int>(1, (int)dynStructure["Свойство1"]);
                Assert.Equal <string>("Hello", dynStructure["Свойство2"]);
            }
        }
示例#6
0
        public void RequestHeadersAccessibleThrough_MapImpl()
        {
            lock (TestOrderingLock.Lock)
            {
                var se      = new MinimalTypeSystemHack();
                var request = new Mock <HttpRequest>();
                var headers = new HeaderDictionary();
                headers.Add("Content-Length", "12312");
                headers.Add("Content-Encoding", "utf-8");
                request.SetupGet(x => x.Headers).Returns(headers);

                var scriptRequest = new HttpRequestImpl(request.Object);

                Assert.Equal(2, scriptRequest.Headers.Count());
                Assert.Equal(headers["Content-Length"], scriptRequest.Headers.GetIndexedValue(ValueFactory.Create("Content-Length")).AsString());
                Assert.Equal(headers["Content-Encoding"], scriptRequest.Headers.GetIndexedValue(ValueFactory.Create("Content-Encoding")).AsString());
            }
        }
示例#7
0
        public void ResponseHeadersCanBeSetFrom_MapImpl()
        {
            lock (TestOrderingLock.Lock)
            {
                var se       = new MinimalTypeSystemHack();
                var response = new Mock <HttpResponse>();
                var headers  = new MapImpl();
                headers.SetIndexedValue(ValueFactory.Create("Content-Length"), ValueFactory.Create("123456"));
                headers.SetIndexedValue(ValueFactory.Create("Content-Encoding"), ValueFactory.Create("utf-8"));

                var testedHeaders = new HeaderDictionary();
                response.SetupGet(x => x.Headers).Returns(testedHeaders);

                var scriptRequest = new HttpResponseImpl(response.Object);
                scriptRequest.SetHeaders(headers);

                Assert.Equal(testedHeaders["Content-Length"], "123456");
                Assert.Equal(testedHeaders["Content-Encoding"], "utf-8");
            }
        }
示例#8
0
        public void FormDataIsAccessible()
        {
            lock (TestOrderingLock.Lock)
            {
                var se = new MinimalTypeSystemHack();

                var fileMock = new Mock <IFormFile>();
                fileMock.SetupGet(x => x.Name).Returns("uploaded");

                var filesMock = new Mock <IFormFileCollection>();
                filesMock.SetupGet(x => x.Count).Returns(1);
                filesMock.Setup(x => x.GetFile("uploaded")).Returns(fileMock.Object);
                filesMock.Setup(x => x.GetEnumerator()).Returns(() =>
                {
                    var arr = new List <IFormFile>
                    {
                        fileMock.Object
                    };
                    return(arr.GetEnumerator());
                });

                var formMock = new Mock <IFormCollection>();
                formMock.SetupGet(x => x.Files).Returns(filesMock.Object);

                var requestMock = new Mock <HttpRequest>();
                requestMock.SetupGet(x => x.Form).Returns(formMock.Object);
                requestMock.SetupGet(x => x.Headers).Returns(new HeaderDictionary());

                var request = new HttpRequestImpl(requestMock.Object);

                Assert.Equal(1, request.FormData.Files.Count());
                Assert.IsType(typeof(FormDataCollectionContext), request.FormData);
                Assert.IsType(typeof(FormFilesCollectionContext), request.FormData.Files);

                var fFile    = request.FormData.Files[0];
                var fFileInt = request.FormData.Files["uploaded"];

                Assert.Equal(fFile, fFileInt);
            }
        }
        public void WrapStructureEnumeration()
        {
            lock (TestOrderingLock.Lock)
            {
                var se = new MinimalTypeSystemHack();

                var     structure    = new StructureImpl();
                dynamic dynStructure = new DynamicContextWrapper(structure);

                dynStructure.Вставить("Свойство1", 1);
                dynStructure.Вставить("Свойство2", "Hello");

                int cnt = 0;
                foreach (var kv in dynStructure)
                {
                    ++cnt;
                    Assert.IsType(typeof(DynamicContextWrapper), kv);
                }

                Assert.Equal(2, cnt);
            }
        }