Example #1
0
        public void ResponseReceivedForNewUserGroup_PublishesCorrectEvent()
        {
            var suitableParents = new[] { new UserGroupDto {
                                              Id = Guid.NewGuid()
                                          } };
            var userGroup = new UserGroupDto {
                Name = "some group", ParentId = suitableParents[0].Id
            };

            Presenter.BindingModel.Populate(suitableParents, userGroup);
            var newId = Guid.NewGuid();

            RequestDispatcherStub.SetResponsesToReturn(new SaveUserGroupResponse {
                NewUserGroupId = newId
            });

            Presenter.PersistChanges();
            RequestDispatcherStub.ReturnResponses();

            var publishedEvent = EventAggregatorStub.GetPublishedEvents <UserGroupChangedEvent>()[0];

            Assert.AreEqual(newId, publishedEvent.Id);
            Assert.AreEqual(userGroup.Name, publishedEvent.Name);
            Assert.AreEqual(userGroup.ParentId.Value, publishedEvent.ParentId.Value);
            Assert.IsTrue(publishedEvent.IsNew);
        }
Example #2
0
 public void InstructsViewToExpandTreeViewWhenUserGroupsHaveBeenReceived()
 {
     RequestDispatcherStub.SetResponsesToReturn(new GetAllUserGroupsResponse {
         UserGroups = new[] { new UserGroupDto() }
     });
     Presenter.Initialize();
     RequestDispatcherStub.ReturnResponses();
     ViewMock.Verify(v => v.ExpandTreeView());
 }
Example #3
0
 public void PopulatesModelWithReceivedUserGroups()
 {
     RequestDispatcherStub.SetResponsesToReturn(new GetAllUserGroupsResponse {
         UserGroups = new[] { new UserGroupDto() }
     });
     Presenter.Initialize();
     RequestDispatcherStub.ReturnResponses();
     Assert.AreEqual(1, Presenter.BindingModel.UserGroups.Count);
 }
Example #4
0
        public void PublishesUserGroupDeletedEventWhenResponseIsReturned()
        {
            Presenter.BindingModel.Id = Guid.NewGuid();
            RequestDispatcherStub.SetResponsesToReturn(new DeleteUserGroupResponse());

            Presenter.Delete();
            RequestDispatcherStub.ReturnResponses();

            Assert.AreEqual(Presenter.BindingModel.Id.Value, EventAggregatorStub.GetPublishedEvents <UserGroupDeletedEvent>()[0].UserGroupId);
        }
        public void PublishesEventIfRemoteExceptionOccurred()
        {
            var exception = new ExceptionInfo();

            Presenter.Handle(new UserGroupNeedsToBeCreatedEvent());
            RequestDispatcherStub.SetResponsesToReturn(new GetSuitableParentUserGroupsResponse {
                Exception = exception
            });
            RequestDispatcherStub.ReturnResponses();
            Assert.AreEqual(exception, EventAggregatorStub.GetPublishedEvents <RemoteExceptionOccurredEvent>()[0].ExceptionInfo);
        }
Example #6
0
        public void PublishesEventIfRemoteExceptionOccurred()
        {
            var exception = new ExceptionInfo();

            Presenter.Initialize();
            RequestDispatcherStub.SetResponsesToReturn(new GetAllUserGroupsResponse {
                Exception = exception
            });
            RequestDispatcherStub.ReturnResponses();
            Assert.AreEqual(exception, EventAggregatorStub.GetPublishedEvents <RemoteExceptionOccurredEvent>()[0].ExceptionInfo);
        }
Example #7
0
 public void HidesAddNewButtonOnViewIfUserDoesntHaveRequiredPermission()
 {
     RequestDispatcherStub.SetResponsesToReturn(new CheckPermissionsResponse
     {
         AuthorizationResults = new Dictionary <Guid, bool> {
             { Permissions.CreateUserGroup, false }
         }
     });
     Presenter.Initialize();
     RequestDispatcherStub.ReturnResponses();
     ViewMock.Verify(v => v.HideAddNewButton());
 }
Example #8
0
        public void PublishesEventIfRemoteExceptionOccurred()
        {
            Presenter.BindingModel.Id = Guid.NewGuid();
            var exception = new ExceptionInfo();

            RequestDispatcherStub.SetResponsesToReturn(new DeleteUserGroupResponse {
                Exception = exception
            });

            Presenter.Delete();
            RequestDispatcherStub.ReturnResponses();

            Assert.AreEqual(exception, EventAggregatorStub.GetPublishedEvents <RemoteExceptionOccurredEvent>()[0].ExceptionInfo);
        }
        public void ResponsesReceived_ShowsTheView()
        {
            var suitableParents = new[] { new UserGroupDto {
                                              Id = Guid.NewGuid()
                                          } };

            Presenter.Handle(new UserGroupNeedsToBeCreatedEvent());
            RequestDispatcherStub.SetResponsesToReturn(new GetSuitableParentUserGroupsResponse {
                SuitableParentUserGroups = suitableParents
            });
            RequestDispatcherStub.ReturnResponses();

            ViewMock.Verify(v => v.Show());
        }
        public void ResponseReceived_PopulatesModel()
        {
            var suitableParents = new[] { new UserGroupDto {
                                              Id = Guid.NewGuid()
                                          } };

            Presenter.Handle(new UserGroupNeedsToBeCreatedEvent());
            RequestDispatcherStub.SetResponsesToReturn(new GetSuitableParentUserGroupsResponse {
                SuitableParentUserGroups = suitableParents
            });
            RequestDispatcherStub.ReturnResponses();

            Assert.AreEqual(suitableParents[0].Id, Presenter.BindingModel.SuitableParentUserGroups[1].Id);
        }
Example #11
0
        public void ResponsesReceived_DoesNotTellViewToPreventModificationIfUserHasPermission()
        {
            Presenter.Handle(new UserGroupSelectedEvent(Guid.NewGuid()));
            RequestDispatcherStub.SetResponsesToReturn(new GetUserGroupResponse(),
                                                       new GetSuitableParentUserGroupsResponse {
                SuitableParentUserGroups = new UserGroupDto[0]
            },
                                                       new CheckPermissionsResponse
            {
                AuthorizationResults = new Dictionary <Guid, bool> {
                    { Permissions.DeleteUserGroup, true }, { Permissions.EditUserGroup, true }
                }
            });
            RequestDispatcherStub.ReturnResponses();

            ViewMock.Verify(v => v.PreventModification(), Times.Never());
        }
Example #12
0
        public void ResponseReceivedForNewUserGroup_UpdatesUserGroupIdInBindingModel()
        {
            var userGroup = new UserGroupDto {
                Id = Guid.NewGuid(), Name = "some group"
            };

            Presenter.BindingModel.Populate(new UserGroupDto[0], userGroup);
            var newId = Guid.NewGuid();

            RequestDispatcherStub.SetResponsesToReturn(new SaveUserGroupResponse {
                NewUserGroupId = newId
            });

            Presenter.PersistChanges();
            RequestDispatcherStub.ReturnResponses();

            Assert.AreEqual(newId, Presenter.BindingModel.Id.Value);
        }
Example #13
0
        public void PublishesEventIfRemoteExceptionOccurred()
        {
            var userGroup = new UserGroupDto {
                Id = Guid.NewGuid(), Name = "some group"
            };

            Presenter.BindingModel.Populate(new UserGroupDto[0], userGroup);
            var exception = new ExceptionInfo();

            RequestDispatcherStub.SetResponsesToReturn(new SaveUserGroupResponse {
                Exception = exception
            });

            Presenter.PersistChanges();
            RequestDispatcherStub.ReturnResponses();

            Assert.AreEqual(exception, EventAggregatorStub.GetPublishedEvents <RemoteExceptionOccurredEvent>()[0].ExceptionInfo);
        }