Пример #1
0
        public void OnImportsSatisfiedShouldRetrieveSystemOptions()
        {
            var vm = new MainViewModel
                         {
                             ProcessBuilderRecentEntries = CreateProcessBuilderRecentEntries(),
                             EventAggregator = CreateEventAggregator(),
                             SystemOptionsWrapper = CreateISystemOptionsWrapper()
                         };

            Mock.NonPublic.Arrange(vm, "SetupNotifications").DoNothing();

            var getSystemOptionsCalled = false;
            Mock.Arrange(() => vm.SystemOptionsWrapper.GetSystemOptions(Arg.IsAny<EventHandler<DataPortalResult<SystemOptionsRetriever>>>())).DoInstead(
                () =>
                {
                    getSystemOptionsCalled = true;
                });

            var asyncCompleted = false;
            var taskSource = new TaskCompletionSource<MQ1Principal>();
            taskSource.SetResult(Mock.Create<MQ1Principal>(Behavior.Loose));
            /*Mock.Arrange(() => MQ1Principal.BeginLoadAsync(Arg.IsAny<string>())).Returns(
                () =>
                    {
                        asyncCompleted = true;
                        return taskSource.Task;
                    });      */

            // Act
            vm.OnImportsSatisfied();

            // Assert
            //this.EnqueueConditional(() => asyncCompleted);
            this.EnqueueCallback(() => Assert.IsTrue(getSystemOptionsCalled));
            this.EnqueueTestComplete();
        }
Пример #2
0
        public void OnImportSatisfied_WhenCalled_SetsSystemOptions()
        {
            //Arrange
            var vm = new MainViewModel();
            var communicationServiceMock = Mock.Create<ICommunicationService>();
            vm.CommunicationService = communicationServiceMock;
            vm.ProcessBuilderRecentEntries = Mock.Create<IRecentEntryList>();
            vm.EventAggregator = Mock.Create<IEventAggregator>();
            vm.SystemOptionsWrapper = Mock.Create<ISystemOptionsWrapper>();

            var systemOptionsRetrieverMock = Mock.Create<SystemOptionsRetriever>();
            var sysOptionsMock = Mock.Create<SystemOptionsInfo>();
            Mock.Arrange(() => sysOptionsMock.SessionInactivityTimeoutAction).Returns(InactivityTimoutActionEnum.Locked);
            Mock.Arrange(() => sysOptionsMock.InactivityMinutes).Returns(5);
            Mock.Arrange(() => systemOptionsRetrieverMock.SystemOptions).Returns(sysOptionsMock);
            Mock.NonPublic.Arrange(vm, "StartInactivityTimer", ArgExpr.IsAny<SystemOptionsInfo>()).MustBeCalled();



            Mock.Arrange(
                () =>
                    vm.SystemOptionsWrapper.GetSystemOptions(
                        Arg.IsAny<EventHandler<DataPortalResult<SystemOptionsRetriever>>>()))
                .DoInstead<EventHandler<DataPortalResult<SystemOptionsRetriever>>>(
                    callback =>
                        callback(null,
                            new DataPortalResult<SystemOptionsRetriever>(systemOptionsRetrieverMock, null, null)));

            //Act
            vm.OnImportsSatisfied();

            //Assert
            vm.AssertAll();
        }
Пример #3
0
        public void SetupNotifications_WhenCommunicationMessageReceived_CallsShowMessage()
        {
            var vm = new MainViewModel();
            var communicationServiceMock = Mock.Create<ICommunicationService>();
            vm.CommunicationService = communicationServiceMock;
            vm.ProcessBuilderRecentEntries = Mock.Create<IRecentEntryList>();
            vm.EventAggregator = Mock.Create<IEventAggregator>();
            vm.SystemOptionsWrapper = Mock.Create<ISystemOptionsWrapper>();
            vm.MessageReceiver = new LazyMessageReceiver
            {
                InnerValue = new Lazy<IMessageReceiver>(Mock.Create<IMessageReceiver>)
            };

            var adminMessageService = Mock.Create<AdminMessageService>();
            Mock.Arrange(() => adminMessageService.ShowMessage(Arg.AnyString, Arg.IsAny<IMessageReceiver>())).MustBeCalled();

            vm.TheAdminMessageService = new Lazy<AdminMessageService>(() => adminMessageService);

            //Act
            vm.OnImportsSatisfied();
            Mock.Raise(() => communicationServiceMock.MessageReceived += null, new ValueEventArgs<string>("123"));

            //Assert
            adminMessageService.AssertAll();

        }
Пример #4
0
        public void OnImportSatisfied_WhenCalled_SetsUpNotifications()
        {
            //Arrange
            var vm = new MainViewModel();
            var communicationServiceMock = Mock.Create<ICommunicationService>();
            vm.CommunicationService = communicationServiceMock;
            vm.ProcessBuilderRecentEntries = Mock.Create<IRecentEntryList>();
            vm.EventAggregator = Mock.Create<IEventAggregator>();
            vm.SystemOptionsWrapper = Mock.Create<ISystemOptionsWrapper>();
            Mock.ArrangeSet(() => communicationServiceMock.MessageReceived += null).IgnoreArguments().OccursOnce();

            //Act
            vm.OnImportsSatisfied();

            //Assert
            communicationServiceMock.AssertAll();
        }