Exemple #1
0
        public void GivenAnUnRegisteredUser_WhenAUserRegisters_ThenAnExceptionIsThrown()
        {
            _repository.Setup(r => r.Entities).Returns(new System.Collections.Generic.List<User> { new User { Email = "" } }.AsQueryable());

            var service = new UserService(_repository.Object);
            service.UnRegister().Should().BeFalse();
        }
Exemple #2
0
        public void GivenARegisteredUser_WhenAUserRegisters_ThenAnExceptionIsThrown()
        {
            _repository.Setup(r => r.Entities).Returns(new System.Collections.Generic.List<User> { new User { Email = "somename" } }.AsQueryable());

            var service = new UserService(_repository.Object);
            Action act = () => service.Register(It.IsAny<string>(), It.IsAny<string>());
            act.ShouldThrow<ItsaException>();
        }
Exemple #3
0
        public void GivenAnUnregisteredUser_WhenTheUserLogon_ThenTheLogonThrowsAnException()
        {
            _repository.Setup(r => r.Entities).Returns(new System.Collections.Generic.List<User>().AsQueryable());
            var service = new UserService(_repository.Object);
            Action act = () =>service.Logon(It.IsAny<string>(), It.IsAny<string>());

            act.ShouldThrow<ItsaException>();
        }
 public UserActionService(UserService _Service,User_GroupService _Group,User_Role_ModuleService role,
     ModuleService module, EmailListService Email)
 {
     Service = _Service;
        GroupService = _Group;
        RoleService = role;
        ModuleService = module;
        EmailService = Email;
 }
Exemple #5
0
        public void GivenARegisteredUser_WhenAUserUnRegisters_ThenCreateIsCalled()
        {
            _repository.Setup(r => r.Entities).Returns(new System.Collections.Generic.List<User> { new User { Email = "somename" } }.AsQueryable());

            var service = new UserService(_repository.Object);
            service.UnRegister();

            _repository.Verify(r => r.Create(It.IsAny<User>()), Times.Once());
        }
        public void FollowUser_WhenUserWantsToFollowHimself_ReturnFalse()
        {
            var storageMock = new Mock<IEntityStorage<User>>();
            storageMock.SetupGet(x => x.Entities)
                .Returns(new List<User> { new User { UserName = "******" } });
            var dateTimeServiceMock = new Mock<IDateTimeService>();
            var service = new UserService(storageMock.Object, dateTimeServiceMock.Object) as IUserService;

            var result = service.FollowUser("franta", "franta");

            Assert.IsFalse(result);
        }
        public void GetUserByUserName_WhenUserDoesNotExist_ReturnNull()
        {
            var storageMock = new Mock<IEntityStorage<User>>();
            storageMock.SetupGet(x => x.Entities)
                .Returns(new List<User>());

            var dateTimeServiceMock = new Mock<IDateTimeService>();
            var service = new UserService(storageMock.Object, dateTimeServiceMock.Object) as IUserService;

            var user = service.GetUserByUserName("non existing username");

            Assert.IsNull(user);
        }
Exemple #8
0
 public UserDetailsListModel CreateUserDetailsListModel(string userNameFilter, int pageIndex, int pageSize)
 {
 
     var permissionFactory = new PermissionFactory();
 
     var userDetailsModels = new UserService().GetUsersByName(userNameFilter, pageIndex, pageSize).Select(CreateUserDetailsModel).ToList();
 
     var locations = new LocationService().GetAllLocations();
 
     var permissions = new PermissionService().GetAllPermissions().Select(permissionFactory.CreatePermissionModel).ToList();
 
     return new UserDetailsListModel()
     {
         Locations = locations,
         Permission = permissions,
         Users = new Common.PageableList<UserDetailsModel>(userDetailsModels, pageSize, pageIndex)
     };
 }
 public OrdersController(CategoryRepository categoryRepository,
     UserRepository userRepository, SubcategoryRepository subcategoryRepository,
     OrdersRepository ordersRepository, AssetRepository assetRepository, TaskRepository taskRepository,
     ReviewRepository reviewRepository, UserService userService,
     UserResponseHistoryRepository userResponseHistoryRepository,
     ViewCounterService viewCounterService,
     BillingService billingService, GigbucketDbContext dbContext)
 {
     _categoryRepository = categoryRepository;
     _userRepository = userRepository;
     _subcategoryRepository = subcategoryRepository;
     _ordersRepository = ordersRepository;
     _assetRepository = assetRepository;
     _taskRepository = taskRepository;
     _reviewRepository = reviewRepository;
     _userService = userService;
     _userResponseHistoryRepository = userResponseHistoryRepository;
     _viewCounterService = viewCounterService;
     _billingService = billingService;
     _dbContext = dbContext;
 }
        public void PublishMessage_WhenMessageIsNullOrWhiteSpace_ThrowArgumentException(string message)
        {
            var storageMock = new Mock<IEntityStorage<User>>();
            var dateTimeServiceMock = new Mock<IDateTimeService>();
            var service = new UserService(storageMock.Object, dateTimeServiceMock.Object) as IUserService;

            service.PublishMessage("userName", message);
        }
 public void Init()
 {
     _dataBase = MockRepository.GenerateMock<IDataBase<UserTable>>();
     _mapper = MockRepository.GenerateStub<IMapperType>();
     _service = new UserService(_dataBase, _mapper);
 }
        public void RequestOrderItem(Guid userId, int amount, Guid itemId, string notes)
        {
            User   user = null;
            ItemVM item = null;

            //1-find user
            user = UserService.FindByGuid(userId);


            //2-find order
            CreateOrderIfNotExist();



            ResponseService.Init();
            if (user == null)
            {
                ResponseService.Status = false;
                ResponseService.Errors.Add("User Not Found");
                return;
            }


            Order order = FindCurrentOrder();

            if (order.Ordered)
            {
                ResponseService.Status = false;
                ResponseService.Errors.Add("Order Has Been Ordered!");
                return;
            }
            //3-find order details
            OrderDetails orderDetails = null;

            orderDetails = CreateOrderDetailsIfNotExist(order, user);

            //4-find item

            item = ItemService.GetByGuid(itemId);

            if (item == null)
            {
                ResponseService.Status = false;
                ResponseService.Errors.Add("User Not Found");
                return;
            }

            //5-create item details
            ItemDetails itemDetails = new ItemDetails()
            {
                OrderDetailsId = orderDetails.Id,
                ItemId         = item.ElementId,
                Amount         = amount,
                Notes          = notes
            };

            UnitOfWork.ItemDetailsRepository.Create(itemDetails);

            if (UnitOfWork.Save() > 0)
            {
                ResponseService.Status = true;
                ResponseService.Success.Add("Order Created Successfully");
            }
            else
            {
                ResponseService.Status = false;
                ResponseService.Errors.Add("Server Error");
            }
        }
 public IUserService CreateUserService()
 {
     UserService userService = new UserService(AuthConfig, BaseApiURI);
     return userService;
 }
Exemple #14
0
        public void GivenARegisteredUser_WhenTheUserLogon_AndTheNameAndPassowrdMatch_ThenTheLogonSucceeds()
        {
            var user = new User("email", "password");
            _repository.Setup(r => r.Entities).Returns(new System.Collections.Generic.List<User> { user }.AsQueryable());
            var service = new UserService(_repository.Object);

            var loggedinUser =  service.Logon("email", "password");
            loggedinUser.Should().NotBeNull();
        }
Exemple #15
0
        public void GivenNoUser_WhenAUserIsReturned_ThenNullIsReturned()
        {
            _repository.Setup(r => r.Entities).Returns(new System.Collections.Generic.List<User> { new User{Name = ""} }.AsQueryable());

            var service = new UserService(_repository.Object);
            service.GetRegisteredUser().Should().BeNull();
        }
        public void GetUserByUserName_WhenUserNameIsNullOrWhiteSpace_ThrowArgumentException(string userName)
        {
            var storageMock = new Mock<IEntityStorage<User>>();
            var dateTimeServiceMock = new Mock<IDateTimeService>();
            var service = new UserService(storageMock.Object, dateTimeServiceMock.Object) as IUserService;

            service.GetUserByUserName(userName);
        }
Exemple #17
0
 public void GivenARegisteredUser_WhenTheUserLogon_AndTheNameDoesNotMatch_ThenTheLogonFails()
 {
     var user = new User("email", "password");
     _repository.Setup(r => r.Entities).Returns(new System.Collections.Generic.List<User> { user }.AsQueryable());
     var service = new UserService(_repository.Object);
     Assert.Throws<ItsaException>(() => service.Logon("name1", "password"));
 }
        private static async Task GrantWeb(OAuthGrantResourceOwnerCredentialsContext context, string allowedOrigin)
        {
            var userService = new UserService();

            // make sure we have an allowed origin on response
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

            // this is required for ie11 to work
            context.OwinContext.Response.Headers.AppendCommaSeparatedValues(CorsConstants.AccessControlAllowHeaders,
                "accept", "authorization");

            // make sure username and password were sent
            if (string.IsNullOrWhiteSpace(context.UserName) || string.IsNullOrWhiteSpace(context.Password))
            {
                context.SetError("invalid_grant", "Username and password are required.");
                await Task.FromResult<object>(null);
                return;
            }

            var user = userService.Login(context.UserName, context.Password);

            if (user == null)
            {
                context.SetError("invalid_grant", "The username or password is incorrect");
                await Task.FromResult<object>(null);
                return;
            }

            var identity = new ClaimsIdentity(context.Options.AuthenticationType);

            identity.AddClaims(new[]
            {
                new Claim(ClaimTypes.Name, context.UserName),
                new Claim("sub", context.UserName),
                new Claim(ClaimTypes.Sid, user.Id.ToString())
            });

            identity.AddClaims(user.Roles.Select(x => new Claim(ClaimTypes.Role, x.ToString())));

            // add properties
            var props = new AuthenticationProperties(new Dictionary<string, string>
            {
                { "client_id", context.ClientId },
                { "userId", user.Id.ToString() },
                { "userName", user.UserName },
                { "firstName", user.FirstName },
                { "lastName", user.LastName },
                { "roles", string.Join(",", user.Roles) }
            });

            var ticket = new AuthenticationTicket(identity, props);

            context.Validated(ticket);
        }
Exemple #19
0
 public SessionService(UserService userService)
 {
     UserService = userService;
 }