Beispiel #1
0
        public void getById_MeetingRequstsFound()
        {
            List <MeetingRequest> meetingRequests = new List <MeetingRequest>();

            meetingRequests.PopulateMeetingRequests(3);

            meetingRequests.Skip(1).First().User.Id = meetingRequests.First().User.Id;
            meetingRequests.Skip(2).First().User.Id = meetingRequests.First().User.Id;

            List <MeetingRequest> expected = new List <MeetingRequest>();

            foreach (MeetingRequest meetingRequest in meetingRequests)
            {
                expected.Add(MockingHelper.CreateMeetingRequestCopy(meetingRequest));
            }

            _repositoryMock.Setup(f => f.getById(It.IsAny <string>())).Returns(meetingRequests);

            var result = _meetingServiceMock.Object.getById(meetingRequests.First().User.Id);

            _repositoryMock.Verify(f => f.getById(It.Is <string>(k => k == expected.First().User.Id)), Times.Once);

            Assert.AreEqual(expected.Count(), result.Count());
            for (int i = 0; i < result.Count; i++)
            {
                MockingHelper.CheckAssertsForMeetingRequest(expected.Skip(i).First(), result.Skip(i).First());
            }
        }
Beispiel #2
0
        public void getParticipants_EventsFound()
        {
            List <Event> events = new List <Event>();

            events.PopulateEvents(2);

            List <Event> expected = new List <Event>();

            foreach (Event ev in events)
            {
                expected.Add(MockingHelper.CreateEventCopy(ev));
            }

            Event firstEvent = events.First();

            _repositoryMock.Setup(f => f.getParticipants(It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <string>(), It.IsAny <PrioritiesY>())).Returns(events);

            var result = _meetingServiceMock.Object.getParticipants(firstEvent.Title, firstEvent.Start, firstEvent.End, firstEvent.Location, firstEvent.Priority);

            _repositoryMock.Verify(f => f.getParticipants(It.Is <string>(k => k == firstEvent.Title), It.Is <DateTime>(k => k == firstEvent.Start), It.Is <DateTime>(k => k == firstEvent.End), It.Is <string>(k => k == firstEvent.Location), It.Is <PrioritiesY>(k => k == firstEvent.Priority)), Times.Once);

            Assert.AreEqual(expected.Count(), result.Count());

            for (int i = 0; i < result.Count(); i++)
            {
                MockingHelper.CheckAssertsForEvent(expected.Skip(i).First(), result.Skip(i).First());
            }
        }
Beispiel #3
0
        public void getFriends_FriendsFound()
        {
            List <User> users = new List <User>();

            users.PopulateUsers(3);

            List <User> mockedUsers = new List <User>();

            foreach (User user in users)
            {
                mockedUsers.Add(MockingHelper.CreateUserCopy(user));
            }

            _connectionRepoMock.Setup(f => f.getFriends(It.IsAny <string>())).Returns(users);

            var result = _connectionServiceMock.Object.getFriends(users.First().UserName);

            _connectionRepoMock.Verify(f => f.getFriends(It.Is <string>(k => k == users.First().UserName)), Times.Once);

            Assert.AreEqual(mockedUsers.Count, result.Count);

            for (int i = 0; i < result.Count; i++)
            {
                MockingHelper.CheckAssertsForUser(mockedUsers.Skip(i).First(), result.Skip(i).First());
            }
        }
Beispiel #4
0
        public async Task AcceptConnection_ConnectionAcceptedAsync()
        {
            _connections.PopulateConnections(1);
            Connection connection = _connections.First();

            Connection mockedConnection = MockingHelper.CreateConnectionCopy(connection);

            _connectionRepoMock.Setup(f => f.AcceptConnection(It.IsAny <Connection>())).ReturnsAsync(connection);

            _connectionNotificationRepoMock.Setup(f => f.createNotification(It.IsAny <ConnectionNotification>()));

            var result = await _connectionServiceMock.Object.AcceptConnection(connection);

            _connectionRepoMock.Verify(f => f.AcceptConnection(It.Is <Connection>(k => k.ID == connection.ID &&
                                                                                  k.StartDate == connection.StartDate &&
                                                                                  k.Status == connection.Status &&
                                                                                  k.User1.Id == connection.User1.Id &&
                                                                                  k.User2.Id == connection.User2.Id)), Times.Once);
            _connectionNotificationRepoMock.Verify(f => f.createNotification(It.Is <ConnectionNotification>(k => k.User1.Id == connection.User2.Id &&
                                                                                                            k.User2.Id == connection.User1.Id &&
                                                                                                            k.Read == false &&
                                                                                                            k.Content == "accepted your request for connection" &&
                                                                                                            k.Date.ToShortDateString() == DateTime.Now.ToShortDateString())), Times.Once);
            MockingHelper.CheckAssertsForConnection(mockedConnection, result);
        }
Beispiel #5
0
        public void getByTitle_MeetingFound()
        {
            _meetings.PopulateMeetings(1);
            Meeting expected = MockingHelper.CreateMeetingCopy(_meetings.First());

            _repositoryMock.Setup(f => f.getByTitle(It.IsAny <string>())).Returns(_meetings.First());

            var result = _meetingServiceMock.Object.getByTitle(_meetings.First().Title);

            _repositoryMock.Verify(f => f.getByTitle(It.Is <string>(k => k == expected.Title)), Times.Once);

            MockingHelper.CheckAssertsForMeeting(expected, result);
        }
        public void getUserByUsername_UserFound()
        {
            User mockedUser = _users.PopulateUsers(1).FirstOrDefault();

            User expected = MockingHelper.CreateUserCopy(mockedUser);

            _userRepositoryMock.Setup(f => f.getUserByUsername(It.IsAny <string>())).Returns(mockedUser);

            var result = _userServiceMock.Object.getUserByUsername(mockedUser.UserName);

            _userRepositoryMock.Verify(f => f.getUserByUsername(It.Is <string>(v => v == mockedUser.UserName)), Times.Once);

            MockingHelper.CheckAssertsForUser(expected, result);
        }
        public async Task deleteEvent_EventDeletedAsync()
        {
            _events.PopulateEvents(1);
            Event eventModel = _events.First();

            _eventRepoMock.Setup(f => f.DeleteEvent(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <string>())).ReturnsAsync(eventModel);

            var result = await _eventServiceMock.Object.deleteEvent(eventModel.Title, eventModel.ID, eventModel.User.UserName);

            _eventRepoMock.Verify(f => f.DeleteEvent(It.Is <string>(k => k == eventModel.Title),
                                                     It.Is <Guid>(k => k == eventModel.ID),
                                                     It.Is <string>(k => k == eventModel.User.UserName)), Times.Once);

            MockingHelper.CheckAssertsForEvent(eventModel, result);
        }
        public void editEvent_EventEdited()
        {
            _events.PopulateEvents(1);
            Event eventModel = _events.First();

            _eventRepoMock.Setup(f => f.EditEvent(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <DateTime>(), It.IsAny <DateTime>())).Returns(eventModel);

            var result = _eventServiceMock.Object.editEvent(eventModel.Title, eventModel.ID, eventModel.Start, eventModel.End);

            _eventRepoMock.Verify(f => f.EditEvent(It.Is <string>(k => k == eventModel.Title),
                                                   It.Is <Guid>(k => k == eventModel.ID),
                                                   It.Is <DateTime>(k => k == eventModel.Start),
                                                   It.Is <DateTime>(k => k == eventModel.End)), Times.Once);

            MockingHelper.CheckAssertsForEvent(eventModel, result);
        }
Beispiel #9
0
        public void GetConnection_ConnectionFound()
        {
            _connections.PopulateConnections(1);
            Connection connection = _connections.First();

            Connection mockedConnection = MockingHelper.CreateConnectionCopy(connection);

            _connectionRepoMock.Setup(f => f.GetConnection(It.IsAny <string>(), It.IsAny <string>())).Returns(connection);

            var result = _connectionServiceMock.Object.GetConnection(connection.User1.Id, connection.User2.Id);

            _connectionRepoMock.Verify(f => f.GetConnection(It.Is <string>(k => k == connection.User1.Id),
                                                            It.Is <string>(k => k == connection.User2.Id)), Times.Once);

            MockingHelper.CheckAssertsForConnection(mockedConnection, result);
        }
        public async Task createEvent_EventCreatedAsync()
        {
            _events.PopulateEvents(1);
            Event eventModel = _events.First();

            _eventRepoMock.Setup(f => f.CreateEvent(It.IsAny <Event>())).ReturnsAsync(eventModel);

            var result = await _eventServiceMock.Object.createEvent(eventModel);

            _eventRepoMock.Verify(f => f.CreateEvent(It.Is <Event>(k => k.ID == eventModel.ID &&
                                                                   k.Location == eventModel.Location &&
                                                                   k.Title == eventModel.Title &&
                                                                   k.User.Id == eventModel.User.Id &&
                                                                   k.Priority == eventModel.Priority &&
                                                                   k.MR.ID == eventModel.MR.ID)), Times.Once);
            MockingHelper.CheckAssertsForEvent(eventModel, result);
        }
        public void getUserById_UserFound()
        {
            User mockedUser = _users.PopulateUsers(1).FirstOrDefault();

            User expected = MockingHelper.CreateUserCopy(mockedUser);

            //We use AAA syntax in each unit test in this project

            //Arrange
            _userRepositoryMock.Setup(f => f.getUserById(It.IsAny <string>())).Returns(mockedUser);

            //Act
            var result = _userServiceMock.Object.getUserById(mockedUser.Id);

            //Assert
            _userRepositoryMock.Verify(f => f.getUserById(It.Is <string>(v => v == mockedUser.Id)), Times.Once);

            MockingHelper.CheckAssertsForUser(expected, result);
        }
        public void getEvents_EventsFound()
        {
            _events.PopulateEvents(2);
            Event firstEvent  = _events.First();
            Event secondEvent = _events.Skip(1).First();

            secondEvent.User.UserName = firstEvent.User.UserName;

            _eventRepoMock.Setup(f => f.getEvents(It.IsAny <string>())).Returns(_events);

            var result = _eventServiceMock.Object.getEvents(firstEvent.User.UserName);

            _eventRepoMock.Verify(f => f.getEvents(It.Is <string>(k => k == firstEvent.User.UserName)), Times.Once);

            for (int i = 0; i < _events.Count(); i++)
            {
                MockingHelper.CheckAssertsForEvent(_events.Skip(i).First(), result.Skip(i).First());
            }
        }
        public void getAll_UsersFound()
        {
            _users.PopulateUsers(5);

            foreach (User user in _users)
            {
                expectedUsers.Add(MockingHelper.CreateUserCopy(user));
            }

            _userRepositoryMock.Setup(f => f.getAll()).Returns(_users);

            var result = _userServiceMock.Object.getAll();

            _userRepositoryMock.Verify(f => f.getAll(), Times.Once);

            Assert.AreEqual(expectedUsers.Count, result.Count);

            for (int i = 0; i < result.Count; i++)
            {
                MockingHelper.CheckAssertsForUser(expectedUsers.Skip(i).First(), result.Skip(i).First());
            }
        }
        public void getConnectionNotifications_ResultListNotEmpty()
        {
            _connectionNotifications.PopulateConnectionNotifications(2);

            foreach (ConnectionNotification connectionNotification in _connectionNotifications)
            {
                expectedConnectionNotifications.Add(MockingHelper.CreateConnectionNotificationCopy(connectionNotification));
            }

            _connectionNotificationRepositoryMock.Setup(f => f.getConnectionNotifications(It.IsAny <string>(),
                                                                                          It.IsAny <int>(),
                                                                                          It.IsAny <int>())).Returns(_connectionNotifications);

            _connectionNotificationRepositoryMock.Setup(f => f.readConnestionNotification(It.IsAny <ConnectionNotification>()));

            var result = _userServiceMock.Object.getConnectionNotifications(_connectionNotifications.First().User2.Id, 0, _connectionNotifications.Count);

            _connectionNotificationRepositoryMock.Verify(f => f.getConnectionNotifications(It.Is <string>(k => k == _connectionNotifications.First().User2.Id),
                                                                                           It.Is <int>(k => k == 0),
                                                                                           It.Is <int>(k => k == _connectionNotifications.Count)), Times.Once);

            for (int i = 0; i < _connectionNotifications.Count; i++)
            {
                _connectionNotificationRepositoryMock.Verify(f => f.readConnestionNotification(It.Is <ConnectionNotification>(k => k.User1.Id == _connectionNotifications.Skip(i).First().User1.Id&&
                                                                                                                              k.User2.Id == _connectionNotifications.Skip(i).First().User2.Id&&
                                                                                                                              k.ID == _connectionNotifications.Skip(i).First().ID&&
                                                                                                                              k.Content == _connectionNotifications.Skip(i).First().Content&&
                                                                                                                              k.Date == _connectionNotifications.Skip(i).First().Date
                                                                                                                              )), Times.Once());
            }

            Assert.AreEqual(expectedConnectionNotifications.Count, result.Count);

            for (int i = 0; i < result.Count; i++)
            {
                MockingHelper.CheckAssertsForConnectionNotification(expectedConnectionNotifications.Skip(i).First(), result.Skip(i).First());
            }
        }