public void ThrowArgumentNullException_WhenSportsIsNull()
        {
            //Arrange
            var dbContextMock = new Mock <ISportscardSystemDbContext>();
            var mapperMock    = new Mock <IMapper>();

            var data = new List <Sport>
            {
                new Sport {
                    Name = "Gym"
                },
                new Sport {
                    Name = "Yoga"
                },
                new Sport {
                    Name = "Pilates"
                }
            };

            var mockSet = new Mock <DbSet <Sport> >();

            mockSet.SetupData(data);
            Mapper.Reset();
            AutomapperConfiguration.Initialize();

            dbContextMock
            .Setup(x => x.Sports)
            .Returns((IDbSet <Sport>)null);

            var sportService = new SportService(dbContextMock.Object, mapperMock.Object);

            //Act && Assert
            Assert.ThrowsException <ArgumentNullException>(() => sportService.GetAllSports());
        }
示例#2
0
        public void ShouldGetAllSports()
        {
            var sports = new List <Sport>
            {
                new Sport(),
                new Sport(),
                new Sport()
            };

            _sportRepositoryMock.Setup(x => x.GetAll())
            .Returns(sports);

            var result = _sportService.GetAllSports();

            Assert.Equal(sports.Count, result.Count);
        }
        public void ReturnIEnumerableOfSportDto_WhenCollectionIsNotNull()
        {
            //Arrange
            var dbContextMock = new Mock <ISportscardSystemDbContext>();
            var mapperMock    = new Mock <IMapper>();

            var data = new List <Sport>
            {
                new Sport {
                    Name = "Gym"
                },
                new Sport {
                    Name = "Yoga"
                },
                new Sport {
                    Name = "Pilates"
                }
            };

            var mockSet = new Mock <DbSet <Sport> >();

            mockSet.SetupData(data);
            Mapper.Reset();
            AutomapperConfiguration.Initialize();

            dbContextMock
            .Setup(x => x.Sports)
            .Returns(mockSet.Object);

            var sportService = new SportService(dbContextMock.Object, mapperMock.Object);

            //Act
            var sports = sportService.GetAllSports();

            //Assert
            Assert.AreEqual(data.Count, sports.Count());
            Assert.IsNotNull(sports);
            Assert.IsInstanceOfType(sports, typeof(IEnumerable <ISportDto>));
        }