public void CheckOnlineService()
        {
            var    settings   = new MockSettings();
            var    service    = new OnlineService();
            object result     = null;
            var    connection = new OnlineServiceConnection(settings,
                                                            () => { throw new ConnectionTimedOut(); });

            connection.Connected +=
                () => connection.Send(new LoginRequest(LoadApiKeyFromRegistry(), "LogoApp"));
            connection.DataReceived += message => result = message;
            service.Connect("CurrentUser", connection);
            Thread.Sleep(500);
            Console.WriteLine("User Name: " + service.UserName);
            CheckService(service, "LogoApp", result);
            Assert.IsFalse(service.IsDeveloper);
            bool hasProjectChanged = false;

            service.ProjectChanged += () => hasProjectChanged = true;
            service.ChangeProject("Asteroids");
            Thread.Sleep(500);
            Assert.IsTrue(hasProjectChanged);
            CheckService(service, "Asteroids", result);
            Assert.IsFalse(service.IsDeveloper);
        }
Example #2
0
 private void CreateOnlineService()
 {
     onlineService = new OnlineServiceConnection(settings, OnTimeout);
     onlineService.ServerErrorHappened = OnError;
     onlineService.ContentReady        = OnReady;
     onlineService.ContentReceived     = OnContentReceived;
     RegisterInstance(onlineService);
 }
        public void ConnectToInvalidServerShouldTimeOut()
        {
            bool timedOut   = false;
            var  connection = new OnlineServiceConnection();

            connection.Connect("localhost", 12345, () => timedOut = true);
            Thread.Sleep((int)((connection.Timeout + 0.5f) * 1000));
            Assert.IsTrue(timedOut);
            Assert.IsFalse(connection.IsLoggedIn);
        }
        public void SolutionFilePathCanBeLoadedFromSettings()
        {
            var settings   = new FileSettings();
            var service    = new OnlineService();
            var connection = new OnlineServiceConnection(settings,
                                                         () => { throw new ConnectionTimedOut(); });

            service.Connect("CurrentUser", connection);
            service.ChangeProject("DeltaEngine.Tutorials");
            Thread.Sleep(1000);
            Assert.AreEqual(TutorialsSolutionFilePath, service.CurrentContentProjectSolutionFilePath);
        }
        public void ClientGetsConnectedAndSendsLoginRequest()
        {
            string errorReceived = "";
            bool   readyReceived = false;
            var    connection    = new OnlineServiceConnection(new MockSettings(), () => { });

            connection.ServerErrorHappened += text => errorReceived = text;
            connection.ContentReady        += () => readyReceived = true;
            connection.ConnectToService();
            Thread.Sleep(1000);
            Assert.AreEqual("", errorReceived);
            Assert.IsTrue(connection.IsLoggedIn);
            Assert.IsTrue(readyReceived);
        }
 private void ConnectToOnlineServiceAndTryToLogin()
 {
     if (tryingToConnect)
     {
         return;
     }
     tryingToConnect          = true;
     connection               = new OnlineServiceConnection();
     connection.Connected    += ValidateLogin;
     connection.Disconnected += ConnectionLost;
     connection.DataReceived += OnDataReceived;
     connection.Connect(Settings.Current.OnlineServiceIp, Settings.Current.OnlineServicePort,
                        OnTimeout);
 }
        public void ReceiveResultFromServer()
        {
            var    connection          = new OnlineServiceConnection(new MockSettings(), () => { });
            object lastMessageReceived = null;
            string errorReceived       = "";

            connection.ServerErrorHappened += text => errorReceived = text;
            connection.DataReceived        += message => lastMessageReceived = message;
            Assert.IsNull(lastMessageReceived);
            connection.ConnectToService();
            Thread.Sleep(1000);
            Assert.AreEqual("", errorReceived);
            Assert.IsNotNull(lastMessageReceived);
        }
Example #8
0
        public void GetContentFromOnlineService()
        {
            DeleteContentDirectoriesIfAvailable();
            var messagesReceived = new List <object>();
            var connection       = new OnlineServiceConnection(new MockSettings(),
                                                               () => { throw new ConnectionTimedOut(); });
            var contentLoader = new EditorContentLoader(connection);

            connection.Connected    += () => GetProjectsAndLogin(connection);
            connection.DataReceived += message => { messagesReceived.Add(message); };
            Thread.Sleep(3000);
            CheckConnection(connection);
            CheckContentLoader(contentLoader);
            CheckAndWriteMessages(messagesReceived);
        }
        public void Connect(string userName, OnlineServiceConnection connection)
        {
            UserName = userName;
            onlineServiceConnection  = connection;
            connection.DataReceived += OnDataReceived;
            send = connection.Send;
            var oldResolver = ContentLoader.resolver;

            ContentLoader.DisposeIfInitialized();
            ContentLoader.resolver = oldResolver;
            ContentLoader.Use <EditorContentLoader>();
            editorContent = new EditorContentLoader(onlineServiceConnection);
            editorContent.ContentUpdated += OnContentUpdated;
            editorContent.ContentDeleted += OnContentDeleted;
            editorContent.ContentReady   += OnContentReady;
        }
        public static void LogToRealLogServer()
        {
            var ready      = false;
            var connection = new OnlineServiceConnection(new MockSettings(), () => {});

            connection.ServerErrorHappened += error => { throw new ServerErrorReceived(error); };
            connection.ContentReady        += () => ready = true;
            using (var logClient = new NetworkLogger(connection))
            {
                for (int timeoutMs = 1000; timeoutMs > 0 && !ready; timeoutMs -= 10)
                {
                    Thread.Sleep(10);
                }
                logClient.Write(Logger.MessageType.Info, "Hello TestWorld from " + Environment.MachineName);
            }
        }
        public void AbsoluteSolutionFilePathDependsOnTheSelectedContentProject()
        {
            var settings   = new MockSettings();
            var service    = new OnlineService();
            var connection = new OnlineServiceConnection(settings,
                                                         () => { throw new ConnectionTimedOut(); });

            service.Connect("CurrentUser", connection);
            Assert.AreEqual("", service.CurrentContentProjectSolutionFilePath);
            service.ChangeProject("LogoApp");
            Thread.Sleep(1000);
            AssertSolutionFilePath(GetSamplesSlnPath(), service);
            service.ChangeProject("DeltaEngine.Tutorials");
            Thread.Sleep(1000);
            AssertSolutionFilePath(GetTutorialsSlnPath(), service);
        }
        public void SolutionFilePathIsStoredInSettingsFileWithProjectName()
        {
            var settings   = new FileSettings();
            var service    = new OnlineService();
            var connection = new OnlineServiceConnection(settings,
                                                         () => { throw new ConnectionTimedOut(); });

            service.Connect("CurrentUser", connection);
            service.ChangeProject("DeltaEngine.Tutorials");
            Thread.Sleep(1000);
            service.CurrentContentProjectSolutionFilePath = TutorialsSolutionFilePath;
            var projects = Settings.Current.GetValue("ContentProjects", new Dictionary <string, string>());

            Assert.GreaterOrEqual(projects.Count, 1);
            settings.Save();
        }
Example #13
0
        public void StartLogServer()
        {
            server = new LocalhostLogServer(new TcpServer());
            server.Start();
            new MockSettings();
            var ready      = false;
            var connection = new OnlineServiceConnection();

            connection.DataReceived += o => ready = true;
            connection.Connect("localhost", LocalhostLogServer.Port);
            connection.Send(new LoginRequest("", "DeltaEngine.Logging.Tests"));
            logger = new NetworkLogger(connection);
            for (int timeoutMs = 1000; timeoutMs > 0 && !ready; timeoutMs -= 10)
            {
                Thread.Sleep(10);
            }
            Assert.IsTrue(ready);
        }
        public void ConnectToOnlineContentServiceWithoutExistingContent()
        {
            if (Directory.Exists("Content"))
            {
                Directory.Delete("Content", true);
            }
            bool ready      = false;
            var  connection = new OnlineServiceConnection(new MockSettings(),
                                                          () => { throw new ConnectionTimedOut(); });

            connection.ServerErrorHappened += error => { throw new ServerErrorReceived(error); };
            connection.ContentReady        += () => ready = true;
            ContentLoaderResolver.CreationParameterForContentLoader = connection;
            ContentLoader.Use <DeveloperOnlineContentLoader>();
            Assert.IsTrue(ContentLoader.Exists("DeltaEngineLogo"));
            Assert.IsTrue(Directory.Exists("Content"));
            Assert.IsTrue(ready);
            ContentLoader.DisposeIfInitialized();
        }
Example #15
0
 //ncrunch: no coverage start
 protected internal DeveloperOnlineContentLoader(OnlineServiceConnection connection)
 {
     this.connection = connection;
     if (StackTraceExtensions.StartedFromNCrunchOrNunitConsole &&
         File.Exists(ContentMetaDataFilePath) && IsContentMetaDataYoungerThanOneMinute())
     {
         return;
     }
     StartedToRequestOnlineContent   = true;
     connection.loadContentMetaData += OnLoadContentMetaData;
     connection.DataReceived        += OnDataReceived;
     if (!connection.IsConnected)
     {
         connection.ConnectToService();
     }
     if (connection.IsLoggedIn)
     {
         SendCheckProjectContent();
     }
 }
 public EditorContentLoader(OnlineServiceConnection connection)
     : base(connection)
 {
 }
Example #17
0
 public NetworkLogger(OnlineServiceConnection connection)
     : base(true)
 {
     this.connection = connection;
 }
Example #18
0
 private static void CheckConnection(OnlineServiceConnection connection)
 {
     Assert.AreEqual(true, connection.IsConnected);
     Assert.AreEqual(true, connection.IsLoggedIn);
 }
 private void Disconnect()
 {
     tryingToConnect = false;
     connection.Dispose();
     connection = new OnlineServiceConnection();
 }