Example #1
0
        public void AddReportTest()
        {
            UnitOfWork unit = new UnitOfWork();
            var user = ObjectHelpers.CreateUser("*****@*****.**");
            var @event = ObjectHelpers.CreateEvent(user);
            unit.UserRepository.Add(user);
            unit.EventRepository.Add(@event);
            unit.SaveChanges();
            user = unit.UserRepository.FindByEmail(user.Email);
            @event = unit.EventRepository.GetByTitle(@event.EventTitle);
            var report = ObjectHelpers.CreateReport(
                "AddReportTest",
                user,
                @event);

            unit.ReportRepository.Add(report);
            unit.SaveChanges();

            var reports = unit.ReportRepository.FindByEvent(@event.Id);
            Assert.IsTrue(reports.Any());
            Assert.IsTrue(reports.FirstOrDefault().Reason.Equals(report.Reason));
            reports = unit.ReportRepository.FindByUser(user.UserId);
            Assert.IsTrue(reports.Any());
            Assert.IsTrue(reports.FirstOrDefault().Reason.Equals(report.Reason));
            CleanUp(unit, report);
        }
Example #2
0
 private void CleanUp(UnitOfWork unit, Report report)
 {
     var user = report.ReportedBy;
     var @event = report.ReportedEvent;
     unit.ReportRepository.Remove(report);
     unit.EventRepository.Remove(@event);
     unit.UserRepository.Remove(user);
     unit.SaveChanges();
 }
Example #3
0
 public void AddRoleToUser()
 {
     UnitOfWork unit = new UnitOfWork();
     var user = CreateUser("*****@*****.**");
     unit.UserRepository.Add(user);
     unit.SaveChanges();
     var role = unit.RoleRepository.FindByName("User");
     user.Roles.Add(role);
     unit.UserRepository.Update(user);
     unit.SaveChanges();
     user = unit.UserRepository.FindByEmail(user.Email);
     role = unit.RoleRepository.FindByName("User");
     Assert.IsTrue(user.Roles.Count > 0);
     CleanUp(unit, user);
 }
Example #4
0
 public void AddKarmaTest()
 {
     UnitOfWork unit = new UnitOfWork();
     var user = CreateUser("*****@*****.**");
     unit.UserRepository.Add(user);
     unit.SaveChanges();
     user = unit.UserRepository.FindByEmail(user.Email);
     user.Karma++;
     unit.UserRepository.Update(user);
     unit.SaveChanges();
     user = unit.UserRepository.FindByEmail(user.Email);
     Assert.IsTrue(user.Karma == 1);
     user.Karma--;
     unit.UserRepository.Update(user);
     unit.SaveChanges();
     user = unit.UserRepository.FindByEmail(user.Email);
     Assert.IsTrue(user.Karma == 0);
     CleanUp(unit, user);
 }
        public void AttendEventTest()
        {
            var user = ObjectHelpers.CreateUser("*****@*****.**");
            var @event = ObjectHelpers.CreateEvent(user);
            var attendee = ObjectHelpers.CreateUser();
            UnitOfWork unit = new UnitOfWork();

            try
            {
                unit.UserRepository.Add(user);
                unit.SaveChanges();
                unit.UserRepository.Add(attendee);
                unit.SaveChanges();
                unit.EventRepository.Add(@event);
                unit.SaveChanges();
                //user = unit.UserRepository.FindByEmail(user.Email);
                //@event = unit.EventRepository.find
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            try
            {
                unit.AttendEvent(attendee, @event);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            unit.SaveChanges();
            var Weventq = unit.EventRepository.FindById(@event.Id);
            var userq = unit.UserRepository.FindById(attendee.UserId);
            Assert.IsTrue(unit.UserRepository.FindById(attendee.UserId).AttendedEvents.Count > 0);
            Assert.IsTrue(unit.EventRepository.FindById(@event.Id).Attendees.Count > 0);
            CleanUp(unit, @event, attendee);
        }
 private void CleanUp(UnitOfWork unit, Event @event, User attendee)
 {
     //var user = @event.Host;
     @event.Attendees = new List<User>();
     unit.EventRepository.Update(@event);
     unit.SaveChanges();
     attendee.AttendedEvents = new List<Event>();
     unit.UserRepository.Update(attendee);;
     unit.UserRepository.Remove(attendee);
     unit.EventRepository.Remove(@event);
     //unit.UserRepository.Remove(user);
     unit.SaveChanges();
 }
Example #7
0
 public void AddUserToSetTest()
 {
     UnitOfWork unit = new UnitOfWork();
     var user = CreateUser();
     unit.UserRepository.Add(user);
     unit.SaveChanges();
     var newUser = unit.UserRepository.FindByUserName(user.UserName);
     Assert.AreEqual(newUser.Email, user.Email);
     CleanUp(unit, user);
 }
Example #8
0
        public void AddRoleToUserManagerTest()
        {
            UserManager<Congregatio.CommonComponents.Identity.IdentityUser, Guid> _manager =
                new UserManager<CommonComponents.Identity.IdentityUser, Guid>(new UserStore());
            var IdentityUser = new CommonComponents.Identity.IdentityUser()
            {
                Email = "*****@*****.**",
                UserName = "******"
            };
            var result = _manager.Create(IdentityUser);
            if (result.Succeeded)
            {
                var createdUser = _manager.FindByEmail(IdentityUser.Email);
                _manager.AddToRole(createdUser.Id, "Admin");
                UnitOfWork unit = new UnitOfWork();
                var updatedUser = unit.UserRepository.FindByEmail(IdentityUser.Email);

                Assert.IsTrue(updatedUser.Roles.Count > 0);
            }
            throw new Exception();
        }
Example #9
0
 private void CleanUp(UnitOfWork unit, User user)
 {
     unit.UserRepository.Remove(user);
     unit.SaveChanges();
     user = unit.UserRepository.FindById(user.UserId);
 }
Example #10
0
 public void UpdateUserTest()
 {
     UnitOfWork unit = new UnitOfWork();
     var user = CreateUser();
     unit.UserRepository.Add(user);
     unit.SaveChanges();
     user.UserName = "******";
     unit.UserRepository.Update(user);
     unit.SaveChanges();
     Assert.AreEqual(unit.UserRepository.FindById(user.UserId).UserName, user.UserName);
     CleanUp(unit, user);
 }
Example #11
0
 public void StalkUserTest()
 {
     UnitOfWork unit = new UnitOfWork();
     var stalker = CreateUser("*****@*****.**");
     var stalked = CreateUser("*****@*****.**");
     unit.UserRepository.Add(stalker);
     unit.UserRepository.Add(stalked);
     unit.SaveChanges();
     stalker = unit.UserRepository.FindByEmail(stalker.Email);
     stalked = unit.UserRepository.FindByEmail(stalked.Email);
     stalker.StalkedPeople.Add(stalked);
     unit.UserRepository.Update(stalker);
     unit.SaveChanges();
     stalker = unit.UserRepository.FindByEmail(stalker.Email);
     stalked = unit.UserRepository.FindByEmail(stalked.Email);
     Assert.IsTrue(stalker.StalkedPeople.Count > 0);
     Assert.IsTrue(stalked.Stalkers.Count > 0);
     CleanUp(unit, stalker);
     CleanUp(unit, stalked);
 }
Example #12
0
 public void RemoveUserFromSetTest()
 {
     UnitOfWork unit = new UnitOfWork();
     var user = CreateUser();
     unit.UserRepository.Add(user);
     unit.SaveChanges();
     unit.UserRepository.Remove(user);
     unit.SaveChanges();
     Assert.IsNull(unit.UserRepository.FindById(user.UserId));
 }
Example #13
0
 //private OldiUserRepository _userRepository;
 public CongregatioService()
 {
     _unitOfWork = new UnitOfWork();
        // _userManager = new UserManager<Congregatio.CommonComponents.Identity.IdentityUser, Guid>(new Microsoft.AspNet.Identity.EntityFramework.UserStore<CommonComponents.Identity.IdentityUser>(_unitOfWork.Context));
     //    _userRepository = new OldiUserRepository();
 }