Example #1
0
        public ICollection <Contracts.DTO.Note> FindNotes(Contracts.DTO.BoundingBox box,
                                                          Contracts.DTO.User user)
        {
            if (user == null || box == null)
            {
                throw new ArgumentException("The user and bounding box must be non-null");
            }

            var notes = this._notes.Where(n => n.Pin.Latitude >= box.South &&
                                          n.Pin.Latitude <= box.North &&
                                          n.Pin.Longitude <= box.East &&
                                          n.Pin.Longitude >= box.West &&
                                          n.Pin.User.UserId == user.UserId);

            if (notes != null && notes.Count() > 0)
            {
                return(notes.Select(n => new Contracts.DTO.Note()
                {
                    NoteId = n.NoteId,
                    Added = n.Added,
                    Content = n.Content,
                    BelongsTo = n.Pin.PinId
                }).ToList <Contracts.DTO.Note>());
            }
            else
            {
                return(new List <Contracts.DTO.Note>());
            }
        }
Example #2
0
        public ICollection <Contracts.DTO.Pin> FindPins(Contracts.DTO.BoundingBox box,
                                                        Contracts.DTO.User user)
        {
            if (box == null || user == null)
            {
                throw new ArgumentException("The user and bounding box must be non-null");
            }

            var pins = this._pins.Where(p => p.Latitude >= box.South &&
                                        p.Latitude <= box.North &&
                                        p.Longitude <= box.East &&
                                        p.Longitude >= box.West &&
                                        p.User.UserId == user.UserId);

            if (pins != null && pins.Count() > 0)
            {
                return(pins.Select(p => new Contracts.DTO.Pin()
                {
                    BelongsTo = p.User.UserId,
                    Latitude = p.Latitude,
                    Longitude = p.Longitude,
                    Name = p.Name,
                    PinId = p.PinId
                }).ToList <Contracts.DTO.Pin>());
            }
            else
            {
                return(new List <Contracts.DTO.Pin>());
            }
        }
Example #3
0
        public void TestRemoveUser()
        {
            IUserAccessor      accessor = this._provider.GetService <IUserAccessor>();
            IUnitOfWork        uow      = this._provider.GetService <IUnitOfWork>();
            PersistenceContext context  = this._provider.GetService <PersistenceContext>();

            Assert.Equal(3, context.Users.Count());

            var user = new Contracts.DTO.User()
            {
                UserId = "bill"
            };

            accessor.RemoveUser(user);
            uow.Commit();

            Assert.Equal(2, context.Users.Count());

            Assert.Throws <ArgumentException>(() =>
            {
                accessor.RemoveUser(new Contracts.DTO.User()
                {
                    UserId = user.UserId
                });
            });


            Assert.Throws <InvalidOperationException>(() =>
            {
                accessor.RemoveUser(null);
            });
        }
Example #4
0
        public Contracts.DTO.User AddUser(Contracts.DTO.User user)
        {
            if (user == null ||
                user.FirstName == null ||
                user.LastName == null ||
                user.Email == null)
            {
                throw new ArgumentException("A user must have a first name, last name, and email address");
            }
            else if (this._users.Where(u => u.UserId == user.UserId)
                     .FirstOrDefault() != null)
            {
                throw new ArgumentException(string.Format("User already exists with ID {0}", user.UserId));
            }
            else
            {
                var id = Guid.NewGuid().ToString();

                var userEntity = new Models.User()
                {
                    UserId    = id,
                    FirstName = user.FirstName,
                    LastName  = user.LastName,
                    AvatarUrl = user.AvatarUrl,
                    Email     = user.Email,
                    Location  = user.Location
                };

                this._users.Add(userEntity);

                user.UserId = id;
                return(user);
            }
        }
Example #5
0
        public void TestAddUser()
        {
            IUserAccessor      accessor = this._provider.GetService <IUserAccessor>();
            IUnitOfWork        uow      = this._provider.GetService <IUnitOfWork>();
            PersistenceContext context  = this._provider.GetService <PersistenceContext>();

            Assert.Equal(3, context.Users.Count());

            var user = new Contracts.DTO.User()
            {
                AvatarUrl = @"http://www.google.com",
                Email     = "*****@*****.**",
                FirstName = "Test",
                LastName  = "User",
                Location  = "Any Place, USA"
            };

            user = accessor.AddUser(user);
            uow.Commit();

            Assert.Equal(4, context.Users.Count());
            var users = context.Users.ToList();

            Assert.Equal("Any Place, USA", context.Users.Where(u => u.UserId == user.UserId)
                         .FirstOrDefault().Location);

            Assert.Equal(user, accessor.FindUser(user.UserId));

            /* Test some bad data */
            Assert.Throws <ArgumentException>(() =>
            {
                accessor.AddUser(null);
            });

            Assert.Throws <ArgumentException>(() =>
            {
                accessor.AddUser(new Contracts.DTO.User()
                {
                    FirstName = "Bad",
                    LastName  = "User"
                });
            });

            /* Test entry of a user with an already existing ID */
            Assert.Throws <ArgumentException>(() =>
            {
                accessor.AddUser(new Contracts.DTO.User()
                {
                    FirstName = "Bad",
                    LastName  = "User",
                    Location  = "Death Valley",
                    Email     = "*****@*****.**",
                    UserId    = "bill"
                });
            });
        }
Example #6
0
        public ICollection <Contracts.DTO.Pin> FindPins(Contracts.DTO.User user)
        {
            if (user == null)
            {
                throw new ArgumentException("The pin cannot be null");
            }

            var uentity = this._users.Where(u => u.UserId == user.UserId).FirstOrDefault();

            if (uentity != null && uentity.Pins != null && uentity.Pins.Count > 0)
            {
                return(uentity.Pins.Select(p => new Contracts.DTO.Pin()
                {
                    BelongsTo = uentity.UserId,
                    Latitude = p.Latitude,
                    Longitude = p.Longitude,
                    Name = p.Name,
                    PinId = p.PinId
                }).ToList <Contracts.DTO.Pin>());
            }

            return(new List <Contracts.DTO.Pin>());
        }
Example #7
0
        public ICollection <Contracts.DTO.Note> FindNotes(Contracts.DTO.User user)
        {
            if (user == null)
            {
                throw new ArgumentException("The user cannot be null");
            }

            var notes = this._notes.Where(n => n.Pin.User.UserId == user.UserId);

            if (notes != null || notes.Count() > 0)
            {
                return(notes.Select(n => new Contracts.DTO.Note()
                {
                    NoteId = n.NoteId,
                    Added = n.Added,
                    BelongsTo = n.Pin.User.UserId,
                    Content = n.Content
                }).ToList <Contracts.DTO.Note>());
            }
            else
            {
                return(new List <Contracts.DTO.Note>());
            }
        }