Ejemplo n.º 1
0
        public void AspxPagesAreNotAddedToLifetimeContainer()
        {
            TestableWebClientApplication application = new TestableWebClientApplication();
            MockHttpContext mockContext = new MockHttpContext();
            MockPage        mockPage    = new MockPage();

            mockContext.Request             = new HttpRequest("page.aspx", "http://application/page.aspx", null);
            mockContext.Handler             = mockPage;
            mockContext.ApplicationInstance = application;
            TestableRootCompositionContainer container = new TestableRootCompositionContainer();

            application.ModuleContainer = container;
            application.SetTestCurrentContext(mockContext);

            application.TestRun();

            int lifetimeObjects = container.Locator.Count;

            //application.TestPreRequestHandlerExecute(mockContext);
            mockPage.CallOnInit();

            Assert.IsNotNull(mockPage.Presenter);
            Assert.IsNull(container.Locator.Get <MockPresenter>());
            Assert.IsNull(container.Locator.Get <MockPage>());

            //application.TestPostRequestHandlerExecute(mockContext);

            Assert.AreEqual(lifetimeObjects, container.Locator.Count);
        }
Ejemplo n.º 2
0
        public async Task AutoWireViewModel_With_Custom_Resolver_And_Factory()
        {
            await ExecuteOnUIThread(() =>
            {
                var page = new MockPage();

                // Set the ViewTypeToViewModelTypeResolver
                ViewModelLocator.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
                {
                    var viewName = viewType.FullName;

                    // The ViewModel is in the same namespace as the View
                    var viewModelName = String.Format("{0}ViewModel", viewName);
                    return(Type.GetType(viewModelName));
                });

                // Set the ViewTypeToViewModelTypeResolver
                ViewModelLocator.SetDefaultViewModelFactory((viewModelType) =>
                {
                    // The ViewModel has a constructor with no parameters
                    return(Activator.CreateInstance(viewModelType) as ViewModel);
                });

                // Fire AutoWireViewModelChanged
                ViewModelLocator.SetAutoWireViewModel(page, true);

                Assert.IsNotNull(page.DataContext);
                Assert.IsInstanceOfType(page.DataContext, typeof(MockPageViewModel));
            });
        }
Ejemplo n.º 3
0
        public async Task NavigateFromCurrentViewModel_Calls_VieModel_OnNavigatedFrom()
        {
            await ExecuteOnUIThread(() =>
            {
                var frame = new FrameFacadeAdapter(new Frame());

                bool viewModelNavigatedFromCalled = false;
                var viewModel = new MockPageViewModel();
                viewModel.OnNavigatedFromCommand = (frameState, suspending) =>
                {
                    Assert.IsFalse(suspending);
                    viewModelNavigatedFromCalled = true;
                };

                var sessionStateService = new MockSessionStateService();
                sessionStateService.GetSessionStateForFrameDelegate = (currentFrame) => new Dictionary <string, object>();

                var navigationService = new FrameNavigationService(frame, (pageToken) => typeof(MockPage), sessionStateService);

                // Initial navigatio
                navigationService.Navigate("page0", 0);

                // Set up the frame's content with a Page
                var view         = new MockPage();
                view.DataContext = viewModel;
                frame.Content    = view;

                // Navigate to fire the NavigatedToCurrentViewModel
                navigationService.Navigate("page1", 1);

                Assert.IsTrue(viewModelNavigatedFromCalled);
            });
        }
Ejemplo n.º 4
0
            public void AddPage(string url, Dictionary <string, string> postData, string result)
            {
                MockPage page = new MockPage();

                page.url      = url;
                page.postData = postData;
                page.result   = result;
                this.mockPages.Add(page);
            }
Ejemplo n.º 5
0
        public void TestDefaultPage()
        {
            MockPage page = new MockPage();

            server.AddPage(page);
            string text = WebUtils.PlainText(WebUtils.ReadPage(server.Url));

            Assert.IsTrue(text.Contains("test page"), "Didn't output test page");
        }
        public void AutoWireViewModelWithFactoryRegistration()
        {
            var page = new MockPage();

            ViewModelLocator.Register(typeof(MockPage).ToString(), () => new MockPageViewModel());
            ViewModelLocator.SetAutoWireViewModel(page, true);

            Assert.IsNotNull(page.BindingContext);
            Assert.IsInstanceOf(typeof(MockPageViewModel), page.BindingContext);
        }
Ejemplo n.º 7
0
        public void TestGetForm()
        {
            MockPage page = new MockPage();

            server.AddPage(page);
            string query = "?rabbits=funny&fortytwo=42&floating=134.2&german=99,31";

            WebUtils.ReadPage(server.Url + page.Name() + query);
            Assert.AreEqual("funny", page.Query["rabbits"]);
            Assert.AreEqual("42", page.Query["fortytwo"]);
            Assert.AreEqual("134.2", page.Query["floating"]);
            Assert.AreEqual("99,31", page.Query["german"]);
            Assert.AreEqual(4, page.Query.Count);
        }
Ejemplo n.º 8
0
        public void TestPageWithoutHeaders()
        {
            MockPage page = new MockPage();

            server.AddPage(page);
            string text = WebUtils.PlainText(WebUtils.ReadPage(server.Url + page.Name()));

            Assert.IsTrue(text.Contains("test page"), "Didn't output test page");
            Assert.AreEqual(null, page.SystemName);
            Assert.AreEqual(null, page.CharName);
            Assert.AreEqual(null, page.CharId);
            Assert.AreEqual(1, page.Headers.Count);
            Assert.AreEqual("Host", page.Headers.GetKey(0));
        }
Ejemplo n.º 9
0
        public async Task AutoWireViewModel_With_Factory_Registration()
        {
            await ExecuteOnUIThread(() =>
            {
                var page = new MockPage();

                // Register the ViewModel to the page
                ViewModelLocator.Register(typeof(MockPage).ToString(), () => new MockPageViewModel());

                // Fire AutoWireViewModelChanged
                ViewModelLocator.SetAutoWireViewModel(page, true);

                Assert.IsNotNull(page.DataContext);
                Assert.IsInstanceOfType(page.DataContext, typeof(MockPageViewModel));
            });
        }
Ejemplo n.º 10
0
        public void TestPageWithHeaders()
        {
            MockPage page = new MockPage();

            server.AddPage(page);
            NameValueCollection headers = new NameValueCollection();

            headers.Add("Eve.solarsystemname", "Sol");
            headers.Add("Eve.charname", "Mark");
            headers.Add("Eve.charid", "1");
            headers.Add("Eve.otherinformation", "Sunsets are beautiful");
            string text = WebUtils.PlainText(WebUtils.ReadPageWithHeaders(server.Url + page.Name(), headers, null));

            Assert.IsTrue(text.Contains("test page"), "Didn't output test page");
            Assert.AreEqual("Sol", page.SystemName);
            Assert.AreEqual("Mark", page.CharName);
            Assert.AreEqual("1", page.CharId);
            Assert.AreEqual(5, page.Headers.Count);
            Assert.AreEqual("Sunsets are beautiful", page.Headers["Eve.otherinformation"]);
        }
Ejemplo n.º 11
0
        public async Task AutoWireViewModel_With_Custom_Resolver()
        {
            await DispatcherHelper.ExecuteOnUIThread(() =>
            {
                var page = new MockPage();

                // Set the ViewTypeToViewModelTypeResolver
                ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
                {
                    var viewName = viewType.FullName;

                    // The ViewModel is in the same namespace as the View
                    var viewModelName = String.Format("{0}ViewModel", viewName);
                    return(Type.GetType(viewModelName));
                });

                // Fire AutoWireViewModelChanged
                ViewModelLocator.SetAutoWireViewModel(page, true);

                Assert.IsNotNull(page.DataContext);
                Assert.IsInstanceOfType(page.DataContext, typeof(MockPageViewModel));
            });
        }
Ejemplo n.º 12
0
        public void NestedUserControlsAreBuiltCorrectly()
        {
            TestableWebClientApplication application = new TestableWebClientApplication();
            MockHttpContext mockContext = new MockHttpContext();
            MockPage        mockPage    = new MockPage();

            mockContext.Request             = new HttpRequest("page.aspx", "http://application/page.aspx", null);
            mockContext.Handler             = mockPage;
            mockContext.ApplicationInstance = application;
            TestableRootCompositionContainer container = new TestableRootCompositionContainer();

            application.ModuleContainer = container;
            application.SetTestCurrentContext(mockContext);

            application.TestRun();
            mockPage.CallOnInit();
            mockPage.MyControl.CallOnInit();
            mockPage.MyControl.Nested.CallOnInit();

            Assert.IsNotNull(mockPage.Presenter);
            Assert.IsNotNull(mockPage.MyControl.MyControlPresenter);
            Assert.IsNotNull(mockPage.MyControl.Nested.MyControlPresenter);
        }
        private ITenantsOperations GetTenantMock(List <TenantIdDescription> tenants)
        {
            var tenantMock = new Mock <ITenantsOperations>();

            tenantMock.Setup(t => t.ListWithHttpMessagesAsync(It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>()))
            .Returns(
                (Dictionary <string, List <string> > ch, CancellationToken token) =>
            {
                if (TenantListQueueVerLatest != null && TenantListQueueVerLatest.Any())
                {
                    return(ListTenantQueueDequeueVerLatest());
                }
                var mockPage = new MockPage <TenantIdDescription>(tenants);

                AzureOperationResponse <IPage <TenantIdDescription> > r = new AzureOperationResponse <IPage <TenantIdDescription> >
                {
                    Body = mockPage
                };

                return(Task.FromResult(r));
            }
                );
            return(tenantMock.Object);
        }
        public SubscriptionClient GetSubscriptionClient()
        {
            var tenantMock = new Mock <ITenantsOperations>();

            tenantMock.Setup(t => t.ListWithHttpMessagesAsync(It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>()))
            .Returns(
                (Dictionary <string, List <string> > ch, CancellationToken token) =>
            {
                var tenants  = _tenants.Select((k) => new TenantIdDescription(id: k, tenantId: k));
                var mockPage = new MockPage <TenantIdDescription>(tenants.ToList());

                AzureOperationResponse <IPage <TenantIdDescription> > r = new AzureOperationResponse <IPage <TenantIdDescription> >
                {
                    Body = mockPage
                };

                return(Task.FromResult(r));
            }
                );
            var subscriptionMock = new Mock <ISubscriptionsOperations>();

            subscriptionMock.Setup(
                s => s.GetWithHttpMessagesAsync(It.IsAny <string>(), It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>())).Returns(
                (string subId, Dictionary <string, List <string> > ch, CancellationToken token) =>
            {
                if (_getAsyncQueue != null && _getAsyncQueue.Any())
                {
                    return(Task.FromResult(_getAsyncQueue.Dequeue().Invoke()));
                }
                AzureOperationResponse <Subscription> result = new AzureOperationResponse <Subscription>
                {
                    RequestId = Guid.NewGuid().ToString()
                };
                if (_subscriptionSet.Contains(subId))
                {
                    result.Body =
                        new Subscription(
                            id: subId,
                            subscriptionId: subId,
                            tenantId: null,
                            displayName: GetSubscriptionNameFromId(subId),
                            state: SubscriptionState.Enabled,
                            subscriptionPolicies: null,
                            authorizationSource: null);
                }

                return(Task.FromResult(result));
            });
            subscriptionMock.Setup(
                (s) => s.ListWithHttpMessagesAsync(null, It.IsAny <CancellationToken>())).Returns(
                (Dictionary <string, List <string> > ch, CancellationToken token) =>
            {
                if (_listAsyncQueue != null && _listAsyncQueue.Any())
                {
                    return(Task.FromResult(_listAsyncQueue.Dequeue().Invoke()));
                }

                AzureOperationResponse <IPage <Subscription> > result = null;
                if (_subscriptions.Count > 0)
                {
                    var subscriptionList = _subscriptions.Dequeue();
                    result = new AzureOperationResponse <IPage <Subscription> >
                    {
                        RequestId = Guid.NewGuid().ToString(),
                        Body      = new MockPage <Subscription>(
                            new List <Subscription>(
                                subscriptionList.Select(
                                    sub =>
                                    new Subscription(
                                        id: sub,
                                        subscriptionId: sub,
                                        tenantId: null,
                                        displayName: GetSubscriptionNameFromId(sub),
                                        state: SubscriptionState.Enabled,
                                        subscriptionPolicies: null,
                                        authorizationSource: null))), "LinkToNextPage")
                    };
                }

                return(Task.FromResult(result));
            });
            subscriptionMock.Setup(
                (s) => s.ListNextWithHttpMessagesAsync("LinkToNextPage", null, It.IsAny <CancellationToken>())).Returns(
                (string nextLink, Dictionary <string, List <string> > ch, CancellationToken token) =>
            {
                AzureOperationResponse <IPage <Subscription> > result = null;
                if (_subscriptions.Count > 0)
                {
                    var subscriptionList = _subscriptions.Dequeue();
                    result = new AzureOperationResponse <IPage <Subscription> >
                    {
                        RequestId = Guid.NewGuid().ToString(),
                        Body      = new MockPage <Subscription>(
                            new List <Subscription>(
                                subscriptionList.Select(
                                    sub =>
                                    new Subscription(
                                        id: sub,
                                        subscriptionId: sub,
                                        tenantId: null,
                                        displayName: GetSubscriptionNameFromId(sub),
                                        state: SubscriptionState.Disabled,
                                        subscriptionPolicies: null,
                                        authorizationSource: null))))
                    };
                }
                return(Task.FromResult(result));
            });
            var client = new Mock <SubscriptionClient>()
            {
                CallBase = true
            };

            client.SetupGet(c => c.Subscriptions).Returns(subscriptionMock.Object);
            client.SetupGet(c => c.Tenants).Returns(tenantMock.Object);
            return(client.Object);
        }
Ejemplo n.º 15
0
 public void AddPage(string url, Dictionary<string, string> postData, string result)
 {
     MockPage page = new MockPage();
     page.url = url;
     page.postData = postData;
     page.result = result;
     this.mockPages.Add(page);
 }