public void IsProcessingEnabled_WhenThereIsAnInboxAction_IsTrue()
        {
            var test = new WorkspacePresenter(AnInboxActionsFilter.Providing(AnAction.In(State.Inbox)).Build(), null,
                                              null);

            Assert.True(test.IsProcessingEnabled);
        }
Esempio n. 2
0
        private async Task SendMessageToConnection(AnAction action, string connectionId)
        {
            var json = LambdaSerializer.Serialize <object>(action);

            if (DebugLoggingEnabled)
            {
                LogDebug($"Post to connection: {connectionId}\n{{0}}", json);
            }
            else
            {
                LogInfo($"Post to connection: {connectionId}");
            }

            // attempt to send serialized message to connection
            var messageBytes = Encoding.UTF8.GetBytes(json);

            try {
                await _amaClient.PostToConnectionAsync(new PostToConnectionRequest {
                    ConnectionId = connectionId,
                    Data         = new MemoryStream(messageBytes)
                });
            } catch (AmazonServiceException e) when(e.StatusCode == System.Net.HttpStatusCode.Gone)
            {
                // HTTP Gone status code indicates the connection has been closed; nothing to do
            } catch (Exception e) {
                LogErrorAsWarning(e, "PostToConnectionAsync() failed on connection {0}", connectionId);
            }
        }
 public void Setup()
 {
     _result = new AnAction();
     _result.FillParameters(new Dictionary <string, object> {
         { "param1", _obj }
     });
 }
        public void ProcessButtonText_WhenThereIsAnInboxAction_ContainsNumber()
        {
            var test = new WorkspacePresenter(AnInboxActionsFilter.Providing(AnAction.In(State.Inbox)).Build(), null,
                                              null);

            Assert.Equal("Process (1)", test.ProcessButtonText);
        }
        public void DisplayName__ReturnsActionTitle()
        {
            const string titleOfTheAction = "Title of the action";
            var          test             = new ProcessActionPresenter(AnAction.Called(titleOfTheAction).Build(),
                                                                       x => new[] { _fakeProcessor.Object });

            Assert.Equal(titleOfTheAction, test.DisplayName);
        }
        public void Initialize__PopulatesPresenters()
        {
            var test = new ProcessActionPresenter(AnAction.Build(), x => new[] { _fakeProcessor.Object });

            test.Initialize();

            Assert.NotEmpty(test.Screens);
        }
        public void CanAdd_WhenTitleIsNotEmpty_IsTrue()
        {
            _fakeAction = AnAction.Called("This action has a title").Mock();

            InputPresenter test = BuildDefaultInputViewPresenter();

            Assert.True(test.CanAdd());
        }
        public void CanAdd_WhenTitleIsEmpty_IsFalse()
        {
            _fakeAction = AnAction.Called(string.Empty).Mock();

            InputPresenter test = BuildDefaultInputViewPresenter();

            Assert.False(test.CanAdd());
        }
        public void CurrentPresenter_WhenInboxHasACurrentItem_IsAPresenter()
        {
            _fakeInbox.Setup(x => x.SelectedItem).Returns(AnAction.Build());
            ProcessPresenter test = BuildDefaultProcessPresenter();

            test.Initialize();

            Assert.NotNull(test.ActiveScreen);
        }
        public void BlockingActions__ReturnsBlockingActions()
        {
            var stubBlockingActions = new Mock <IBlockingActionsPresenter>();

            var test = new ActionTreeNodePresenter(AnAction.BlockedBy(AnAction).Build(),
                                                   stubBlockingActions.Object);

            Assert.Same(stubBlockingActions.Object, test.BlockingActions);
        }
Esempio n. 11
0
        public void AddBlockingAction_GivenAction_AddsActionToBlockingActions()
        {
            var test = new Action();

            IAction blockingAction = AnAction.Build();

            test.AddBlockingAction(blockingAction);

            Assert.Contains(blockingAction, test.BlockingActions);
        }
Esempio n. 12
0
        public void Actions_WhenWorkspaceContainsAnActionThatIsBlockedButNotBlocking_ContainsAction()
        {
            IAction unblockedAction = AnAction.Build();
            IAction blockedAction   = AnAction.BlockedBy(unblockedAction).Build();
            var     test            = new ProjectsFilter(AWorkspace.With(blockedAction).
                                                         With(unblockedAction).Build());

            Assert.Contains(blockedAction, test.Actions);
            Assert.Equal(1, test.Actions.Count);
        }
Esempio n. 13
0
        public void Execute__MarksActionAsCompleted()
        {
            DateTime       timeAtStart = DateTime.UtcNow;
            Mock <IAction> mockAction  = AnAction.Mock();

            var test = new DoNowCommand();

            test.Execute(mockAction.Object);

            mockAction.VerifySet(x => x.CompletedDate = It.IsInRange(timeAtStart, DateTime.UtcNow, Range.Inclusive));
        }
Esempio n. 14
0
        public void Execute_GivenProject_AddsActionToProjectBlockingActions()
        {
            Mock <IAction> mockProject = AnAction.Mock();

            _test.Context = AContext.Build();
            _test.Project = mockProject.Object;

            _test.Execute(_fakeAction.Object);

            mockProject.Verify(x => x.AddBlockingAction(_fakeAction.Object));
        }
        public void DisplayName_WhenActionTitleChanges_RaisesPropertyChanged()
        {
            const string   titleOfTheAction = "Title of the action";
            Mock <IAction> stubAction       = AnAction.Called(titleOfTheAction).Mock();

            var test = new ProcessActionPresenter(stubAction.Object, x => new[] { _fakeProcessor.Object });

            test.AssertThatChangeNotificationIsRaisedBy(x => x.DisplayName).
            When(() => stubAction.Raise(x => x.PropertyChanged += null,
                                        new PropertyChangedEventArgs("Title")));
        }
        public void DisplayName_WhenSet_SetsActionTitle()
        {
            Mock <IAction> mockAction = AnAction.Mock();
            var            test       = new ProcessActionPresenter(mockAction.Object, x => new[] { _fakeProcessor.Object });

            const string newTitle = "New title";

            test.DisplayName = newTitle;

            mockAction.VerifySet(x => x.Title = newTitle);
        }
		public bool AsyncWaitHandle ()
		{
			var d = new AnAction (DoAction);  

			IAsyncResult ar = d.BeginInvoke (true, 1, null, null);   

			do {
			} while (!ar.AsyncWaitHandle.WaitOne (10, true));

			return d.EndInvoke (ar);
		}
		public bool IsCompleted ()
		{
			var d = new AnAction (DoAction);   

			IAsyncResult ar = d.BeginInvoke (true, 1, null, null);   

			do {  
				Thread.Sleep (10);
			} while(!ar.IsCompleted);   

			return d.EndInvoke (ar);
		}
        public bool AsyncWaitHandle()
        {
            var d = new AnAction(DoAction);

            IAsyncResult ar = d.BeginInvoke(true, 1, null, null);

            do
            {
            } while (!ar.AsyncWaitHandle.WaitOne(10, true));

            return(d.EndInvoke(ar));
        }
        public bool IsCompleted()
        {
            var d = new AnAction(DoAction);

            IAsyncResult ar = d.BeginInvoke(true, 1, null, null);

            do
            {
                Thread.Sleep(10);
            } while(!ar.IsCompleted);

            return(d.EndInvoke(ar));
        }
        public void TopLevelProjects_WhenWorkspaceContainsAnActionThatIsBlockedButNotBlocking_ReturnsAction()
        {
            var stubProjectPresenter = new Mock <IActionTreeNodePresenter>();

            var test =
                new OptionalProjectSelector(AProjectsFilter.Providing(AnAction.Build()).Build(),
                                            action => stubProjectPresenter.Object,
                                            new AllowNullSelectionPolicy());

            test.Initialize();

            Assert.Contains(stubProjectPresenter.Object, test.Screens);
        }
        public void GettingApplyCommandProject_WhenProjectHasBeenSelected_ReturnsTheProject()
        {
            DoLaterPresenter test = BuildDefaultDoLaterPresenter();

            test.Initialize();

            IAction project = AnAction.Build();

            ProjectIsSelected(project);

            GC.KeepAlive(test);
            Assert.Same(project, _applyCommand.Project);
        }
		public bool AsyncCallbackWithState ()
		{
			var d = new AnAction (DoAction);  

			var ar = d.BeginInvoke (true, 10, 
				         new AsyncCallback (MyCallback), 
				         new object ());

			do {  
				Thread.Sleep (10);
			} while(!ar.IsCompleted && !CallBackCalled);  

			return true;
		}
        public void Presenters_WhenThereIsAnInboxAction_ContainsInboxActionPresenter()
        {
            IAction inboxAction = AnAction.In(State.Inbox).Build();

            var stubActionPresenter = new Mock <IActionPresenter>();

            var test = new SingleInboxActionSelector(AnInboxActionsFilter.Providing(inboxAction).Build(),
                                                     action => stubActionPresenter.Object,
                                                     new AlwaysSelectedPolicy());

            test.Initialize();

            Assert.Contains(stubActionPresenter.Object, test.Screens);
        }
        public bool AsyncCallbackWithState()
        {
            var d = new AnAction(DoAction);

            var ar = d.BeginInvoke(true, 10,
                                   new AsyncCallback(MyCallback),
                                   new object());

            do
            {
                Thread.Sleep(10);
            } while(!ar.IsCompleted && !CallBackCalled);

            return(true);
        }
        public void Apply__AppliesCurrentPresenter()
        {
            IAction action = AnAction.Build();

            var mockCommand = new Mock <ICommand>();

            _fakeProcessor.Setup(x => x.ApplyCommand).Returns(mockCommand.Object);

            var test = new ProcessActionPresenter(action, x => new[] { _fakeProcessor.Object });

            test.Initialize();

            test.Apply();

            mockCommand.Verify(x => x.Execute(action));
        }
        public void Actions_WhenWorkspaceHasMixedActions_ContainsOnlyInboxActions()
        {
            IAction inboxAction = AnAction.In(State.Inbox).Build();

            WorkspaceBuilder stubWorkspace =
                AWorkspace
                .With(AnAction.In(State.Committed))
                .With(inboxAction)
                .With(AnAction.In(State.Hold))
                .With(AnAction.In(State.SomedayMaybe));

            var test = new InboxActionsFilter(stubWorkspace.Build());

            Assert.Contains(inboxAction, test.Actions);
            Assert.Equal(1, test.Actions.Count);
        }
Esempio n. 28
0
        public void Presenters_WhenActionHasABlockingAction_ContainsPresenterForBlockingAction()
        {
            IAction blockingAction = AnAction.Build();
            var     stubPresenter  = new Mock <IActionPresenter>();

            var test = new BlockingActionsPresenter(AnAction.BlockedBy(blockingAction).Build(),
                                                    delegate(IAction action)
            {
                Assert.Same(blockingAction, action);
                return(stubPresenter.Object);
            });

            test.Initialize();

            Assert.Contains(stubPresenter.Object, test.Screens);
        }
        public void IsProcessingEnabled_WhenAnInboxActionIsAdded_RaisesPropertyChanged()
        {
            var actions = new ObservableCollection <IAction>();
            Mock <IInboxActionsFilter> inboxActionsFilter = AnInboxActionsFilter.ProvidingViewOf(actions);

            var test = new WorkspacePresenter(inboxActionsFilter.Object, null, null);

            bool eventRaised = false;

            test.PropertyChanged += (sender, args) => eventRaised |= args.PropertyName == "IsProcessingEnabled";

            actions.Add(AnAction.In(State.Inbox).Build());
            GC.KeepAlive(test);

            Assert.True(eventRaised);
        }
        public void Actions_WhenAnActionIsMovedOutOfTheInbox_RaisesCollectionChanged()
        {
            Mock <IAction> stubAction = AnAction.In(State.Inbox).Mock();
            IWorkspace     workspace  = AWorkspace.With(stubAction.Object).Build();

            var test = new InboxActionsFilter(workspace);

            bool eventRaised = false;

            test.Actions.CollectionChanged += (o, args) => eventRaised = true;

            stubAction.Setup(x => x.ActionState).Returns(State.Committed);
            stubAction.Raise(x => x.PropertyChanged += null, new PropertyChangedEventArgs("ActionState"));

            Assert.DoesNotContain(stubAction.Object, test.Actions);
            Assert.Empty(test.Actions);
            Assert.True(eventRaised);
        }
        public void Actions_WhenFirstInboxActionIsAddedToWorkspace_RaisesCollectionChanged()
        {
            IWorkspace workspace   = AWorkspace.Build();
            IAction    inboxAction = AnAction.In(State.Inbox).Build();

            var test = new InboxActionsFilter(workspace);

            bool eventRaised = false;

            test.Actions.CollectionChanged +=
                (o, args) =>
            {
                Assert.Same(inboxAction, args.NewItems.Cast <IAction>().Single());
                eventRaised = true;
            };

            workspace.Actions.Add(inboxAction);

            Assert.Contains(inboxAction, test.Actions);
            Assert.Equal(1, test.Actions.Count);
            Assert.True(eventRaised);
        }
Esempio n. 32
0
 public void Setup()
 {
     _result = new AnAction();
 }
Esempio n. 33
0
 public void CanExecute_WhenGivenAnAction_ReturnsTrue()
 {
     Assert.True(new DoNowCommand().CanExecute(AnAction.Build()));
 }