public void ReturnCorrectResult_IfCollectionIsNotEmpty()
        {
            // Arrange
            var fishCollection = Utils.GetFishCollection();
            var mockedDbSet    = MockDbSet.Mock(fishCollection.AsQueryable());

            var mockedDbContext = new Mock <IDatabaseContext>();

            mockedDbContext.Setup(c => c.Fish).Returns(mockedDbSet.Object);

            var fishService = new FishService(mockedDbContext.Object);

            // Act
            var allFish = fishService.GetAll();

            // Assert
            Assert.IsTrue(allFish.Count() == fishCollection.Count);
            var index = 0;

            foreach (var fish in allFish)
            {
                Assert.AreEqual(fishCollection[index].Name, fish.Name);
                Assert.AreEqual(fishCollection[index].ImageUrl, fish.ImageUrl);
                index++;
            }
        }
Beispiel #2
0
        public void GetCatchesTest()
        {
            //Arrange

            IFishService service = new FishService();

            //Act

            IList <Fangst> fangster = service.GetCatches();

            //Assert

            Assert.IsTrue(fangster.Count > 0);
        }
        public void ReturnNull_IfCollectionIsEmpty()
        {
            // Arrange
            var mockedDbContext = new Mock <IDatabaseContext>();

            mockedDbContext.Setup(c => c.Fish).Verifiable();

            var fishService = new FishService(mockedDbContext.Object);

            // Act
            var fish = fishService.GetAll();

            // Assert
            Assert.IsNull(fish);
            mockedDbContext.Verify(c => c.Fish, Times.Once);
        }
Beispiel #4
0
        public void AddFishToDbContext()
        {
            // Arrange
            var mockedCollection = new List <Fish>();
            var mockedDbSet      = MockDbSet.Mock(mockedCollection.AsQueryable());

            mockedDbSet.Setup(d => d.Add(It.IsAny <Fish>())).Callback <Fish>(f => mockedCollection.Add(f));

            var mockedDbContext = new Mock <IDatabaseContext>();

            mockedDbContext.Setup(c => c.Fish).Returns(mockedDbSet.Object);

            var fishService = new FishService(mockedDbContext.Object);
            var fish        = new Fish();

            // Act
            fishService.Add(fish);

            // Assert
            Assert.IsTrue(mockedCollection.Count == 1);
            Assert.IsTrue(mockedCollection.Contains(fish));
        }