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!");
                });

            }
        }
Esempio n. 2
0
        public void CreateRole(string name)
        {
            var connectionString = ConfigurationManager.AppSettings["localConnection"];
            using (IDbConnection connection = new SqlConnection(connectionString))
            using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            using (var repository = new RoleRepository(connection))
            {
                var role = new Role
                {
                    Name = name
                };

                var created = repository.Create(role, _ => Task.FromResult(0)).Result;

                Assert.True(created.HasValue, "Role has not been created!");
                // The command is never committed to database
                // transactionScope.Complete();
            }
        }