示例#1
0
        public void OpenDocumentViaCommandLineTest()
        {
            FileController fileController = Container.GetExportedValue <FileController>();
            IFileService   fileService    = Container.GetExportedValue <IFileService>();

            MockDocumentType documentType = new MockDocumentType("Mock Document", ".mock");

            fileController.Register(documentType);

            Assert.IsFalse(fileService.Documents.Any());
            Assert.IsNull(fileService.ActiveDocument);

            // Open is called with a fileName which might be a command line parameter.
            fileService.OpenCommand.Execute("Document1.mock");
            IDocument document = fileService.Documents.Last();

            Assert.AreEqual("Document1.mock", document.FileName);

            Assert.IsTrue(fileService.Documents.SequenceEqual(new[] { document }));
            Assert.AreEqual(document, fileService.ActiveDocument);

            // Call open with a fileName that has an invalid extension
            MockMessageService messageService = Container.GetExportedValue <MockMessageService>();

            messageService.Clear();
            fileService.OpenCommand.Execute("Document.wrongextension");
            Assert.AreEqual(MessageType.Error, messageService.MessageType);
            Assert.IsFalse(string.IsNullOrEmpty(messageService.Message));

            // Call open with a fileName that doesn't exist
            messageService.Clear();
            fileService.OpenCommand.Execute("2i0501fh-89f1-4197-a318-d5241135f4f6.rtf");
            Assert.AreEqual(MessageType.Error, messageService.MessageType);
            Assert.IsFalse(string.IsNullOrEmpty(messageService.Message));
        }
        public void ShowQuestionTest()
        {
            var messageService = new MockMessageService();

            var view    = new object();
            var message = "Hello World";
            var format  = "Result: {0}";

            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowQuestion(null !, message));
            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowQuestion(null !, null, message));
            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowYesNoQuestion(null !, message));
            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowYesNoQuestion(null !, null, message));

            bool showQuestionCalled = false;

            messageService.ShowQuestionStub = (_, m) =>
            {
                showQuestionCalled = true;
                Assert.AreEqual(message, m);
                return(true);
            };
            Assert.IsTrue(messageService.ShowQuestion(message) == true);
            Assert.IsTrue(showQuestionCalled);

            showQuestionCalled = false;
            messageService.ShowQuestionStub = (o, m) =>
            {
                showQuestionCalled = true;
                Assert.AreSame(view, o);
                Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, format, 42), m);
                return(true);
            };
            Assert.IsTrue(messageService.ShowQuestion(view, format, 42) == true);
            Assert.IsTrue(showQuestionCalled);

            showQuestionCalled = false;
            messageService.Clear();
            messageService.ShowYesNoQuestionStub = (_, m) =>
            {
                showQuestionCalled = true;
                Assert.AreEqual(message, m);
                return(true);
            };
            Assert.IsTrue(messageService.ShowYesNoQuestion(message));
            Assert.IsTrue(showQuestionCalled);

            showQuestionCalled = false;
            messageService.Clear();
            messageService.ShowYesNoQuestionStub = (o, m) =>
            {
                showQuestionCalled = true;
                Assert.AreSame(view, o);
                Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, format, 42), m);
                return(true);
            };
            Assert.IsTrue(messageService.ShowYesNoQuestion(view, format, 42));
            Assert.IsTrue(showQuestionCalled);
        }
        public void CreateNewEmailTest()
        {
            Person harry = new Person()
            {
                Firstname = "Harry", Email = "*****@*****.**"
            };
            Person ron = new Person()
            {
                Firstname = "Ron", Email = "Wrong Address"
            };

            IEntityService entityService = Container.GetExportedValue <IEntityService>();

            entityService.Persons.Add(harry);
            entityService.Persons.Add(ron);

            PersonController personController = Container.GetExportedValue <PersonController>();

            personController.Initialize();

            MockPersonListView  personListView      = Container.GetExportedValue <MockPersonListView>();
            PersonListViewModel personListViewModel = ViewHelper.GetViewModel <PersonListViewModel>(personListView);
            MockPersonView      personView          = Container.GetExportedValue <MockPersonView>();
            PersonViewModel     personViewModel     = ViewHelper.GetViewModel <PersonViewModel>(personView);

            ICommand command = personListViewModel.CreateNewEmailCommand;

            Assert.AreEqual(command, personViewModel.CreateNewEmailCommand);

            MockEmailService emailService = Container.GetExportedValue <MockEmailService>();

            command.Execute(harry);
            Assert.AreEqual(harry.Email, emailService.ToEmailAddress);

            // An error message should occur when the email address is invalid.

            MockMessageService messageService = Container.GetExportedValue <MockMessageService>();

            messageService.Clear();
            emailService.ToEmailAddress = null;
            command.Execute(ron);
            Assert.AreEqual(MessageType.Error, messageService.MessageType);
            Assert.AreEqual(Resources.CorrectEmailAddress, messageService.Message);
            Assert.IsNull(emailService.ToEmailAddress);

            // An error message should occur when no email address was entered.

            messageService.Clear();
            emailService.ToEmailAddress = null;
            ron.Email = null;
            command.Execute(ron);
            Assert.AreEqual(MessageType.Error, messageService.MessageType);
            Assert.AreEqual(Resources.CorrectEmailAddress, messageService.Message);
            Assert.IsNull(emailService.ToEmailAddress);
        }
        public void ShowQuestionTest()
        {
            MockMessageService messageService = new MockMessageService();

            string message = "Hello World";
            AssertHelper.ExpectedException<ArgumentNullException>(() => MessageServiceExtensions.ShowQuestion(null, message));
            AssertHelper.ExpectedException<ArgumentNullException>(() => MessageServiceExtensions.ShowYesNoQuestion(null, message));

            bool showQuestionCalled = false;
            messageService.ShowQuestionAction = m =>
            {
                showQuestionCalled = true;
                Assert.AreEqual(message, m);
                return true;
            };
            Assert.IsTrue(messageService.ShowQuestion(message) == true);
            Assert.IsTrue(showQuestionCalled);

            showQuestionCalled = false;
            messageService.Clear();
            messageService.ShowYesNoQuestionAction = m =>
            {
                showQuestionCalled = true;
                Assert.AreEqual(message, m);
                return true;
            };
            Assert.IsTrue(messageService.ShowYesNoQuestion(message) == true);
            Assert.IsTrue(showQuestionCalled);
        }
示例#5
0
        public void ShowQuestionTest()
        {
            var messageService = new MockMessageService();

            var message = "Hello World";

            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowQuestion(null !, message));
            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowYesNoQuestion(null !, message));

            bool showQuestionCalled = false;

            messageService.ShowQuestionAction = m =>
            {
                showQuestionCalled = true;
                Assert.AreEqual(message, m);
                return(true);
            };
            Assert.IsTrue(messageService.ShowQuestion(message) == true);
            Assert.IsTrue(showQuestionCalled);

            showQuestionCalled = false;
            messageService.Clear();
            messageService.ShowYesNoQuestionAction = m =>
            {
                showQuestionCalled = true;
                Assert.AreEqual(message, m);
                return(true);
            };
            Assert.IsTrue(messageService.ShowYesNoQuestion(message));
            Assert.IsTrue(showQuestionCalled);
        }
        public void OpenFileViaCommandLine()
        {
            MockEnvironmentService environmentService = Container.GetExportedValue <MockEnvironmentService>();

            environmentService.DocumentFileName = "Document.mock";

            var controller = Container.GetExportedValue <ModuleController>();

            controller.Initialize();


            // Open the 'Document.mock' file
            controller.Run();

            // Open a file with an unknown file extension and check if an error message is shown.
            environmentService.DocumentFileName = "Unknown.fileExtension";
            MockMessageService messageService = Container.GetExportedValue <MockMessageService>();

            messageService.Clear();

            controller.Run();

            Assert.AreEqual(MessageType.Error, messageService.MessageType);
            Assert.IsFalse(string.IsNullOrEmpty(messageService.Message));
        }
示例#7
0
        public void ShellViewModelBasicTest()
        {
            MockShellView      shellView      = Container.GetExportedValue <MockShellView>();
            MockMessageService messageService = Container.GetExportedValue <MockMessageService>();
            IShellService      shellService   = Container.GetExportedValue <IShellService>();
            ShellViewModel     shellViewModel = Container.GetExportedValue <ShellViewModel>();

            // The title isn't available in the unit test environment.
            Assert.AreEqual("", shellViewModel.Title);

            Assert.AreEqual(shellService, shellViewModel.ShellService);

            // Show the ShellView
            shellViewModel.Show();
            Assert.IsTrue(shellView.IsVisible);

            // Show the about message box
            messageService.Clear();
            shellViewModel.AboutCommand.Execute(null);
            Assert.IsFalse(string.IsNullOrEmpty(messageService.Message));
            Assert.AreEqual(MessageType.Message, messageService.MessageType);

            // Close the ShellView
            bool closingEventRaised = false;

            shellViewModel.Closing += (sender, e) =>
            {
                closingEventRaised = true;
            };
            shellViewModel.Close();
            Assert.IsFalse(shellView.IsVisible);
            Assert.IsTrue(closingEventRaised);
        }
        public void ShowMessageTest()
        {
            var messageService = new MockMessageService();

            var view    = new object();
            var message = "Hello World";
            var format  = "Result: {0}";

            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowMessage(null !, message));
            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowMessage(null !, null, message));
            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowWarning(null !, message));
            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowWarning(null !, null, message));
            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowError(null !, message));
            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowError(null !, null, message));

            messageService.ShowMessage(message);
            Assert.AreEqual(MessageType.Message, messageService.MessageType);
            Assert.AreEqual(message, messageService.Message);

            messageService.Clear();
            messageService.ShowMessage(view, format, 42);
            Assert.AreSame(view, messageService.Owner);
            Assert.AreEqual(MessageType.Message, messageService.MessageType);
            Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, format, 42), messageService.Message);

            messageService.Clear();
            messageService.ShowWarning(message);
            Assert.AreEqual(MessageType.Warning, messageService.MessageType);
            Assert.AreEqual(message, messageService.Message);

            messageService.Clear();
            messageService.ShowWarning(view, format, 42);
            Assert.AreSame(view, messageService.Owner);
            Assert.AreEqual(MessageType.Warning, messageService.MessageType);
            Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, format, 42), messageService.Message);

            messageService.Clear();
            messageService.ShowError(message);
            Assert.AreEqual(MessageType.Error, messageService.MessageType);
            Assert.AreEqual(message, messageService.Message);

            messageService.Clear();
            messageService.ShowError(view, format, 42);
            Assert.AreSame(view, messageService.Owner);
            Assert.AreEqual(MessageType.Error, messageService.MessageType);
            Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, format, 42), messageService.Message);
        }
        public void ShowMessageTest()
        {
            MockMessageService messageService = new MockMessageService();

            string message = "Hello World";
            AssertHelper.ExpectedException<ArgumentNullException>(() => MessageServiceExtensions.ShowMessage(null, message));
            AssertHelper.ExpectedException<ArgumentNullException>(() => MessageServiceExtensions.ShowWarning(null, message));
            AssertHelper.ExpectedException<ArgumentNullException>(() => MessageServiceExtensions.ShowError(null, message));

            messageService.ShowMessage(message);
            Assert.AreEqual(MessageType.Message, messageService.MessageType);
            Assert.AreEqual(message, messageService.Message);

            messageService.Clear();
            messageService.ShowWarning(message);
            Assert.AreEqual(MessageType.Warning, messageService.MessageType);
            Assert.AreEqual(message, messageService.Message);

            messageService.Clear();
            messageService.ShowError(message);
            Assert.AreEqual(MessageType.Error, messageService.MessageType);
            Assert.AreEqual(message, messageService.Message);
        }
示例#10
0
        public void ShowMessageTest()
        {
            var messageService = new MockMessageService();

            var message = "Hello World";

            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowMessage(null !, message));
            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowWarning(null !, message));
            AssertHelper.ExpectedException <ArgumentNullException>(() => MessageServiceExtensions.ShowError(null !, message));

            messageService.ShowMessage(message);
            Assert.AreEqual(MessageType.Message, messageService.MessageType);
            Assert.AreEqual(message, messageService.Message);

            messageService.Clear();
            messageService.ShowWarning(message);
            Assert.AreEqual(MessageType.Warning, messageService.MessageType);
            Assert.AreEqual(message, messageService.Message);

            messageService.Clear();
            messageService.ShowError(message);
            Assert.AreEqual(MessageType.Error, messageService.MessageType);
            Assert.AreEqual(message, messageService.Message);
        }
示例#11
0
        public void SaveDocumentTest()
        {
            MockFileDialogService fileDialogService = Container.GetExportedValue <MockFileDialogService>();
            FileController        fileController    = Container.GetExportedValue <FileController>();
            IFileService          fileService       = Container.GetExportedValue <IFileService>();
            MockDocumentType      documentType      = new MockDocumentType("Mock Document", ".mock");

            fileController.Register(documentType);
            fileController.New(documentType);
            IDocument document = fileService.Documents.Single();

            document.FileName = "Document.mock";

            fileDialogService.Result = new FileDialogResult("Document1.mock", new FileType("Mock Document", ".mock"));
            fileService.SaveAsCommand.Execute(null);

            Assert.AreEqual(FileDialogType.SaveFileDialog, fileDialogService.FileDialogType);
            Assert.AreEqual("Mock Document", fileDialogService.FileTypes.Single().Description);
            Assert.AreEqual(".mock", fileDialogService.FileTypes.Single().FileExtension);
            Assert.AreEqual("Mock Document", fileDialogService.DefaultFileType.Description);
            Assert.AreEqual(".mock", fileDialogService.DefaultFileType.FileExtension);
            Assert.AreEqual("Document", fileDialogService.DefaultFileName);

            Assert.AreEqual(DocumentOperation.Save, documentType.DocumentOperation);
            Assert.AreEqual(document, documentType.Document);

            Assert.AreEqual("Document1.mock", documentType.FileName);

            // Change the CanSave to return false so that no documentType is able to save the document anymore

            documentType.CanSaveResult = false;
            Assert.IsFalse(fileService.SaveCommand.CanExecute(null));

            // Simulate an exception during the Save operation.

            MockMessageService messageService = Container.GetExportedValue <MockMessageService>();

            messageService.Clear();
            documentType.ThrowException = true;
            documentType.CanSaveResult  = true;
            fileService.SaveAsCommand.Execute(null);
            Assert.AreEqual(MessageType.Error, messageService.MessageType);
            Assert.IsFalse(string.IsNullOrEmpty(messageService.Message));
        }