Пример #1
0
            public void GivenList_ThenCallsSaveOnEach()
            {
                // arrange
                var mockRepository = new Mock <IRepository>(MockBehavior.Strict);
                var service        = new CardService(mockRepository.Object, new List <IInterrogator>());
                var cardsToSave    = new List <Card>
                {
                    new Card {
                        Name = "Test One"
                    },
                    new Card {
                        Name = "Test Two"
                    },
                    new Card {
                        Name = "Test Three"
                    },
                };

                mockRepository
                .Setup(x => x.GetAll <Card>())
                .Returns(new List <Card>().AsQueryable());
                mockRepository
                .Setup(x => x.Save(It.IsAny <Card>()))
                .Returns(Guid.NewGuid());

                // act
                service.BulkSave(cardsToSave);

                // assert
                mockRepository.Verify(x => x.Save(It.IsAny <Card>()), Times.Exactly(3));
            }
Пример #2
0
            public void GivenNullList_ThenThrowsArgumentNullException()
            {
                // arrange
                var mockRepository = new Mock <IRepository>(MockBehavior.Strict);
                var service        = new CardService(mockRepository.Object, new List <IInterrogator>());

                mockRepository
                .Setup(x => x.GetAll <Card>())
                .Returns(new List <Card>().AsQueryable());

                // act
                service.BulkSave(null);

                // assert
                Assert.Fail("ArgumentNullException should have been thrown.");
            }
Пример #3
0
            public void GivenListWithANullItem_ThenThrowsInvalidOperationException()
            {
                // arrange
                var mockRepository = new Mock <IRepository>(MockBehavior.Strict);
                var service        = new CardService(mockRepository.Object, new List <IInterrogator>());
                var cards          = new List <Card> {
                    null
                };

                mockRepository
                .Setup(x => x.GetAll <Card>())
                .Returns(new List <Card>().AsQueryable());

                // act
                service.BulkSave(cards);

                // assert
                Assert.Fail("InvalidOperationException should have been thrown.");
            }