コード例 #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="unitOfWorkManager"> </param>
 /// <param name="membershipService"> </param>
 /// <param name="localizationService"></param>
 /// <param name="settingsService"> </param>
 /// <param name="badgeService"> </param>
 /// <param name="loggingService"> </param>
 public AdminBadgeController(IBadgeService badgeService, IPostService postService, ILoggingService loggingService, IUnitOfWorkManager unitOfWorkManager, 
     IMembershipService membershipService, ILocalizationService localizationService, ISettingsService settingsService)
     : base(loggingService, unitOfWorkManager, membershipService, localizationService, settingsService)
 {
     _badgeService = badgeService;
     _postService = postService;
 }
コード例 #2
0
        public QuestionViewModel(IQuestionService questionService, 
                                    INavigationService navigationService,
                                    IBadgeService badgeService,
                                    ISettingsService settingsService,
                                    ILocalizationService localizationService,
                                    IAudioService audioService)
        {
            _questionService = questionService;
            _navigationService = navigationService;
            _badgeService = badgeService;
            _settingsService = settingsService;
            _localizationService = localizationService;
            _audioService = audioService;

            Messenger.Default.Register<Set>(this, Load);
            Messenger.Default.Register<CleanUp>(this, CallCleanUp);
#if DEBUG
            if (IsInDesignMode)
            {
                SelectedQuestion = new Question();

                BindQuestion(SelectedQuestion);

                ProgresLabel = "1/10";

                CorrectAnswers = 0;
                IncorrectAnswers = 0;
            }
#endif
        }
コード例 #3
0
        public virtual async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            var mapper = new ApiBadgeServerModelMapper();
            ApplicationDbContext        context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IBadgeService               service = testServer.Host.Services.GetService(typeof(IBadgeService)) as IBadgeService;
            ApiBadgeServerResponseModel model   = await service.Get(1);

            ApiBadgeClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", 1);

            UpdateResponse <ApiBadgeClientResponseModel> updateResponse = await client.BadgeUpdateAsync(model.Id, request);

            context.Entry(context.Set <Badge>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Badge>().ToList()[0].Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <Badge>().ToList()[0].Name.Should().Be("B");
            context.Set <Badge>().ToList()[0].UserId.Should().Be(1);

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            updateResponse.Record.Name.Should().Be("B");
            updateResponse.Record.UserId.Should().Be(1);
        }
コード例 #4
0
        public void UserAlreadyHasBadge()
        {
            _badgeRepository = Substitute.For <IBadgeRepository>();
            _badgeService    = new BadgeService(_badgeRepository, _api, _loggingService, _localizationService, _activityService);

            // Create a user with one vote no badges
            var user = new MembershipUser
            {
                Votes = new List <Vote>
                {
                    new Vote {
                        Id = Guid.NewGuid()
                    }
                },
                Badges = new List <Badge>(),
                BadgeTypesTimeLastChecked = new List <BadgeTypeTimeLastChecked>
                {
                    new BadgeTypeTimeLastChecked
                    {
                        BadgeType = BadgeType.VoteUp.ToString(), TimeLastChecked = GetTimeAllowsBadgeUpdate()
                    }
                }
            };


            // Call twice but only one badge awarded
            _badgeRepository.Get(Arg.Any <Guid>()).Returns(new Badge {
                Name = "testbadge"
            });
            _badgeService.ProcessBadge(BadgeType.VoteUp, user);
            _badgeService.ProcessBadge(BadgeType.VoteUp, user);

            Assert.IsTrue(user.Badges.Count == 1);
        }
コード例 #5
0
        public void UserVoteUpAwardBadge2()
        {
            _badgeRepository = Substitute.For <IBadgeRepository>();
            _badgeService    = new BadgeService(_badgeRepository, _api, _loggingService, _localizationService, _activityService);

            // Create a user with two votes no badges - will create a badge because no previous badge
            var user = new MembershipUser
            {
                Votes = new List <Vote>
                {
                    new Vote {
                        Id = Guid.NewGuid()
                    },
                    new Vote {
                        Id = Guid.NewGuid()
                    }
                },
                Badges = new List <Badge>(),
                BadgeTypesTimeLastChecked = new List <BadgeTypeTimeLastChecked>
                {
                    new BadgeTypeTimeLastChecked
                    {
                        BadgeType = BadgeType.VoteUp.ToString(), TimeLastChecked = GetTimeAllowsBadgeUpdate()
                    }
                }
            };

            _badgeRepository.Get(Arg.Any <Guid>()).Returns(new Badge {
                Name = "UserVoteUp"
            });
            _badgeService.ProcessBadge(BadgeType.VoteUp, user);

            Assert.IsTrue(user.Badges.Count == 1);
            Assert.IsTrue(user.Badges[0].Name == "UserVoteUp");
        }
コード例 #6
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="context"></param>
 /// <param name="settingsService"> </param>
 /// <param name="localizationService"> </param>
 /// <param name="activityService"> </param>
 /// <param name="cacheService"></param>
 /// <param name="voteService"></param>
 /// <param name="badgeService"></param>
 /// <param name="privateMessageService"></param>
 /// <param name="favouriteService"></param>
 /// <param name="membershipUserPointsService"></param>
 /// <param name="topicService"></param>
 /// <param name="categoryService"></param>
 /// <param name="postService"></param>
 /// <param name="notificationService"></param>
 /// <param name="pollService"></param>
 public MembershipService(IMvcForumContext context, ISettingsService settingsService,
                          ILocalizationService localizationService,
                          IActivityService activityService, ICacheService cacheService, IVoteService voteService,
                          IBadgeService badgeService,
                          IPrivateMessageService privateMessageService,
                          IFavouriteService favouriteService, IMembershipUserPointsService membershipUserPointsService,
                          ITopicService topicService, ICategoryService categoryService, IPostService postService,
                          INotificationService notificationService, IPollService pollService)
 {
     _settingsService             = settingsService;
     _localizationService         = localizationService;
     _activityService             = activityService;
     _cacheService                = cacheService;
     _voteService                 = voteService;
     _badgeService                = badgeService;
     _privateMessageService       = privateMessageService;
     _favouriteService            = favouriteService;
     _membershipUserPointsService = membershipUserPointsService;
     _topicService                = topicService;
     _categoryService             = categoryService;
     _postService                 = postService;
     _notificationService         = notificationService;
     _pollService                 = pollService;
     _context = context;
 }
コード例 #7
0
        public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            IBadgeService service = testServer.Host.Services.GetService(typeof(IBadgeService)) as IBadgeService;
            var           model   = new ApiBadgeServerRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", 1);
            CreateResponse <ApiBadgeServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.BadgeDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiBadgeServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
コード例 #8
0
ファイル: TopicTagService.cs プロジェクト: huchao007/mvcforum
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="tagRepository"></param>
 /// <param name="topicRepository"></param>
 /// <param name="categoryService"></param>
 public TopicTagService(ITopicTagRepository tagRepository, ITopicRepository topicRepository, ICategoryService categoryService, IBadgeService badgeService)
 {
     _tagRepository = tagRepository;
     _topicRepository = topicRepository;
     _categoryService = categoryService;
     _badgeService = badgeService;
 }
コード例 #9
0
ファイル: MembershipService.cs プロジェクト: yaobos/mvcforum
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="membershipRepository"> </param>
 /// <param name="settingsRepository"> </param>
 /// <param name="emailService"> </param>
 /// <param name="localizationService"> </param>
 /// <param name="activityService"> </param>
 /// <param name="privateMessageService"> </param>
 /// <param name="membershipUserPointsService"> </param>
 /// <param name="topicNotificationService"> </param>
 /// <param name="voteService"> </param>
 /// <param name="badgeService"> </param>
 /// <param name="categoryNotificationService"> </param>
 /// <param name="loggingService"></param>
 /// <param name="uploadedFileService"></param>
 /// <param name="postRepository"></param>
 /// <param name="pollVoteRepository"></param>
 /// <param name="pollAnswerRepository"></param>
 /// <param name="pollRepository"></param>
 /// <param name="topicRepository"></param>
 /// <param name="favouriteRepository"></param>
 /// <param name="categoryService"></param>
 public MembershipService(IMembershipRepository membershipRepository, ISettingsRepository settingsRepository,
                          IEmailService emailService, ILocalizationService localizationService, IActivityService activityService,
                          IPrivateMessageService privateMessageService, IMembershipUserPointsService membershipUserPointsService,
                          ITopicNotificationService topicNotificationService, IVoteService voteService, IBadgeService badgeService,
                          ICategoryNotificationService categoryNotificationService, ILoggingService loggingService, IUploadedFileService uploadedFileService,
                          IPostRepository postRepository, IPollVoteRepository pollVoteRepository, IPollAnswerRepository pollAnswerRepository,
                          IPollRepository pollRepository, ITopicRepository topicRepository, IFavouriteRepository favouriteRepository,
                          ICategoryService categoryService)
 {
     _membershipRepository        = membershipRepository;
     _settingsRepository          = settingsRepository;
     _emailService                = emailService;
     _localizationService         = localizationService;
     _activityService             = activityService;
     _privateMessageService       = privateMessageService;
     _membershipUserPointsService = membershipUserPointsService;
     _topicNotificationService    = topicNotificationService;
     _voteService  = voteService;
     _badgeService = badgeService;
     _categoryNotificationService = categoryNotificationService;
     _loggingService       = loggingService;
     _uploadedFileService  = uploadedFileService;
     _postRepository       = postRepository;
     _pollVoteRepository   = pollVoteRepository;
     _pollAnswerRepository = pollAnswerRepository;
     _pollRepository       = pollRepository;
     _topicRepository      = topicRepository;
     _favouriteRepository  = favouriteRepository;
     _categoryService      = categoryService;
 }
コード例 #10
0
ファイル: ActivityService.cs プロジェクト: zuTTers/mvcforum
 /// <summary>
 /// Constructor
 /// </summary>
 public ActivityService(IBadgeService badgeService, ILoggingService loggingService, IMVCForumContext context, ICacheService cacheService)
 {
     _badgeService   = badgeService;
     _loggingService = loggingService;
     _cacheService   = cacheService;
     _context        = context as MVCForumContext;
 }
コード例 #11
0
            public override void InstallBindings()
            {
                IBadgeService badgeService = Substitute.For <IBadgeService>();

                badgeService.currentBadges.Returns(new Data.BadgeData()
                {
                    AmountBadges = new int[] { 3, 2, 1 },
                    StreakBadges = new int[] { 2, 1, 1 },
                    TimeBadges   = new int[] { 5, 2, 1 }
                });

                IReadOnlyCollection <int> fastLevels = Array.AsReadOnly(new int[] { 2, 5, 10 });

                badgeService.fastLevels.Returns(fastLevels);

                IReadOnlyCollection <int> amountLevels = Array.AsReadOnly(new int[] { 4, 6, 8 });

                badgeService.amountLevels.Returns(amountLevels);

                IReadOnlyCollection <int> streakLevels = Array.AsReadOnly(new int[] { 1, 3, 5 });

                badgeService.streakLevels.Returns(streakLevels);

                badgeService.currentAmount.Returns(UnityEngine.Random.Range(0, amountLevels.Max() + 1));
                badgeService.currentFast.Returns(UnityEngine.Random.Range(0, fastLevels.Max() + 1));
                badgeService.currentStreak.Returns(UnityEngine.Random.Range(0, streakLevels.Max() + 1));

                Container.Bind <IBadgeService>().FromInstance(badgeService);
            }
コード例 #12
0
        public void SyncBadgesDeleteOldBadgeRecords()
        {
            _badgeRepository = Substitute.For <IBadgeRepository>();
            _badgeService    = new BadgeService(_badgeRepository, _api, _loggingService, _localizationService, _activityService);

            var badgesInDbAlready = new List <Badge>
            {
                new Badge
                {
                    Id   = new Guid("2ac1fc11-2f9e-4d5a-9df4-29715f10b6d1"),
                    Name = "PosterVoteUp"
                },
                new Badge
                {
                    Id   = new Guid("2ac1fc11-2f9e-4d5a-9df4-29715f10b6d2"),
                    Name = "BadgeWithNoMatchingClass"
                }
            };

            _badgeRepository.GetAll().Returns(badgesInDbAlready);

            _badgeService.SyncBadges();

            _badgeRepository.Received().Delete(Arg.Is <Badge>(x => x.Name == "BadgeWithNoMatchingClass"));
        }
コード例 #13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="context"></param>
 /// <param name="topicService"></param>
 /// <param name="categoryService"></param>
 /// <param name="badgeService"></param>
 public TopicTagService(IMVCForumContext context, ITopicService topicService, ICategoryService categoryService, IBadgeService badgeService)
 {
     _topicService    = topicService;
     _categoryService = categoryService;
     _badgeService    = badgeService;
     _context         = context as MVCForumContext;
 }
コード例 #14
0
        public void SyncBadgesUpdateBadgeRecords()
        {
            _badgeRepository = Substitute.For <IBadgeRepository>();
            _badgeService    = new BadgeService(_badgeRepository, _api, _loggingService, _localizationService, _activityService);

            var badgeInDb = new Badge
            {
                Id          = new Guid(GuidTestVoteUp),
                Name        = "XXX",
                DisplayName = "XXX",
                Description = "XXX",
                Image       = "XXX"
            };

            var badgesInDbAlready = new List <Badge>
            {
                badgeInDb
            };

            _badgeRepository.GetAll().Returns(badgesInDbAlready);

            _badgeService.SyncBadges();

            // The test badge class has been identified as the same badge as found in the "database", so that database
            // badge's fields have been updated with the test badge class's attributes
            Assert.IsTrue(badgeInDb.Name == NameTestVoteUp);
            Assert.IsTrue(badgeInDb.Description == DescriptionTestVoteUp);
            Assert.IsTrue(badgeInDb.DisplayName == DisplayNameTestVoteUp);
            Assert.IsTrue(badgeInDb.Image == ImageTestVoteUp);
        }
コード例 #15
0
 private void Construct(IAciEventManager eventManager, IWorkflowService workflowService, IBadgeService badgeService)
 {
     m_EventManager    = eventManager;
     m_WorkflowService = workflowService;
     m_BadgeService    = badgeService;
     RegisterForEvents();
 }
コード例 #16
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="membershipRepository"> </param>
 /// <param name="settingsRepository"> </param>
 /// <param name="emailService"> </param>
 /// <param name="localizationService"> </param>
 /// <param name="activityService"> </param>
 /// <param name="privateMessageService"> </param>
 /// <param name="membershipUserPointsService"> </param>
 /// <param name="topicNotificationService"> </param>
 /// <param name="voteService"> </param>
 /// <param name="badgeService"> </param>
 /// <param name="categoryNotificationService"> </param>
 /// <param name="loggingService"></param>
 /// <param name="uploadedFileService"></param>
 /// <param name="postRepository"></param>
 /// <param name="pollVoteRepository"></param>
 /// <param name="pollAnswerRepository"></param>
 /// <param name="pollRepository"></param>
 /// <param name="topicRepository"></param>
 /// <param name="favouriteRepository"></param>
 /// <param name="categoryService"></param>
 public MembershipService(IMembershipRepository membershipRepository, ISettingsRepository settingsRepository,
     IEmailService emailService, ILocalizationService localizationService, IActivityService activityService,
     IPrivateMessageService privateMessageService, IMembershipUserPointsService membershipUserPointsService,
     ITopicNotificationService topicNotificationService, IVoteService voteService, IBadgeService badgeService,
     ICategoryNotificationService categoryNotificationService, ILoggingService loggingService, IUploadedFileService uploadedFileService,
     IPostRepository postRepository, IPollVoteRepository pollVoteRepository, IPollAnswerRepository pollAnswerRepository,
     IPollRepository pollRepository, ITopicRepository topicRepository, IFavouriteRepository favouriteRepository,
     ICategoryService categoryService)
 {
     _membershipRepository = membershipRepository;
     _settingsRepository = settingsRepository;
     _emailService = emailService;
     _localizationService = localizationService;
     _activityService = activityService;
     _privateMessageService = privateMessageService;
     _membershipUserPointsService = membershipUserPointsService;
     _topicNotificationService = topicNotificationService;
     _voteService = voteService;
     _badgeService = badgeService;
     _categoryNotificationService = categoryNotificationService;
     _loggingService = loggingService;
     _uploadedFileService = uploadedFileService;
     _postRepository = postRepository;
     _pollVoteRepository = pollVoteRepository;
     _pollAnswerRepository = pollAnswerRepository;
     _pollRepository = pollRepository;
     _topicRepository = topicRepository;
     _favouriteRepository = favouriteRepository;
     _categoryService = categoryService;
 }
コード例 #17
0
ファイル: ActivityService.cs プロジェクト: lenwen/mvcforum
 /// <summary>
 /// Constructor
 /// </summary>
 public ActivityService(IBadgeService badgeService, ILoggingService loggingService, IMVCForumContext context, ICacheService cacheService)
 {
     _badgeService = badgeService;
     _loggingService = loggingService;
     _cacheService = cacheService;
     _context = context as MVCForumContext;
 }
コード例 #18
0
        public void AnniversaryTimeAwardBadge()
        {
            _badgeRepository = Substitute.For <IBadgeRepository>();
            _api.Topic       = Substitute.For <ITopicAPI>();
            _badgeService    = new BadgeService(_badgeRepository, _api, _loggingService, _localizationService, _activityService);

            var now  = DateTime.UtcNow;
            var user = new MembershipUser
            {
                CreateDate = new DateTime(now.Year - 1, now.Month, now.Day),
                Badges     = new List <Badge>(),
                BadgeTypesTimeLastChecked = new List <BadgeTypeTimeLastChecked>
                {
                    new BadgeTypeTimeLastChecked
                    {
                        BadgeType = BadgeType.VoteUp.ToString(), TimeLastChecked = GetTimeAllowsBadgeUpdate()
                    }
                }
            };

            _badgeRepository.Get(Arg.Any <Guid>()).Returns(new Badge {
                Name = "MemberForAYear"
            });

            _badgeService.ProcessBadge(BadgeType.Time, user);

            Assert.IsTrue(user.Badges.Count == 1);
            Assert.IsTrue(user.Badges[0].Name == "MemberForAYear");
        }
コード例 #19
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="context"></param>
 /// <param name="settingsService"> </param>
 /// <param name="emailService"> </param>
 /// <param name="localizationService"> </param>
 /// <param name="activityService"> </param>
 /// <param name="privateMessageService"> </param>
 /// <param name="membershipUserPointsService"> </param>
 /// <param name="topicNotificationService"> </param>
 /// <param name="voteService"> </param>
 /// <param name="badgeService"> </param>
 /// <param name="categoryNotificationService"> </param>
 /// <param name="loggingService"></param>
 /// <param name="uploadedFileService"></param>
 /// <param name="postService"></param>
 /// <param name="pollVoteService"></param>
 /// <param name="pollAnswerService"></param>
 /// <param name="pollService"></param>
 /// <param name="topicService"></param>
 /// <param name="favouriteService"></param>
 /// <param name="categoryService"></param>
 public MembershipService(IMVCForumContext context, ISettingsService settingsService,
                          IEmailService emailService, ILocalizationService localizationService, IActivityService activityService,
                          IPrivateMessageService privateMessageService, IMembershipUserPointsService membershipUserPointsService,
                          ITopicNotificationService topicNotificationService, IVoteService voteService, IBadgeService badgeService,
                          ICategoryNotificationService categoryNotificationService, ILoggingService loggingService, IUploadedFileService uploadedFileService,
                          IPostService postService, IPollVoteService pollVoteService, IPollAnswerService pollAnswerService,
                          IPollService pollService, ITopicService topicService, IFavouriteService favouriteService,
                          ICategoryService categoryService, IPostEditService postEditService)
 {
     _settingsService             = settingsService;
     _emailService                = emailService;
     _localizationService         = localizationService;
     _activityService             = activityService;
     _privateMessageService       = privateMessageService;
     _membershipUserPointsService = membershipUserPointsService;
     _topicNotificationService    = topicNotificationService;
     _voteService  = voteService;
     _badgeService = badgeService;
     _categoryNotificationService = categoryNotificationService;
     _loggingService      = loggingService;
     _uploadedFileService = uploadedFileService;
     _postService         = postService;
     _pollVoteService     = pollVoteService;
     _pollAnswerService   = pollAnswerService;
     _pollService         = pollService;
     _topicService        = topicService;
     _favouriteService    = favouriteService;
     _categoryService     = categoryService;
     _postEditService     = postEditService;
     _context             = context as MVCForumContext;
 }
コード例 #20
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="context"></param>
 /// <param name="topicService"></param>
 /// <param name="categoryService"></param>
 /// <param name="badgeService"></param>
 public TopicTagService(IMVCForumContext context, ITopicService topicService, ICategoryService categoryService, IBadgeService badgeService)
 {
     _topicService = topicService;
     _categoryService = categoryService;
     _badgeService = badgeService;
     _context = context as MVCForumContext;
 }
コード例 #21
0
ファイル: TopicTagService.cs プロジェクト: yaobos/mvcforum
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="tagRepository"></param>
 /// <param name="topicRepository"></param>
 /// <param name="categoryService"></param>
 public TopicTagService(ITopicTagRepository tagRepository, ITopicRepository topicRepository, ICategoryService categoryService, IBadgeService badgeService)
 {
     _tagRepository   = tagRepository;
     _topicRepository = topicRepository;
     _categoryService = categoryService;
     _badgeService    = badgeService;
 }
コード例 #22
0
        private void Construct(IAciEventManager eventManager,
                               IAdaptivityService adaptivityService,
                               IConfigProvider configProvider,
                               IWorkflowService workflowService,
                               ITimeTrackingRepository timeTrackingRepo,
                               IBot bot,
                               IBadgeService badgeService,
                               IAudioService audioService,
                               FeedbackActivityFactory factory,
                               FeedbackActivityLibrary library)
        {
            m_ConfigProvider    = configProvider;
            m_EventManager      = eventManager;
            m_AdaptivityService = adaptivityService;
            m_WorkflowService   = workflowService;
            m_TimeTrackingRepo  = timeTrackingRepo;
            m_BadgeService      = badgeService;
            m_Bot             = bot;
            m_Factory         = factory;
            m_ActivityLibrary = library;
            m_AudioService    = audioService;

            m_ConfigProvider?.RegisterClient(this);
            //write default values to config if no config values were loaded
            if (assetsUrl.IsNullOrEmpty())
            {
                m_ConfigProvider?.ClientDirty(this);
            }

            RegisterForEvents();
        }
コード例 #23
0
        public void PosterVoteUpRefuseBadge_TooSoon()
        {
            _badgeRepository = Substitute.For <IBadgeRepository>();
            _badgeService    = new BadgeService(_badgeRepository, _api, _loggingService, _localizationService, _activityService);

            // Create a user with one post with one vote
            var post = new Post
            {
                Id    = Guid.NewGuid(),
                Votes = new List <Vote> {
                    new Vote {
                        Id = Guid.NewGuid()
                    }
                },
            };

            var user = new MembershipUser
            {
                Posts = new List <Post> {
                    post
                },
                Badges = new List <Badge>(),
                BadgeTypesTimeLastChecked = new List <BadgeTypeTimeLastChecked>
                {
                    new BadgeTypeTimeLastChecked
                    {
                        BadgeType = BadgeType.VoteUp.ToString(), TimeLastChecked = GetTimeDisAllowsBadgeUpdate()
                    }
                }
            };

            _badgeService.ProcessBadge(BadgeType.VoteUp, user);

            Assert.IsTrue(user.Badges.Count == 0);
        }
コード例 #24
0
ファイル: MembershipService.cs プロジェクト: flerka/mvcforum
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="context"></param>
 /// <param name="settingsService"> </param>
 /// <param name="emailService"> </param>
 /// <param name="localizationService"> </param>
 /// <param name="activityService"> </param>
 /// <param name="privateMessageService"> </param>
 /// <param name="membershipUserPointsService"> </param>
 /// <param name="topicNotificationService"> </param>
 /// <param name="voteService"> </param>
 /// <param name="badgeService"> </param>
 /// <param name="categoryNotificationService"> </param>
 /// <param name="loggingService"></param>
 /// <param name="uploadedFileService"></param>
 /// <param name="postService"></param>
 /// <param name="pollVoteService"></param>
 /// <param name="pollAnswerService"></param>
 /// <param name="pollService"></param>
 /// <param name="topicService"></param>
 /// <param name="favouriteService"></param>
 /// <param name="categoryService"></param>
 public MembershipService(IMVCForumContext context, ISettingsService settingsService,
     IEmailService emailService, ILocalizationService localizationService, IActivityService activityService,
     IPrivateMessageService privateMessageService, IMembershipUserPointsService membershipUserPointsService,
     ITopicNotificationService topicNotificationService, IVoteService voteService, IBadgeService badgeService,
     ICategoryNotificationService categoryNotificationService, ILoggingService loggingService, IUploadedFileService uploadedFileService,
     IPostService postService, IPollVoteService pollVoteService, IPollAnswerService pollAnswerService,
     IPollService pollService, ITopicService topicService, IFavouriteService favouriteService, 
     ICategoryService categoryService, IPostEditService postEditService)
 {
     _settingsService = settingsService;
     _emailService = emailService;
     _localizationService = localizationService;
     _activityService = activityService;
     _privateMessageService = privateMessageService;
     _membershipUserPointsService = membershipUserPointsService;
     _topicNotificationService = topicNotificationService;
     _voteService = voteService;
     _badgeService = badgeService;
     _categoryNotificationService = categoryNotificationService;
     _loggingService = loggingService;
     _uploadedFileService = uploadedFileService;
     _postService = postService;
     _pollVoteService = pollVoteService;
     _pollAnswerService = pollAnswerService;
     _pollService = pollService;
     _topicService = topicService;
     _favouriteService = favouriteService;
     _categoryService = categoryService;
     _postEditService = postEditService;
     _context = context as MVCForumContext;
 }
コード例 #25
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="context"></param>
 /// <param name="membershipService"> </param>
 /// <param name="localizationService"></param>
 /// <param name="settingsService"> </param>
 /// <param name="badgeService"> </param>
 /// <param name="loggingService"> </param>
 public AdminBadgeController(IBadgeService badgeService, ILoggingService loggingService,
                             IMvcForumContext context,
                             IMembershipService membershipService, ILocalizationService localizationService,
                             ISettingsService settingsService)
     : base(loggingService, membershipService, localizationService, settingsService, context)
 {
     _badgeService = badgeService;
 }
コード例 #26
0
        public BadgeTracker(IBadgeService badgeService, IUserManager userManager, IAciEventManager eventManager)
        {
            m_BadgeService = badgeService;
            m_UserManager  = userManager;
            m_EventManger  = eventManager;

            RegisterForEvents();
        }
 private void Construct(INavigationService navigationService,
                        RewardParticleSystemFactory rewardParticleSystemFactory,
                        IBadgeService badgeService)
 {
     m_NavigationService           = navigationService;
     m_BadgeService                = badgeService;
     m_RewardParticleSystemFactory = rewardParticleSystemFactory;
 }
コード例 #28
0
        public void UserVoteUpAwardBadgeTwoUsers()
        {
            // Useful for testing badge service internal badge class instance cache is called

            _badgeRepository = Substitute.For <IBadgeRepository>();
            _badgeService    = new BadgeService(_badgeRepository, _api, _loggingService, _localizationService, _activityService);

            // Create a user with one vote no badges, set time checking offset to be safe so badge will be processed
            var user1 = new MembershipUser
            {
                Votes = new List <Vote>
                {
                    new Vote {
                        Id = Guid.NewGuid()
                    }
                },
                Badges = new List <Badge>(),

                BadgeTypesTimeLastChecked = new List <BadgeTypeTimeLastChecked>
                {
                    new BadgeTypeTimeLastChecked
                    {
                        BadgeType = BadgeType.VoteUp.ToString(), TimeLastChecked = GetTimeAllowsBadgeUpdate()
                    }
                }
            };

            // Create a user with one vote no badges, set time checking offset to be safe so badge will be processed
            var user2 = new MembershipUser
            {
                Votes = new List <Vote>
                {
                    new Vote {
                        Id = Guid.NewGuid()
                    }
                },
                Badges = new List <Badge>(),

                BadgeTypesTimeLastChecked = new List <BadgeTypeTimeLastChecked>
                {
                    new BadgeTypeTimeLastChecked
                    {
                        BadgeType = BadgeType.VoteUp.ToString(), TimeLastChecked = GetTimeAllowsBadgeUpdate()
                    }
                }
            };

            _badgeRepository.Get(Arg.Any <Guid>()).Returns(new Badge {
                Name = "UserVoteUp"
            });
            _badgeService.ProcessBadge(BadgeType.VoteUp, user1);
            _badgeService.ProcessBadge(BadgeType.VoteUp, user2);

            Assert.IsTrue(user1.Badges.Count == 1);
            Assert.IsTrue(user1.Badges[0].Name == "UserVoteUp");
            Assert.IsTrue(user2.Badges.Count == 1);
            Assert.IsTrue(user2.Badges[0].Name == "UserVoteUp");
        }
コード例 #29
0
 public PerguntaController(IPerguntaRepositorio perguntasRepositorio,
                           IUsuarioRepositorio usuarioRepositorio, ITagRepositorio tagsRepositorio,
                           IBadgeService badgeService)
 {
     this.perguntasRepositorio = perguntasRepositorio;
     this.usuarioRepositorio   = usuarioRepositorio;
     this.tagsRepositorio      = tagsRepositorio;
     this.badgeService         = badgeService;
 }
コード例 #30
0
 public TopicNotificationsAndBadgesPipe(IBadgeService badgeService, INotificationService notificationService,
                                        IActivityService activityService, ILocalizationService localizationService, ILoggingService loggingService)
 {
     _badgeService        = badgeService;
     _notificationService = notificationService;
     _activityService     = activityService;
     _localizationService = localizationService;
     _loggingService      = loggingService;
 }
コード例 #31
0
 public RespostaController(IRespostaRepositorio respostasRepositorio,
                           IPerguntaRepositorio perguntasRepositorio, IUsuarioRepositorio usuariosRepositorio,
                           IBadgeService badgeService)
 {
     this.perguntasRepositorio = perguntasRepositorio;
     this.respostasRepositorio = respostasRepositorio;
     this.usuariosRepositorio  = usuariosRepositorio;
     this.badgeService         = badgeService;
 }
コード例 #32
0
 public void SyncBadgesCreateNewBadgeRecords()
 {
     _badgeRepository = Substitute.For <IBadgeRepository>();
     _badgeService    = new BadgeService(_badgeRepository, _api, _loggingService, _localizationService, _activityService);
     _badgeService.SyncBadges();
     _badgeRepository.Received().Add(Arg.Is <Badge>(x => x.Name == "PosterVoteUp" &&
                                                    x.Id.ToString() == "2ac1fc11-2f9e-4d5a-9df4-29715f10b6d1" &&
                                                    x.Image == "PosterVoteUpBadge.png" &&
                                                    x.Description == "This badge is awarded to users after they receive their first vote up from another user."));
 }
コード例 #33
0
 /// <summary>
 /// Re-initializes test.
 /// </summary>
 public BadgeServiceTests()
 {
     _visitorLogContext   = Substitute.For <VisitorLogContext>();
     _badgeRepository     = new BadgeRepositoryFake(_visitorLogContext);
     _badgeTypeRepository = new BadgeTypeRepositoryFake(_visitorLogContext);
     _unitOfWork          = Substitute.For <IUnitOfWork>();
     _unitOfWork.BadgeRepository.Returns(_badgeRepository);
     _unitOfWork.BadgeTypeRepository.Returns(_badgeTypeRepository);
     _badgeService = new BadgeService(_unitOfWork);
 }
コード例 #34
0
 /// <summary>
 /// Constructor
 /// </summary>
 public ActivityService(IBadgeService badgeService, ILoggingService loggingService, IMvcForumContext context, ICacheService cacheService, ITopicService topicService, IPostService postService, ICategoryService categoryService)
 {
     _badgeService    = badgeService;
     _loggingService  = loggingService;
     _cacheService    = cacheService;
     _topicService    = topicService;
     _postService     = postService;
     _categoryService = categoryService;
     _context         = context;
 }
コード例 #35
0
        public void MarkAsSolutionAwardTwoBadges()
        {
            _badgeRepository = Substitute.For <IBadgeRepository>();
            _api.Topic       = Substitute.For <ITopicAPI>();
            _badgeService    = new BadgeService(_badgeRepository, _api, _loggingService, _localizationService, _activityService);

            // Create a user with one topic marked as solved
            var id   = Guid.NewGuid();
            var user = new MembershipUser
            {
                Id     = id,
                Badges = new List <Badge>(),
                BadgeTypesTimeLastChecked = new List <BadgeTypeTimeLastChecked>
                {
                    new BadgeTypeTimeLastChecked
                    {
                        BadgeType = BadgeType.VoteUp.ToString(), TimeLastChecked = GetTimeAllowsBadgeUpdate()
                    }
                }
            };

            var listPostsForMember = new List <Post> {
                new Post
                {
                    User = new MembershipUser
                    {
                        Id     = user.Id,
                        Badges = new List <Badge>()
                    },
                },
            };

            var listTopicsForMember = new List <Topic>
            {
                new Topic
                {
                    Solved = true,
                    User   = new MembershipUser
                    {
                        Id     = user.Id,
                        Badges = new List <Badge>()
                    },
                },
            };


            _api.Topic.GetSolvedTopicsByMember(id).Returns(listTopicsForMember);
            _api.Post.GetSolutionsWrittenByMember(id).Returns(listPostsForMember);
            _badgeRepository.Get(Arg.Any <Guid>()).Returns(new Badge {
                Name = "testbadge"
            });
            _badgeService.ProcessBadge(BadgeType.MarkAsSolution, user);

            Assert.IsTrue(user.Badges.Count == 2);
        }
コード例 #36
0
ファイル: SCManager.cs プロジェクト: GCEstrela/Credenciamento
        public static bool ImprimirCredencialVeiculo(ClasseVeiculosCredenciais.VeiculoCredencial veiculoCredencial)
        {
            try
            {
                //IEngine _sdk = Main.engine;

                Workspace m_workspace = PagePrincipalView.Workspace;

                bool _deletaCredencial = false;

                Cardholder _cardholder = _sdk.GetEntity((Guid)veiculoCredencial.CardHolderGuid) as Cardholder;

                if (_cardholder == null)
                {
                    return(false);
                }

                Credential _credencial = _sdk.GetEntity((Guid)veiculoCredencial.CredencialGuid) as Credential;

                if (_credencial == null)
                {
                    _credencial       = CriarCredencialProvisoria(_cardholder, veiculoCredencial.Validade, new Guid(veiculoCredencial.LayoutCrachaGUID));
                    _deletaCredencial = true;
                }

                Guid _CrachaGUID = new Guid(veiculoCredencial.LayoutCrachaGUID);
                Guid _CHGUID     = _credencial.CardholderGuid; // new Guid("227ee2c9-371f-408f-bf91-07cfb7ac8a74");

                System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    PrintQueue printQueue = GetPrintQueue();
                    if (printQueue != null)
                    {
                        IBadgeService badgeService = m_workspace.Services.Get <IBadgeService>();
                        if (badgeService != null)
                        {
                            BadgeInformation info = new BadgeInformation(_CrachaGUID, _credencial.Guid);
                            badgeService.BeginPrint(info, printQueue, OnBadgePrinted, null);
                        }
                    }
                }));

                if (_deletaCredencial)
                {
                    _sdk.DeleteEntity(_credencial);
                }


                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
コード例 #37
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="loggingService"> </param>
 /// <param name="badgeService"> </param>
 /// <param name="postService"> </param>
 /// <param name="membershipService"> </param>
 /// <param name="localizationService"></param>
 /// <param name="roleService"> </param>
 /// <param name="settingsService"> </param>
 /// <param name="favouriteService"></param>
 /// <param name="cacheService"></param>
 /// <param name="context"></param>
 public BadgeController(ILoggingService loggingService, IBadgeService badgeService, IPostService postService,
                        IMembershipService membershipService, ILocalizationService localizationService, IRoleService roleService,
                        ISettingsService settingsService, IFavouriteService favouriteService, ICacheService cacheService,
                        IMvcForumContext context)
     : base(loggingService, membershipService, localizationService, roleService,
            settingsService, cacheService, context)
 {
     _badgeService     = badgeService;
     _postService      = postService;
     _favouriteService = favouriteService;
 }
コード例 #38
0
 public void Init()
 {
     _api = Substitute.For<IMVCForumAPI>();
     _activityService = Substitute.For<IActivityService>();
     _privateMessageService = Substitute.For<IPrivateMessageService>();
     _membershipUserPointsService = Substitute.For<IMembershipUserPointsService>();
     _topicNotificationService = Substitute.For<ITopicNotificationService>();
     _voteService = Substitute.For<IVoteService>();
     _badgeService = Substitute.For<IBadgeService>();
     _categoryNotificationService = Substitute.For<ICategoryNotificationService>();
     _loggingService = Substitute.For<ILoggingService>();
 }
コード例 #39
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="badgeService"> </param>
 /// <param name="loggingService"> </param>
 /// <param name="unitOfWorkManager"> </param>
 /// <param name="postService"> </param>
 /// <param name="membershipService"> </param>
 /// <param name="localizationService"></param>
 /// <param name="roleService"> </param>
 /// <param name="settingsService"> </param>
 /// <param name="favouriteService"></param>
 public BadgeController(ILoggingService loggingService,
     IUnitOfWorkManager unitOfWorkManager,
     IBadgeService badgeService,
     IPostService postService,
     IMembershipService membershipService,
     ILocalizationService localizationService, IRoleService roleService,
     ISettingsService settingsService, IFavouriteService favouriteService)
     : base(loggingService, unitOfWorkManager, membershipService, localizationService, roleService, settingsService)
 {
     _badgeService = badgeService;
     _postService = postService;
     _favouriteService = favouriteService;
 }
コード例 #40
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="badgeService"> </param>
        /// <param name="loggingService"> </param>
        /// <param name="unitOfWorkManager"> </param>
        /// <param name="postService"> </param>
        /// <param name="membershipService"> </param>
        /// <param name="localizationService"></param>
        /// <param name="roleService"> </param>
        /// <param name="settingsService"> </param>
        public BadgeController(ILoggingService loggingService,
            IUnitOfWorkManager unitOfWorkManager,
            IBadgeService badgeService,
            IPostService postService,
            IMembershipService membershipService,
            ILocalizationService localizationService, IRoleService roleService,
            ISettingsService settingsService)
            : base(loggingService, unitOfWorkManager, membershipService, localizationService, roleService, settingsService)
        {
            _badgeService = badgeService;
            _postService = postService;

            LoggedOnUser = UserIsAuthenticated ? MembershipService.GetUser(Username) : null;
        }
コード例 #41
0
ファイル: VoteController.cs プロジェクト: huchao007/mvcforum
 public VoteController(ILoggingService loggingService,
     IUnitOfWorkManager unitOfWorkManager,
     IMembershipService membershipService,
     ILocalizationService localizationService,
     IRoleService roleService,
     IPostService postService,
     IVoteService voteService,
     ISettingsService settingsService,
     ITopicService topicService,
     IMembershipUserPointsService membershipUserPointsService,
     IBadgeService badgeService)
     : base(loggingService, unitOfWorkManager, membershipService, localizationService, roleService, settingsService)
 {
     _postService = postService;
     _voteService = voteService;
     _topicService = topicService;
     _membershipUserPointsService = membershipUserPointsService;
     _badgeService = badgeService;
 }
コード例 #42
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="membershipRepository"> </param>
 /// <param name="settingsRepository"> </param>
 /// <param name="emailService"> </param>
 /// <param name="localizationService"> </param>
 /// <param name="activityService"> </param>
 /// <param name="privateMessageService"> </param>
 /// <param name="membershipUserPointsService"> </param>
 /// <param name="topicNotificationService"> </param>
 /// <param name="voteService"> </param>
 /// <param name="badgeService"> </param>
 /// <param name="categoryNotificationService"> </param>
 /// <param name="api"> </param>
 /// <param name="loggingService"></param>
 public MembershipService(IMembershipRepository membershipRepository, ISettingsRepository settingsRepository,
     IEmailService emailService, ILocalizationService localizationService, IActivityService activityService, 
     IPrivateMessageService privateMessageService, IMembershipUserPointsService membershipUserPointsService, 
     ITopicNotificationService topicNotificationService, IVoteService voteService, IBadgeService badgeService,
     ICategoryNotificationService categoryNotificationService, IMVCForumAPI api, ILoggingService loggingService)
 {
     _membershipRepository = membershipRepository;
     _settingsRepository = settingsRepository;
     _emailService = emailService;
     _localizationService = localizationService;
     _activityService = activityService;
     _privateMessageService = privateMessageService;
     _membershipUserPointsService = membershipUserPointsService;
     _topicNotificationService = topicNotificationService;
     _voteService = voteService;
     _badgeService = badgeService;
     _categoryNotificationService = categoryNotificationService;
     _api = api;
     _loggingService = loggingService;
 }
コード例 #43
0
 public FavouriteController(ILoggingService loggingService, IUnitOfWorkManager unitOfWorkManager, IMembershipService membershipService, IRoleService roleService, ITopicService topicService, IPostService postService,
     ICategoryService categoryService, ILocalizationService localizationService, ISettingsService settingsService, ITopicTagService topicTagService, IMembershipUserPointsService membershipUserPointsService,
     ICategoryNotificationService categoryNotificationService, IEmailService emailService, ITopicNotificationService topicNotificationService, IPollService pollService,
     IPollAnswerService pollAnswerService, IBannedWordService bannedWordService, IVoteService voteService, IFavouriteService favouriteService, IBadgeService badgeService)
     : base(loggingService, unitOfWorkManager, membershipService, localizationService, roleService, settingsService)
 {
     _topicService = topicService;
     _postService = postService;
     _categoryService = categoryService;
     _topicTagService = topicTagService;
     _membershipUserPointsService = membershipUserPointsService;
     _categoryNotificationService = categoryNotificationService;
     _emailService = emailService;
     _topicNotificationService = topicNotificationService;
     _pollService = pollService;
     _pollAnswerService = pollAnswerService;
     _bannedWordService = bannedWordService;
     _voteService = voteService;
     _favouriteService = favouriteService;
     _badgeService = badgeService;
 }
コード例 #44
0
        public MainViewModel(
            ISetService setService, 
            INavigationService navigationService, 
            IBadgeService badgeService,
            ISettingsService settingsService,
            ILocalizationService localizationService,
            IPurchaseService purchaseService)
        {
            _setService = setService;
            _navigationService = navigationService;
            _badgeService = badgeService;
            _settingsService = settingsService;
            _localizationService = localizationService;
            _purchaseService = purchaseService;

            SetsList = new ObservableCollection<Set>();
            BadgesList = new ObservableCollection<Badge>();

            Messenger.Default.Register<CleanUp>(this, CallCleanUp);

            Refresh();
        }
コード例 #45
0
        public void VoteUpAwardTwoBadges()
        {
            _badgeRepository = Substitute.For<IBadgeRepository>();
            _badgeService = new BadgeService(_badgeRepository,  _api, _loggingService, _localizationService, _activityService);

            // Create a user with one post with one vote, and no badge, and one post with one vote
            var post = new Post
            {
                Id = Guid.NewGuid(),
                Votes = new List<Vote> { new Vote { Id = Guid.NewGuid() } },
            };

            var user = new MembershipUser
            {
                Posts = new List<Post> { post },
                Badges = new List<Badge>(),
                Votes = new List<Vote>
                            {
                                new Vote { Id = Guid.NewGuid() }
                            },
                BadgeTypesTimeLastChecked = new List<BadgeTypeTimeLastChecked> 
                { new BadgeTypeTimeLastChecked 
                    { BadgeType = BadgeType.VoteUp.ToString() , TimeLastChecked = GetTimeAllowsBadgeUpdate()} }
            };

            _badgeRepository.Get(Arg.Any<Guid>()).Returns(new Badge { Name = "testbadge" });

            _badgeService.ProcessBadge(BadgeType.VoteUp, user);

            Assert.IsTrue(user.Badges.Count == 3);

            // These tests can no longer work as we now fetch back the db badge records using a substitute
            //var foundPosterVoteUp = false;
            //var foundUserVoteUp = false;

            //foreach (var badge in user.Badges)
            //{
            //    if (badge.Name == "PosterVoteUp" || badge.Name == NameTestVoteUp)
            //    {
            //        foundPosterVoteUp = true;
            //    }
            //    else if (badge.Name == "UserVoteUp")
            //    {
            //        foundUserVoteUp = true;
            //    }
            //}
            //Assert.IsTrue(foundPosterVoteUp);
            //Assert.IsTrue(foundUserVoteUp);
        }
コード例 #46
0
        public void PosterVoteUpRefuseBadge_TooSoon()
        {
            _badgeRepository = Substitute.For<IBadgeRepository>();
            _badgeService = new BadgeService(_badgeRepository,  _api, _loggingService, _localizationService, _activityService);

            // Create a user with one post with one vote
            var post = new Post
            {
                Id = Guid.NewGuid(),
                Votes = new List<Vote> { new Vote { Id = Guid.NewGuid() } },
            };

            var user = new MembershipUser
            {
                Posts = new List<Post> { post },
                Badges = new List<Badge>(),
                BadgeTypesTimeLastChecked = new List<BadgeTypeTimeLastChecked> 
                { new BadgeTypeTimeLastChecked 
                    { BadgeType = BadgeType.VoteUp.ToString() , TimeLastChecked = GetTimeDisAllowsBadgeUpdate()} }
            };

            _badgeService.ProcessBadge(BadgeType.VoteUp, user);

            Assert.IsTrue(user.Badges.Count == 0);
        }
コード例 #47
0
        public void UserVoteUpAwardBadge2()
        {
            _badgeRepository = Substitute.For<IBadgeRepository>();
            _badgeService = new BadgeService(_badgeRepository, _api, _loggingService, _localizationService, _activityService);

            // Create a user with two votes no badges - will create a badge because no previous badge
            var user = new MembershipUser
            {
                Votes = new List<Vote>
                            {
                                new Vote { Id = Guid.NewGuid() },
                                new Vote { Id = Guid.NewGuid() }
                            },
                Badges = new List<Badge>(),
                BadgeTypesTimeLastChecked = new List<BadgeTypeTimeLastChecked> 
                { new BadgeTypeTimeLastChecked 
                    { BadgeType = BadgeType.VoteUp.ToString() , TimeLastChecked = GetTimeAllowsBadgeUpdate()} }
            };

            _badgeRepository.Get(Arg.Any<Guid>()).Returns(new Badge { Name = "UserVoteUp" });
            _badgeService.ProcessBadge(BadgeType.VoteUp, user);

            Assert.IsTrue(user.Badges.Count == 1);
            Assert.IsTrue(user.Badges[0].Name == "UserVoteUp");

        }
コード例 #48
0
        public void UserVoteUpAwardBadgeTwoUsers()
        {
            // Useful for testing badge service internal badge class instance cache is called

            _badgeRepository = Substitute.For<IBadgeRepository>();
            _badgeService = new BadgeService(_badgeRepository, _api, _loggingService, _localizationService, _activityService);

            // Create a user with one vote no badges, set time checking offset to be safe so badge will be processed
            var user1 = new MembershipUser
            {
                Votes = new List<Vote>
                            {
                                new Vote { Id = Guid.NewGuid() }
                            },
                Badges = new List<Badge>(),

                BadgeTypesTimeLastChecked = new List<BadgeTypeTimeLastChecked> 
                { new BadgeTypeTimeLastChecked 
                    { BadgeType = BadgeType.VoteUp.ToString() , TimeLastChecked = GetTimeAllowsBadgeUpdate()} }
            };

            // Create a user with one vote no badges, set time checking offset to be safe so badge will be processed
            var user2 = new MembershipUser
            {
                Votes = new List<Vote>
                            {
                                new Vote { Id = Guid.NewGuid() }
                            },
                Badges = new List<Badge>(),

                BadgeTypesTimeLastChecked = new List<BadgeTypeTimeLastChecked> 
                { new BadgeTypeTimeLastChecked 
                    { BadgeType = BadgeType.VoteUp.ToString() , TimeLastChecked = GetTimeAllowsBadgeUpdate()} }
            };

            _badgeRepository.Get(Arg.Any<Guid>()).Returns(new Badge { Name = "UserVoteUp" });
            _badgeService.ProcessBadge(BadgeType.VoteUp, user1);
            _badgeService.ProcessBadge(BadgeType.VoteUp, user2);

            Assert.IsTrue(user1.Badges.Count == 1);
            Assert.IsTrue(user1.Badges[0].Name == "UserVoteUp");
            Assert.IsTrue(user2.Badges.Count == 1);
            Assert.IsTrue(user2.Badges[0].Name == "UserVoteUp");
        }
コード例 #49
0
 public BadgeController()
 {
     UserInformationFactory.SetInstance(UserInformation<User, WhoIsOnline>.Instance(new HttpContextWrapper(System.Web.HttpContext.Current), new WhoIsOnlineService<User, WhoIsOnline>(new EntityWhoIsOnlineRepository()), new GetUserStrategy()));
     theBadgeService = new BadgeService();
     theUserRetrievalService = new UofMeUserRetrievalService();
 }
コード例 #50
0
        public void AnniversaryTimeBadgeRefuseBadge()
        {
            _badgeRepository = Substitute.For<IBadgeRepository>();
            _api.Topic = Substitute.For<ITopicAPI>();
            _badgeService = new BadgeService(_badgeRepository,  _api, _loggingService, _localizationService, _activityService);

            var now = DateTime.UtcNow;
            var user = new MembershipUser
            {
                CreateDate = new DateTime(now.Year, now.Month, now.Day),
                Badges = new List<Badge>(),
                BadgeTypesTimeLastChecked = new List<BadgeTypeTimeLastChecked> 
                { new BadgeTypeTimeLastChecked 
                    { BadgeType = BadgeType.VoteUp.ToString() , TimeLastChecked = GetTimeAllowsBadgeUpdate()} }
            };

            _badgeService.ProcessBadge(BadgeType.MarkAsSolution, user);

            Assert.IsTrue(user.Badges.Count == 0);
        }
コード例 #51
0
        public void MarkAsSolutionAwardTwoBadges()
        {
            _badgeRepository = Substitute.For<IBadgeRepository>();
            _api.Topic = Substitute.For<ITopicAPI>();
            _badgeService = new BadgeService(_badgeRepository,  _api, _loggingService, _localizationService, _activityService);

            // Create a user with one topic marked as solved 
            var id = Guid.NewGuid();
            var user = new MembershipUser
            {
                Id = id,
                Badges = new List<Badge>(),
                BadgeTypesTimeLastChecked = new List<BadgeTypeTimeLastChecked> 
                { new BadgeTypeTimeLastChecked 
                    { BadgeType = BadgeType.VoteUp.ToString() , TimeLastChecked = GetTimeAllowsBadgeUpdate()} }
            };

            var listPostsForMember = new List<Post> {
                new Post
                            {
                                User = new MembershipUser
                                {
                                    Id = user.Id,
                                    Badges = new List<Badge>()
                                },
                            },
               };

            var listTopicsForMember = new List<Topic> 
            {
                 new Topic
                            {
                                Solved = true,
                                User = new MembershipUser
                                {
                                    Id = user.Id,
                                    Badges = new List<Badge>()
                                },
                            },
               };


            _api.Topic.GetSolvedTopicsByMember(id).Returns(listTopicsForMember);
            _api.Post.GetSolutionsWrittenByMember(id).Returns(listPostsForMember);
            _badgeRepository.Get(Arg.Any<Guid>()).Returns(new Badge { Name = "testbadge" });
            _badgeService.ProcessBadge(BadgeType.MarkAsSolution, user);

            Assert.IsTrue(user.Badges.Count == 2);
        }        
コード例 #52
0
        public void Init()
        {
            _api = Substitute.For<IMVCForumAPI>();
            _loggingService = Substitute.For<ILoggingService>();
            _localizationService = Substitute.For<ILocalizationService>();
            _activityService = Substitute.For<IActivityService>();

            AppendBadgeClassPath();

            // Ensure a database sync
            _badgeRepository = Substitute.For<IBadgeRepository>();
            _badgeService = new BadgeService(_badgeRepository,  _api, _loggingService, _localizationService, _activityService);
            _badgeService.SyncBadges();
        }
コード例 #53
0
 public BadgesServices(IUserRepository userRepository, IBadgeTypeRepository badgeTypeRepository, IBadgeService badgeService)
 {
     this.userRepository = userRepository;
     this.badgeTypeRepository = badgeTypeRepository;
     this.badgeService = badgeService;
 }
コード例 #54
0
        public void VoteUpAwardOneBadgeOutOfTwo()
        {
            _badgeRepository = Substitute.For<IBadgeRepository>();
            _badgeService = new BadgeService(_badgeRepository, _api, _loggingService, _localizationService, _activityService);

            // Create a user with one post with one vote, and no badge, and one post with no votes
            var user = new MembershipUser
            {
                Posts = new List<Post> { 
                    new Post{ 
                            Id = Guid.NewGuid(),
                            Votes = new List<Vote> { new Vote { Id = Guid.NewGuid() } },
                            }    
                },
                Badges = new List<Badge>(),
                Votes = new List<Vote>(),
                BadgeTypesTimeLastChecked = new List<BadgeTypeTimeLastChecked> 
                        { new BadgeTypeTimeLastChecked 
                                { BadgeType = BadgeType.VoteUp.ToString() , TimeLastChecked = GetTimeAllowsBadgeUpdate()} }
            };

            _badgeRepository.Get(Arg.Any<Guid>()).Returns(new Badge { Name = "testbadge" });
            _badgeService.ProcessBadge(BadgeType.VoteUp, user);

            Assert.IsTrue(user.Badges.Count == 2);
        }
コード例 #55
0
        public void TopicAuthorMarkAsSolutionAwardBadge2()
        {
            _badgeRepository = Substitute.For<IBadgeRepository>();
            _api.Topic = Substitute.For<ITopicAPI>();
            _badgeService = new BadgeService(_badgeRepository, _api, _loggingService, _localizationService, _activityService);

            // Create a user with two topics marked as solved BUT no badge yet so will be awarded
            var id = Guid.NewGuid();
            var user = new MembershipUser
            {
                Id = id,
                Badges = new List<Badge>(),
                BadgeTypesTimeLastChecked = new List<BadgeTypeTimeLastChecked> 
                { new BadgeTypeTimeLastChecked 
                    { BadgeType = BadgeType.VoteUp.ToString() , TimeLastChecked = GetTimeAllowsBadgeUpdate()} }
            };

            var listTopicsForMember = new List<Topic> 
            {
                new Topic
                            {
                                Solved = true,
                                User = new MembershipUser
                                {
                                    Id = user.Id,
                                    Badges = new List<Badge>()
                                },
                            },
                 new Topic
                            {
                                Solved = true,
                                User = new MembershipUser
                                {
                                    Id = user.Id,
                                    Badges = new List<Badge>()
                                },
                            },
               };

            _api.Topic.GetSolvedTopicsByMember(id).Returns(listTopicsForMember);
            _badgeService.ProcessBadge(BadgeType.MarkAsSolution, user);

            Assert.IsTrue(user.Badges.Count == 1);
        }
コード例 #56
0
 public void SyncBadgesCreateNewBadgeRecords()
 {
     _badgeRepository = Substitute.For<IBadgeRepository>();
     _badgeService = new BadgeService(_badgeRepository, _api, _loggingService, _localizationService, _activityService);
     _badgeService.SyncBadges();
     _badgeRepository.Received().Add(Arg.Is<Badge>(x => x.Name == "PosterVoteUp"
         && x.Id.ToString() == "2ac1fc11-2f9e-4d5a-9df4-29715f10b6d1"
         && x.Image == "PosterVoteUpBadge.png"
         && x.Description == "This badge is awarded to users after they receive their first vote up from another user."));
 }
コード例 #57
0
        public void AnniversaryTimeAwardBadge()
        {
            _badgeRepository = Substitute.For<IBadgeRepository>();
            _api.Topic = Substitute.For<ITopicAPI>();
            _badgeService = new BadgeService(_badgeRepository,  _api, _loggingService, _localizationService, _activityService);

            var now = DateTime.UtcNow;
            var user = new MembershipUser
                           {
                               CreateDate = new DateTime(now.Year - 1, now.Month, now.Day),
                               Badges = new List<Badge>(),
                               BadgeTypesTimeLastChecked = new List<BadgeTypeTimeLastChecked> 
                                    { new BadgeTypeTimeLastChecked 
                                        { BadgeType = BadgeType.VoteUp.ToString() , TimeLastChecked = GetTimeAllowsBadgeUpdate()} }
                                               };

            _badgeRepository.Get(Arg.Any<Guid>()).Returns(new Badge { Name = "MemberForAYear" });

            _badgeService.ProcessBadge(BadgeType.Time, user);

            Assert.IsTrue(user.Badges.Count == 1);
            Assert.IsTrue(user.Badges[0].Name == "MemberForAYear");
        }
コード例 #58
0
        public void SyncBadgesDeleteOldBadgeRecords()
        {
            _badgeRepository = Substitute.For<IBadgeRepository>();
            _badgeService = new BadgeService(_badgeRepository, _api, _loggingService, _localizationService, _activityService);

            var badgesInDbAlready = new List<Badge>
                                        {
                                            new Badge
                                                {
                                                    Id = new Guid("2ac1fc11-2f9e-4d5a-9df4-29715f10b6d1"),
                                                    Name = "PosterVoteUp"
                                                },
                                            new Badge
                                                {
                                                    Id = new Guid("2ac1fc11-2f9e-4d5a-9df4-29715f10b6d2"),
                                                    Name = "BadgeWithNoMatchingClass"
                                                }
                                        };
            _badgeRepository.GetAll().Returns(badgesInDbAlready);

            _badgeService.SyncBadges();

            _badgeRepository.Received().Delete(Arg.Is<Badge>(x => x.Name == "BadgeWithNoMatchingClass"));
        }
コード例 #59
0
        public void UserAlreadyHasBadge()
        {
            _badgeRepository = Substitute.For<IBadgeRepository>();
            _badgeService = new BadgeService(_badgeRepository, _api, _loggingService, _localizationService, _activityService);

            // Create a user with one vote no badges
            var user = new MembershipUser
            {
                Votes = new List<Vote>
                            {
                                new Vote { Id = Guid.NewGuid() }
                            },
                Badges = new List<Badge>(),
                BadgeTypesTimeLastChecked = new List<BadgeTypeTimeLastChecked> 
                { new BadgeTypeTimeLastChecked 
                    { BadgeType = BadgeType.VoteUp.ToString() , TimeLastChecked = GetTimeAllowsBadgeUpdate()} }
            };

            
            // Call twice but only one badge awarded
            _badgeRepository.Get(Arg.Any<Guid>()).Returns(new Badge { Name = "testbadge" });
            _badgeService.ProcessBadge(BadgeType.VoteUp, user);
            _badgeService.ProcessBadge(BadgeType.VoteUp, user);

            Assert.IsTrue(user.Badges.Count == 1);
        }
コード例 #60
0
        public void SyncBadgesUpdateBadgeRecords()
        {
            _badgeRepository = Substitute.For<IBadgeRepository>();
            _badgeService = new BadgeService(_badgeRepository, _api, _loggingService, _localizationService, _activityService);

            var badgeInDb = new Badge
                                {
                                    Id = new Guid(GuidTestVoteUp),
                                    Name = "XXX",
                                    DisplayName = "XXX",
                                    Description = "XXX",
                                    Image = "XXX"
                                };
   
            var badgesInDbAlready = new List<Badge>
                                        {
                                           badgeInDb                                          
                                        };

            _badgeRepository.GetAll().Returns(badgesInDbAlready);

            _badgeService.SyncBadges();

            // The test badge class has been identified as the same badge as found in the "database", so that database
            // badge's fields have been updated with the test badge class's attributes
            Assert.IsTrue(badgeInDb.Name == NameTestVoteUp);
            Assert.IsTrue(badgeInDb.Description == DescriptionTestVoteUp);
            Assert.IsTrue(badgeInDb.DisplayName == DisplayNameTestVoteUp);
            Assert.IsTrue(badgeInDb.Image == ImageTestVoteUp);
        }