コード例 #1
0
        public async Task RemoveTest()
        {
            var mockSet     = new Mock <DbSet <ShowRoomViewer> >().SetupList(_sampleList);
            var mockContext = new Mock <LiveShowDBContext>();

            mockContext.Setup(x => x.ShowRoomViewer).Returns(mockSet.Object);
            var mockSvc = new ShowRoomViewerSvc(mockContext.Object);

            await mockSvc.Remove(new ShowRoomViewerDto()
            {
                UserId = 1, ShowRoomId = 1
            });

            mockSet.Verify(x => x.Remove(It.IsAny <ShowRoomViewer>()), Times.Once());
            mockContext.Verify(x => x.SaveChanges(), Times.Once());
        }
コード例 #2
0
        public async Task AddTest()
        {
            var mockSet     = new Mock <DbSet <ShowRoomViewer> >().SetupList(_sampleList);
            var mockRoomSet = new Mock <DbSet <ShowRoom> >().SetupList(_sampleRoomList);
            var mockContext = new Mock <LiveShowDBContext>();

            mockContext.Setup(x => x.ShowRoomViewer).Returns(mockSet.Object);
            mockContext.Setup(x => x.ShowRoom).Returns(mockRoomSet.Object);
            var mockSvc = new ShowRoomViewerSvc(mockContext.Object);

            var dto = new ShowRoomViewerDto()
            {
                UserId = 2, ShowRoomId = 2
            };
            await mockSvc.Add(dto);

            mockSet.Verify(x => x.Add(It.IsAny <ShowRoomViewer>()), Times.Once());
            mockContext.Verify(x => x.SaveChanges(), Times.Once());
        }