public void CreateUser()
        {
            var connectionString = ConfigurationManager.AppSettings["localConnection"];
            using (IDbConnection connection = new SqlConnection(connectionString))
            using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            using(var userRepository = new UserDatabaseRepository(connection))
            using (var roleRepository = new RoleRepository(connection))
            {
                // To create a USER you MUST first have already created a ROLE!
                var role = new Role { Name = "User" };
                var createdRole = roleRepository.Create(role, _ => Task.FromResult(0)).Result;

                createdRole.Match(r =>
                {
                    var user = new User
                    {
                        Email = "*****@*****.**",
                        FirstName = "John",
                        LastName = "Doe",
                        Roles = new List<Role> { r },
                        Username = "******"
                    };

                    var created = userRepository.Create(user, _ => Task.FromResult(0)).Result;
                    Assert.True(created.HasValue);
                },
                () =>
                {
                    Assert.True(false, "Role has not been created!");
                });

            }
        }
        public void CreateImage()
        {
            var connectionString = ConfigurationManager.AppSettings["localConnection"];
            using (IDbConnection connection = new SqlConnection(connectionString))
            using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            using (var imageRepository = new UserImageRepository(connection))
            using (var userRepository = new UserDatabaseRepository(connection))
            using (var roleRepository = new RoleRepository(connection))
            {
                var image = new Image
                {
                    Description = "My description",
                    Filename = "test",
                    Extension = "jpg",
                    MimeType = "application/jpg",
                    Original = new FileInfo { Data = new Lazy<byte[]>(() => new byte[5]), Path = @"c:\tmp\original.jpg" },
                    Preview = new FileInfo { Data = new Lazy<byte[]>(() => new byte[5]), Path = @"c:\tmp\preview.jpg" },
                    Thumbnail = new FileInfo { Data = new Lazy<byte[]>(() => new byte[5]), Path = @"c:\tmp\thumbnail.jpg" },
                };

                // User ID = 2
                var roleCreate = roleRepository.Create(new Role { Name = "User" }, _ => Task.FromResult(0)).Result;
                var userCreate = userRepository.Create(new User
                {
                    Username = "******",
                    Email = "*****@*****.**",
                    FirstName = "John",
                    LastName = "Doe",
                    Roles = new List<Role> { roleCreate.ValueOrFailure() },
                }, _ => Task.FromResult(0)).Result;
                var created = imageRepository.Create(image, _ => Task.FromResult(0), userCreate.ValueOrFailure().ID).Result;
                Assert.True(created.HasValue, "Image is not created");
            }
        }
 public ProfileController(UserDatabaseRepository userDatabaseRepository, IHttpContextAccessor httpContextAccessor,
                          IHostingEnvironment hostingEnvironment, EventDatabaseRepository eventDatabaseRepository, PaymentsDatabaseRepository paymentsDatabaseRepository)
 {
     this.userDatabaseRepository     = userDatabaseRepository;
     this.httpContextAccessor        = httpContextAccessor;
     this.hostingEnvironment         = hostingEnvironment;
     this.eventDatabaseRepository    = eventDatabaseRepository;
     this.paymentsDatabaseRepository = paymentsDatabaseRepository;
 }
Esempio n. 4
0
        public async Task TestDatabaseFindUserById()
        {
            const int id = 1;

            var options = new DbContextOptionsBuilder <UserContext>()
                          .UseInMemoryDatabase("Users")
                          .Options;

            await using var context = new UserContext(options);
            var repository = new UserDatabaseRepository(context);

            repository.Create(new Core.Entities.User());

            var findUser = new FindUser(repository);

            var user = await findUser.ByIdAsync(id);

            Assert.AreEqual(id, user.Id);
        }
Esempio n. 5
0
        public static void Main(string[] args)
        {
            // --------------- VALIDATORS ---------------
            IValidator <AgeCategory> ageCategoryValidator = new AgeCategoryValidator();
            IValidator <Trial>       trialValidator       = new TrialValidator();
            IValidator <User>        userValidator        = new UserValidator();
            IValidator <Participant> participantValidator = new ParticipantValidator();

            // --------------- REPOSITORIES ---------------
            IAgeCategoryRepository ageCategoryRepository = new AgeCategoryDatabaseRepository("ageCategories", QueryBuilder.GetInstance());
            IParticipantRepository participantRepository = new ParticipantDatabaseRepository("participants", QueryBuilder.GetInstance());
            ITrialRepository       trialRepository       = new TrialDatabaseRepository("trials", QueryBuilder.GetInstance());
            IUserRepository        userRepository        = new UserDatabaseRepository("users", QueryBuilder.GetInstance());

            // --------------- SERVICES ---------------
            AgeCategoryService ageCategoryService = new AgeCategoryService(ageCategoryRepository, ageCategoryValidator);
            TrialService       trialService       = new TrialService(trialRepository, ageCategoryRepository, trialValidator);
            UserService        userService        = new UserService(userRepository, userValidator);
            ParticipantService participantService = new ParticipantService(participantRepository, ageCategoryRepository, participantValidator);

            // --------------- SERVER ---------------
            const int  port       = 50052;
            ServerImpl serverImpl = new ServerImpl(ageCategoryService, trialService, userService, participantService);

            var server = new Grpc.Core.Server
            {
                Services = { AppService.BindService(serverImpl) },
                Ports    = { new ServerPort("localhost", port, ServerCredentials.Insecure) }
            };

            server.Start();

            Console.WriteLine("Server listening on port " + port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            server.ShutdownAsync().Wait();
        }
        public async Task TestDatabaseCreate()
        {
            var options = new DbContextOptionsBuilder <UserContext>()
                          .UseInMemoryDatabase("Users")
                          .Options;

            await using var context = new UserContext(options);
            var userRepository = new UserDatabaseRepository(context);

            var createUser = new CreateUser(userRepository);

            var user = new Core.Entities.User
            {
                UserName  = "******",
                Password  = "******",
                FirstName = "administrator",
                LastName  = "administrator"
            };

            await createUser.CreateAsync(user);

            Assert.AreEqual(1, user.Id);
        }
 public UserCardController(UserDatabaseRepository userDatabaseRepository, PaymentsDatabaseRepository paymentsDatabaseRepository)
 {
     this.userDatabaseRepository     = userDatabaseRepository;
     this.paymentsDatabaseRepository = paymentsDatabaseRepository;
 }
 public PaymentApiController(UserDatabaseRepository userDatabaseRepository)
 {
     this.userDatabaseRepository = userDatabaseRepository;
 }
Esempio n. 9
0
 public EventController(EventDatabaseRepository eventDatabaseRepository, IHostingEnvironment hostingEnvironment, UserDatabaseRepository userDatabaseRepository)
 {
     this.eventDatabaseRepository = eventDatabaseRepository;
     this.hostingEnvironment      = hostingEnvironment;
     this.userDatabaseRepository  = userDatabaseRepository;
 }