public void Initialize_with_command_arg_should_return_null() { /* Arrange */ var mocks = new TestAssistant().MockAll(); var mgr = new ApplicationManager(mocks.ActionsManager); A.CallTo(() => mocks.ActionsManager.ExecuteCommandLine(A<string[]>.Ignored)).Returns(true); /* Act */ var a = mgr.Initialize(mocks.Container, new string[] { "MustHaveAtleastOneArg" }); /* Assert */ a.Should().BeNull(); A.CallTo(() => mocks.ActionsManager.BuildActions(A<IEnumerable<IProvideActions>>.Ignored)).MustNotHaveHappened(); A.CallTo(() => mocks.ActionsManager.ExecuteCommandLine(A<string[]>.Ignored)).MustHaveHappened(Repeated.Exactly.Once); }
public void Fail_If_FilePath_DoesNot_Exist() { // Arrange var test = new TestContainer(); const string FilePath = "file-path"; test.FileSystem.Setup(m => m.FileExists(FilePath)) .Returns(false); var importer = test.RegisterAll().Resolve <VirtualMachineImporter>(); // Act var ex = TestAssistant.CatchException(() => importer.Import(FilePath, "some-name")); // Assert Assert.IsNotNull(ex); }
public void Name_Should_Not_Be_Empty() { // Arrange const string Path = "some-path"; var importer = GenerateTestContainer().RegisterAll().Resolve <VirtualMachineImporter>(); // Act var validCase = TestAssistant.CatchException(() => importer.Import(Path, "some-name")); var invalid1 = TestAssistant.CatchException(() => importer.Import(Path, " ")); var invalid2 = TestAssistant.CatchException(() => importer.Import(Path, string.Empty)); var invalid3 = TestAssistant.CatchException(() => importer.Import(Path, null)); // Assert Assert.IsNull(validCase); Assert.IsNotNull(invalid1); Assert.IsNotNull(invalid2); Assert.IsNotNull(invalid3); }
public async Task Throw_ArgumentEx_When_File_DoesNot_Exist() { // Arrange var test = new TestContainer(); const string FilePath = @"some\file\path.vhd"; test.FileSystem.Setup(m => m.FileExists(It.IsAny <string>())).Returns(true); test.FileSystem.Setup(m => m.FileExists(FilePath)).Returns(false); IDiskUuidGetter getter = test.RegisterAll().Resolve <DiskUuidGetter>(); // Act var ex = await TestAssistant.CatchExceptionAsync(getter.GetDiskUuidAsync(FilePath)); // Assert Assert.IsNotNull(ex); Assert.IsTrue(ex is ArgumentException); }
public void Handling_main_request_with_main_already_active_should_work_but_not_create_a_new_instance() { /* Arrange */ var mocks = new TestAssistant().MockAll(); var main = A.Dummy<MainViewModel>(); var vm = new ShellViewModel(main, mocks.Messenger, mocks.ViewModelFactory); var handler = vm as IHandle<ViewRequest>; vm.MonitorEvents(); /* Act */ (vm as IActivate).Activate(); handler.Handle(ViewRequest.MainView); /* Assert */ A.CallTo(() => mocks.ViewModelFactory.Get(typeof(DummyViewModel))).MustNotHaveHappened(); vm.ActiveItem.Should().BeSameAs(main); vm.ShouldNotRaisePropertyChangeFor((svm) => svm.ActiveItem); }
public void Handling_view_requests_should_work() { /* Arrange */ var mocks = new TestAssistant().MockAll(); var main = A.Dummy<MainViewModel>(); A.CallTo(() => mocks.ViewModelFactory.Get(typeof(DummyViewModel))).Returns(new DummyViewModel()); var optionsReq = new ViewRequest(typeof(DummyViewModel)); var vm = new ShellViewModel(main, mocks.Messenger, mocks.ViewModelFactory); var handler = vm as IHandle<ViewRequest>; /* Act */ (vm as IActivate).Activate(); handler.Handle(optionsReq); /* Assert */ A.CallTo(() => mocks.ViewModelFactory.Get(typeof(DummyViewModel))).MustHaveHappened(Repeated.Exactly.Once); vm.ActiveItem.Should().BeOfType<DummyViewModel>(); }
public void Initialize_with_file_arg_should_go_to_request_display_of_config() { /* Arrange */ var mocks = new TestAssistant().MockAll(); var mgr = new ApplicationManager(mocks.ActionsManager); ConfigRequest msg = null; A.CallTo(() => mocks.Messenger.Publish(A<object>.Ignored)).Invokes(c => msg = c.Arguments[0] as ConfigRequest); /* Act */ var a = mgr.Initialize(mocks.Container, new string[] { "SomeFileName" }); a(); /* Assert */ msg.Should().NotBeNull(); msg.RequestedAction.Should().Be(ConfigRequest.Action.Open); msg.Source.Provider.As<FileConfigProvider>().ConfigFileName.Should().Be("SomeFileName"); A.CallTo(() => mocks.ActionsManager.BuildActions(A<IEnumerable<IProvideActions>>.Ignored)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => mocks.ActionsManager.ExecuteCommandLine(A<string[]>.Ignored)).MustHaveHappened(Repeated.Exactly.Once); }
public void Initialize_with_an_existing_plugin_should_find_it_and_load_it() { /* Arrange */ var mocks = new TestAssistant().MockAll(); var mgr = new ApplicationManager(mocks.ActionsManager); PluginConfig.Instance.PluginFolder = "Addins"; /* Act */ var preInit = mocks.Container.TryGet<IProvideConfigSource>(); mgr.Initialize(mocks.Container, new string[0]); var postInit = mocks.Container.TryGet<IProvideConfigSource>(); /* Assert */ AssemblySource.Instance.Should().ContainSingle(asm => asm.GetAssemblyName() == "SampleEditorPlugin"); A.CallTo(mocks.Logger).MustNotHaveHappened(); //Faking the IKernel doesn't work so instead we check the actual container preInit.Should().BeNull(); postInit.Should().NotBeNull(); }
public void Initialize_with_no_args_should_go_to_source_open() { /* Arrange */ var mocks = new TestAssistant().MockAll(); var mgr = new ApplicationManager(mocks.ActionsManager); /* Act */ var a = mgr.Initialize(mocks.Container, new string[0]); a(); /* Assert */ A.CallTo(() => mocks.Messenger.Publish(A<ConfigSourceRequest>.That.Matches(r => r.RequestPurpose == ConfigSourcePurpose.Open))).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => mocks.ActionsManager.BuildActions(A<IEnumerable<IProvideActions>>.Ignored)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => mocks.ActionsManager.ExecuteCommandLine(A<string[]>.Ignored)).MustNotHaveHappened(); }
public void Handling_view_request_to_other_than_main_if_main_is_not_active_should_ignore_and_log() { /* Arrange */ var mocks = new TestAssistant().MockAll(); var main = A.Dummy<MainViewModel>(); var active = new object(); var optionsReq = new ViewRequest(typeof(DummyViewModel)); var vm = new ShellViewModel(main, mocks.Messenger, mocks.ViewModelFactory); var handler = vm as IHandle<ViewRequest>; /* Act */ vm.ActiveItem = active; handler.Handle(optionsReq); /* Assert */ A.CallTo(() => mocks.Logger.Warn(A<string>.Ignored, A<object[]>.Ignored)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => mocks.ViewModelFactory.Get(typeof(DummyViewModel))).MustNotHaveHappened(); vm.ActiveItem.Should().BeSameAs(active); }