コード例 #1
0
        public void CalculateBadgesEmptyRepositoriesTest()
        {
            var userRepositoryMock      = new Mock <IUserRepository>();
            var badgeTypeRepositoryMock = new Mock <IBadgeTypeRepository>();
            var badgeServiceMock        = new Mock <IBadgeService>();

            var badgeService = new BadgesServices(userRepositoryMock.Object, badgeTypeRepositoryMock.Object, badgeServiceMock.Object);

            badgeService.CalculateBadges();

            userRepositoryMock.Verify(e => e.Update(It.IsAny <User>()), Times.Never);
            badgeServiceMock.Verify(e => e.CalculateBadges(It.IsAny <User>(), It.IsAny <List <BadgeType> >()), Times.Never);
        }
コード例 #2
0
        public void CalculateBadgesEmptyBadgesTest()
        {
            var userRepositoryMock      = new Mock <IUserRepository>();
            var badgeTypeRepositoryMock = new Mock <IBadgeTypeRepository>();
            var badgeServiceMock        = new Mock <IBadgeService>();

            userRepositoryMock.Setup(e => e.GetAll()).Returns(new List <User>()
            {
                new User(), new User()
            });

            var badgeService = new BadgesServices(userRepositoryMock.Object, badgeTypeRepositoryMock.Object, badgeServiceMock.Object);

            badgeService.CalculateBadges();

            userRepositoryMock.Verify(e => e.Update(It.Is <User>(u => userRepositoryMock.Object.GetAll().Contains(u))), Times.Exactly(2));
            badgeServiceMock.Verify(e => e.CalculateBadges(It.Is <User>(u => userRepositoryMock.Object.GetAll().Contains(u)), It.Is <List <BadgeType> >(l => !l.Any())), Times.Exactly(2));
        }