Example #1
0
 public void Update(Badge item)
 {
     // Check there's not an object with same identifier already in context
     if (_context.Badge.Local.Select(x => x.Id == item.Id).Any())
     {
         throw new ApplicationException("Object already exists in context - you do not need to call Update. Save occurs on Commit");
     }
     _context.Entry(item).State = EntityState.Modified;  
 }
Example #2
0
        public void BadgeAwardedActivityAdd()
        {
            const string guidStrBadge = "515b7240-3be1-43d4-8846-c0b589cd1cd2";
            const string guidStrUser = "******";

            var activityRepository = Substitute.For<IActivityRepository>();
            IActivityService activityService = new ActivityService(activityRepository, _badgeRepository, _membershipRepository, _loggingService);
            var user = new MembershipUser { Id = new Guid(guidStrUser), UserName = "******" };
            var badge = new Badge { Id = new Guid(guidStrBadge) };

            activityService.BadgeAwarded(badge, user, DateTime.UtcNow);

            activityRepository.Received().Add((Arg.Is<Activity>(x => x.Data == BadgeActivity.KeyBadgeId + "=" + guidStrBadge + "," + BadgeActivity.KeyUserId + "=" + guidStrUser)));
        }
        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);
        }
Example #4
0
 /// <summary>
 /// New badge has been awarded
 /// </summary>
 /// <param name="badge"></param>
 /// <param name="user"> </param>
 /// <param name="timestamp"> </param>
 public void BadgeAwarded(Badge badge, MembershipUser user, DateTime timestamp)
 {
     var badgeActivity = BadgeActivity.GenerateMappedRecord(badge, user, timestamp);
     Add(badgeActivity);
 }
Example #5
0
 /// <summary>
 /// Generic single entity delete
 /// </summary>
 /// <param name="badge"></param>
 public void Delete(Badge badge)
 {
     badge.Users.Clear();
     _context.Badge.Remove(badge);
 }
Example #6
0
 /// <summary>
 /// Add a new badge (expected id already assigned)
 /// </summary>
 /// <param name="newBadge"></param>
 public Badge Add(Badge newBadge)
 {
     return _context.Badge.Add(newBadge);
 }