Ejemplo n.º 1
0
        public async Task deleteEvent_NoRelatedMeeting_EventDeleted()
        {
            _events.PopulateEvents(1);
            _events.ForEach(f => _dbSet.Add(MockingHelper.CreateEventCopy(f)));

            _meetings.PopulateMeetings(2);
            _meetings.ForEach(f => _dbMeetingSet.Add(MockingHelper.CreateMeetingCopy(f)));

            _meetingRequests.PopulateMeetingRequests(2);
            _meetingRequests.ForEach(f => _dbRequestsSet.Add(MockingHelper.CreateMeetingRequestCopy(f)));

            _contextMock.Setup(f => f.Events).Returns(_dbSet);
            _contextMock.Setup(f => f.Meetings).Returns(_dbMeetingSet);
            _contextMock.Setup(f => f.MeetingRequests).Returns(_dbRequestsSet);
            _contextMock.Setup(f => f.SaveChanges()).Returns(0);

            var result = await _eventRepoMock.Object.DeleteEvent(_events.First().Title, _events.First().ID, Guid.NewGuid().ToString());

            _contextMock.Verify(f => f.Events, Times.Exactly(3));
            _contextMock.Verify(f => f.Meetings, Times.Once);
            _contextMock.Verify(f => f.MeetingRequests, Times.Never);

            Assert.AreEqual(_dbSet.Count(), 0);
            MockingHelper.CheckAssertsForEvent(_events.First(), result);
        }
Ejemplo n.º 2
0
        public async Task deleteEvent_WithMeetingCreatorEventsAndMR_EventDeleted()
        {
            _events.PopulateEvents(3);
            _meetings.PopulateMeetings(2);
            _meetingRequests.PopulateMeetingRequests(1);

            _meetings.First().Title = _events.First().Title;
            _events.Skip(1).First().Title = _events.First().Title;
            _meetingRequests.First().Meeting.ID = _meetings.First().ID;

            _events.ForEach(f => _dbSet.Add(MockingHelper.CreateEventCopy(f)));
            _meetings.ForEach(f => _dbMeetingSet.Add(MockingHelper.CreateMeetingCopy(f)));
            _meetingRequests.ForEach(f => _dbRequestsSet.Add(MockingHelper.CreateMeetingRequestCopy(f)));

            _contextMock.Setup(f => f.Events).Returns(_dbSet);
            _contextMock.Setup(f => f.Meetings).Returns(_dbMeetingSet);
            _contextMock.Setup(f => f.MeetingRequests).Returns(_dbRequestsSet);
            _contextMock.Setup(f => f.SaveChanges()).Returns(0);

            var result = await _eventRepoMock.Object.DeleteEvent(_events.First().Title, _events.First().ID, _meetings.First().creator.UserName);

            _contextMock.Verify(f => f.Events, Times.Exactly(4));
            _contextMock.Verify(f => f.Meetings, Times.Exactly(2));
            _contextMock.Verify(f => f.MeetingRequests, Times.Exactly(2));
            _contextMock.Verify(f => f.SaveChanges(), Times.Once);

            Assert.AreEqual(_dbSet.Count(), 1);
            Assert.AreEqual(_dbRequestsSet.Count(), 0);
            Assert.AreEqual(_dbMeetingSet.Count(), 1);
            MockingHelper.CheckAssertsForEvent(_events.First(), result);
        }
        public void GetItemsTest()
        {
            // Arrange: set up a context mock with an initial collection of root items, exposed through a provider mock.
            Mock <IMyContext> myContextMock = new Mock <IMyContext>();
            var myRootItems = new DbSetMock <MyRootItem>(MyMockedRootItems);

            myContextMock.Setup(m => m.MyRootItems).Returns(myRootItems);
            Mock <IMyContextProvider> myContextProvider = new Mock <IMyContextProvider>();

            myContextProvider.Setup(m => m.CreateContext()).Returns(myContextMock.Object);

            // Act: create the service instance and call GetItems operation, preserving the result.
            var service = new MyService(myContextProvider.Object);
            var result  = service.GetItems();

            // Assert: verify that the context is created, and that the result is correct.
            myContextProvider.Verify(m => m.CreateContext());
            Assert.AreEqual(myRootItems.Count(), result.Count());
        }
        public void AddItemsTest()
        {
            // Arrange: set up a context mock with an empty collection of root items, exposed through a provider mock.
            Mock <IMyContext> myContextMock = new Mock <IMyContext>();
            var myRootItems = new DbSetMock <MyRootItem>();

            myContextMock.Setup(m => m.MyRootItems).Returns(myRootItems);
            Mock <IMyContextProvider> myContextProvider = new Mock <IMyContextProvider>();

            myContextProvider.Setup(m => m.CreateContext()).Returns(myContextMock.Object);

            // Act: create the service instance and call AddItems operation.
            var service = new MyService(myContextProvider.Object);

            service.AddItems();

            // Assert: verify that the context is created, and that the side effects are as expected.
            myContextProvider.Verify(m => m.CreateContext());
            Assert.AreEqual(2, myRootItems.Count());
        }
Ejemplo n.º 5
0
        public void rejectMR_MRRejected()
        {
            _meetings.PopulateMeetings(1);

            DbSetMock <MeetingRequest> _dbRequestSet    = new DbSetMock <MeetingRequest>();
            List <MeetingRequest>      _meetingRequests = new List <MeetingRequest>();

            _meetingRequests.PopulateMeetingRequests(3);
            _meetingRequests.Skip(1).First().Status = _meetingRequests.First().Status = false;
            _meetingRequests.First().Meeting = _meetings.First();
            _meetingRequests.First().ID      = Guid.NewGuid();

            _meetingRequests.ForEach(f => _dbRequestSet.Add(MockingHelper.CreateMeetingRequestCopy(f)));

            _contextMock.Setup(f => f.MeetingRequests).Returns(_dbRequestSet);
            _contextMock.Setup(f => f.SaveChanges()).Returns(0);

            _meetingRepoMock.Object.rejectMR(_meetings.First(), _meetings.First().creator, _meetingRequests.First().ID.ToString());

            Assert.AreEqual(_dbRequestSet.Count(), 2);

            _contextMock.Verify(f => f.MeetingRequests, Times.Exactly(2));
            _contextMock.Verify(f => f.SaveChanges(), Times.Once);
        }