2 // Unit tests for System.Windows.Application
5 // Moonlight List (moonlight-list@lists.ximian.com)
7 // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System
.Windows
.Browser
;
33 using System
.Windows
.Controls
;
34 using System
.Windows
.Markup
;
35 using System
.Windows
.Resources
;
36 using Mono
.Moonlight
.UnitTesting
;
37 using Microsoft
.VisualStudio
.TestTools
.UnitTesting
;
39 namespace MoonTest
.System
.Windows
{
42 public class ApplicationTest
{
44 static private Uri uri
= new Uri ("http://www.mono-project.com");
46 void Check (Application app
)
48 Assert
.IsNotNull (app
.Host
, "Host");
50 // not yet implemented in moonlight
51 // Assert.IsNotNull (app.Resources, "Resources");
53 Assert
.IsNotNull (app
.RootVisual
, "RootVisual");
59 Application app
= new Application ();
60 // AFAIK this is *nearly* identical to Application.Current
62 // funny thing is that creating a SilverlightHost defaults to true :|
63 Assert
.IsTrue (app
.Host
.IsLoaded
, "Host.IsLoaded");
67 public void Current ()
69 Application app
= Application
.Current
;
71 Assert
.IsTrue (app
.Host
.IsLoaded
, "Host.IsLoaded");
75 public void InvalidGetResourceStream ()
77 Assert
.Throws
<ArgumentNullException
> (() => Application
.GetResourceStream (null), "GetResourceStream(null)");
78 Assert
.Throws
<ArgumentNullException
> (() => Application
.GetResourceStream (null, uri
), "GetResourceStream(null,uri)");
80 Assert
.IsNull (Application
.GetResourceStream (new Uri ("/moon_unit;component/App-does-not-exists.xaml", UriKind
.Relative
)), "GetResourceStream(does-not-exists-uri)");
82 Assert
.Throws
<ArgumentException
> (() => Application
.GetResourceStream (new Uri ("http://mono-project.com/", UriKind
.Absolute
)), "GetResourceStream absolute uri");
84 StreamResourceInfo sri
= new StreamResourceInfo (new MemoryStream (), String
.Empty
);
86 Assert
.Throws
<ArgumentNullException
> (() => Application
.GetResourceStream (sri
, null), "GetResourceStream(sri,null)");
88 Assert
.Throws
<IndexOutOfRangeException
> (() => Application
.GetResourceStream (new Uri ("", UriKind
.Relative
)));
92 public void InvalidLoadComponent ()
94 Assert
.Throws
<ArgumentNullException
> (() => Application
.LoadComponent (null, uri
), "LoadComponent(null,uri)");
98 public void LoadComponent_Application ()
100 Uri docuri
= HtmlPage
.Document
.DocumentUri
;
102 if (docuri
.Scheme
!= "http" && docuri
.Scheme
!= "https")
105 // Note: Exception message can be misleading
106 Assert
.Throws
<ArgumentNullException
> (() => Application
.LoadComponent (Application
.Current
, null), "LoadComponent(app,null)");
107 Assert
.Throws
<ArgumentException
> (() => Application
.LoadComponent (Application
.Current
, uri
), "LoadComponent(app,uri)");
108 Assert
.Throws
<ArgumentException
> (() => Application
.LoadComponent (Application
.Current
, Application
.Current
.Host
.Source
), "LoadComponent(app,xap)");
110 // try to load an unexisting uri
111 Application
.LoadComponent (Application
.Current
, new Uri ("/moon_unit;component/App-does-not-exists.xaml", UriKind
.Relative
));
115 public void ResetRootVisual ()
117 UIElement root
= Application
.Current
.RootVisual
;
118 Canvas new_root
= new Canvas ();
119 Application
.Current
.RootVisual
= new_root
;
120 // we can't change the root
121 Assert
.IsFalse (Object
.ReferenceEquals (new_root
, Application
.Current
.RootVisual
), "new root");
122 Assert
.IsTrue (Object
.ReferenceEquals (root
, Application
.Current
.RootVisual
), "old root");
123 // and we can't clear it
124 Assert
.Throws (delegate { Application.Current.RootVisual = null; }
, typeof (InvalidOperationException
), "null");